abstract class MySqlContainer
    extends GenericContainer

Defines a reusable MySQL server with a disposable test database.

Each version extends it and sets only $IMAGE. The server runs on tmpfs and skips loading the time zone tables to start fast; it is ready once PDO can connect as root / root.

Properties§

protected static $EXPOSED_PORTS = [3306]
protected static $MOUNTS = ['type=tmpfs,destination=/var/lib/mysql']
protected static $ENVIRONMENTS = ['MYSQL_ROOT_PASSWORD' => 'root', 'MYSQL_ROOT_HOST' => '%', 'MYSQL_DATABASE' =>…
protected static $REUSE_MODE = 'reuse'
protected static $STARTUP_TIMEOUT = 300
protected static $STARTUP_CONFLICT_RETRY_ATTEMPTS = 10
protected static $AUTO_REMOVE_ON_EXIT = true

Methods§

public static function getGrammarVersion(): string

Returns the SQL grammar identifier matching the server version.

Returns

string Grammar identifier, `mysql-` followed by the image tag.
Calls 2
public function afterStart(ContainerInstance $instance): void

Attaches the server endpoint once the container has started.

The host is given as 127.0.0.1 instead of localhost so that clients connect over TCP.

Parameters

$instanceContainerInstanceStarted container instance.

Throws

RuntimeException If the server port is not mapped to the host.
Calls 6
protected function waitStrategy(ContainerInstance $instance): WaitStrategy

Waits until PDO can connect to the test database.

Parameters

$instanceContainerInstanceStarted container instance.

Returns

WaitStrategy PDO connection wait strategy.
Calls 4
  • method-call PDOConnectWaitStrategy::withDsn() line 77
  • new PDOConnectWaitStrategy line 77
  • method-call MySQLDSN::withDbname() line 78
  • new MySQLDSN line 78

Relations§

Extended by 9