mirror of
https://github.com/stan220/testcontainers-php.git
synced 2026-09-12 09:29:35 +00:00
feat: Add postgres container
This commit is contained in:
@@ -38,7 +38,7 @@ class Container
|
||||
*/
|
||||
private array $mounts = [];
|
||||
|
||||
public function __construct(private string $image)
|
||||
protected function __construct(private string $image)
|
||||
{
|
||||
$this->wait = new WaitForNothing();
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ use Testcontainer\Wait\WaitForExec;
|
||||
|
||||
class MariaDBContainer extends Container
|
||||
{
|
||||
public function __construct(string $version = 'latest', string $mysqlRootPassword = 'root')
|
||||
private function __construct(string $version, string $mysqlRootPassword)
|
||||
{
|
||||
parent::__construct('mariadb:' . $version);
|
||||
$this->withEnvironment('MARIADB_ROOT_PASSWORD', $mysqlRootPassword);
|
||||
|
||||
@@ -8,7 +8,7 @@ use Testcontainer\Wait\WaitForExec;
|
||||
|
||||
class MySQLContainer extends Container
|
||||
{
|
||||
public function __construct(string $version = 'latest', string $mysqlRootPassword = 'root')
|
||||
private function __construct(string $version, string $mysqlRootPassword)
|
||||
{
|
||||
parent::__construct('mysql:' . $version);
|
||||
$this->withEnvironment('MYSQL_ROOT_PASSWORD', $mysqlRootPassword);
|
||||
|
||||
@@ -8,7 +8,7 @@ use Testcontainer\Wait\WaitForHttp;
|
||||
|
||||
class OpenSearchContainer extends Container
|
||||
{
|
||||
public function __construct(string $version = 'latest')
|
||||
private function __construct(string $version)
|
||||
{
|
||||
parent::__construct('opensearchproject/opensearch:' . $version);
|
||||
$this->withEnvironment('discovery.type', 'single-node');
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Testcontainer\Container;
|
||||
|
||||
class PostgresContainer extends Container
|
||||
{
|
||||
private function __construct(string $version, string $rootPassword)
|
||||
{
|
||||
parent::__construct('mariadb:' . $version);
|
||||
$this->withEnvironment('POSTGRES_PASSWORD', $rootPassword);
|
||||
}
|
||||
|
||||
public static function make(string $version = 'latest', string $mysqlRootPassword = 'root'): self
|
||||
{
|
||||
return new self($version, $mysqlRootPassword);
|
||||
}
|
||||
|
||||
public function withPostgresUser(string $username): self
|
||||
{
|
||||
$this->withEnvironment('POSTGRES_USER', $username);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function withPostgresDatabase(string $database): self
|
||||
{
|
||||
$this->withEnvironment('POSTGRES_DB', $database);
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
@@ -8,7 +8,7 @@ use Testcontainer\Wait\WaitForLog;
|
||||
|
||||
class RedisContainer extends Container
|
||||
{
|
||||
public function __construct(string $version = 'latest')
|
||||
private function __construct(string $version)
|
||||
{
|
||||
parent::__construct('redis:' . $version);
|
||||
$this->withWait(new WaitForLog('Ready to accept connections'));
|
||||
|
||||
Reference in New Issue
Block a user