mirror of
https://github.com/stan220/testcontainers-php.git
synced 2026-11-07 16:02:38 +00:00
- Move most of the stuff for backwards compatibility support into one class
- Added random port logic - Updated wait wtrategies - API alignments to make it similar to other official implementations - ...
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Testcontainers\Modules;
|
||||
|
||||
use Testcontainers\Container\GenericContainer;
|
||||
use Testcontainers\Wait\WaitForLog;
|
||||
|
||||
class MariaDBContainer extends GenericContainer
|
||||
{
|
||||
public function __construct(string $version = 'latest', string $mysqlRootPassword = 'root')
|
||||
{
|
||||
parent::__construct('mariadb:' . $version);
|
||||
$this->withExposedPorts(3306);
|
||||
$this->withWait(new WaitForLog('ready for connections'));
|
||||
$this->withEnvironment('MARIADB_ROOT_PASSWORD', $mysqlRootPassword);
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Use constructor instead
|
||||
* Left for backward compatibility
|
||||
*/
|
||||
public static function make(string $version = 'latest', string $mysqlRootPassword = 'root'): self
|
||||
{
|
||||
return new self($version, $mysqlRootPassword);
|
||||
}
|
||||
|
||||
public function withMariaDBUser(string $username, string $password): self
|
||||
{
|
||||
$this->withEnvironment('MARIADB_USER', $username);
|
||||
$this->withEnvironment('MARIADB_PASSWORD', $password);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function withMariaDBDatabase(string $database): self
|
||||
{
|
||||
$this->withEnvironment('MARIADB_DATABASE', $database);
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Testcontainers\Modules;
|
||||
|
||||
use Testcontainers\Container\GenericContainer;
|
||||
use Testcontainers\Wait\WaitForLog;
|
||||
|
||||
class MySQLContainer extends GenericContainer
|
||||
{
|
||||
public function __construct(string $version = 'latest', string $mysqlRootPassword = 'root')
|
||||
{
|
||||
parent::__construct('mysql:' . $version);
|
||||
$this->withExposedPorts(3306);
|
||||
$this->withEnvironment('MYSQL_ROOT_PASSWORD', $mysqlRootPassword);
|
||||
$this->withWait(new WaitForLog('ready for connections'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Use constructor instead
|
||||
* Left for backward compatibility
|
||||
*/
|
||||
public static function make(string $version = 'latest', string $mysqlRootPassword = 'root'): self
|
||||
{
|
||||
return new self($version, $mysqlRootPassword);
|
||||
}
|
||||
|
||||
public function withMySQLUser(string $username, string $password): self
|
||||
{
|
||||
$this->withEnvironment('MYSQL_USER', $username);
|
||||
$this->withEnvironment('MYSQL_PASSWORD', $password);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function withMySQLDatabase(string $database): self
|
||||
{
|
||||
$this->withEnvironment('MYSQL_DATABASE', $database);
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Testcontainers\Modules;
|
||||
|
||||
use Testcontainers\Container\GenericContainer;
|
||||
use Testcontainers\Wait\WaitForLog;
|
||||
|
||||
class OpenSearchContainer extends GenericContainer
|
||||
{
|
||||
public function __construct(string $version = 'latest')
|
||||
{
|
||||
parent::__construct('opensearchproject/opensearch:' . $version);
|
||||
$this->withExposedPorts(9200);
|
||||
$this->withEnvironment('discovery.type', 'single-node');
|
||||
$this->withEnvironment('OPENSEARCH_INITIAL_ADMIN_PASSWORD', 'c3o_ZPHo!');
|
||||
$this->withWait(new WaitForLog(
|
||||
'/\]\s+started\?\[/',
|
||||
true,
|
||||
30000
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Use constructor instead
|
||||
* Left for backward compatibility
|
||||
*/
|
||||
public static function make(string $version = 'latest'): self
|
||||
{
|
||||
return new self($version);
|
||||
}
|
||||
|
||||
public function withDisabledSecurityPlugin(): self
|
||||
{
|
||||
$this->withEnvironment('plugins.security.disabled', 'true');
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Use withDisabledSecurityPlugin instead
|
||||
*/
|
||||
public function disableSecurityPlugin(): self
|
||||
{
|
||||
return $this->withDisabledSecurityPlugin();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Testcontainers\Modules;
|
||||
|
||||
use Testcontainers\Container\GenericContainer;
|
||||
use Testcontainers\Wait\WaitForExec;
|
||||
|
||||
class PostgresContainer extends GenericContainer
|
||||
{
|
||||
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->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]));
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Use constructor instead
|
||||
* Left for backward compatibility
|
||||
*/
|
||||
public static function make(string $version = 'latest', string $dbPassword = 'root'): self
|
||||
{
|
||||
return new self(
|
||||
version: $version,
|
||||
password: $dbPassword
|
||||
);
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Testcontainers\Modules;
|
||||
|
||||
use Testcontainers\Container\GenericContainer;
|
||||
use Testcontainers\Wait\WaitForLog;
|
||||
|
||||
class RedisContainer extends GenericContainer
|
||||
{
|
||||
public function __construct(string $version = 'latest')
|
||||
{
|
||||
parent::__construct('redis:' . $version);
|
||||
$this->withExposedPorts(6379);
|
||||
$this->withWait(new WaitForLog('Ready to accept connections'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Use constructor instead
|
||||
* Left for backward compatibility
|
||||
*/
|
||||
public static function make(string $version = 'latest'): self
|
||||
{
|
||||
return new self($version);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user