mirror of
https://github.com/stan220/testcontainers-php.git
synced 2026-11-07 17:02:38 +00:00
Implement WaitForExec using new Client library. Add BaseWait to avoid some code duplication. Adjust Postgres test
This commit is contained in:
@@ -8,11 +8,18 @@ use Testcontainers\Wait\WaitForExec;
|
||||
|
||||
class PostgresContainer extends GenericContainer
|
||||
{
|
||||
public function __construct(string $version = 'latest', string $rootPassword = 'root')
|
||||
{
|
||||
public function __construct(
|
||||
string $version = 'latest',
|
||||
public readonly string $username = 'test',
|
||||
public readonly string $password = 'test',
|
||||
public readonly string $database = 'test'
|
||||
) {
|
||||
parent::__construct('postgres:' . $version);
|
||||
$this->withEnvironment('POSTGRES_PASSWORD', $rootPassword);
|
||||
$this->withWait(new WaitForExec(["pg_isready", "-h", "127.0.0.1"]));
|
||||
$this->withExposedPorts(5432);
|
||||
$this->withEnvironment('POSTGRES_USER', $this->username);
|
||||
$this->withEnvironment('POSTGRES_PASSWORD', $this->password);
|
||||
$this->withEnvironment('POSTGRES_DB', $this->database);
|
||||
$this->withWait(new WaitForExec(["pg_isready", "-h", "127.0.0.1", "-U", $this->username]));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -21,7 +28,10 @@ class PostgresContainer extends GenericContainer
|
||||
*/
|
||||
public static function make(string $version = 'latest', string $dbPassword = 'root'): self
|
||||
{
|
||||
return new self($version, $dbPassword);
|
||||
return new self(
|
||||
version: $version,
|
||||
password: $dbPassword
|
||||
);
|
||||
}
|
||||
|
||||
public function withPostgresUser(string $username): self
|
||||
|
||||
Reference in New Issue
Block a user