final class Endpoint

Describes how to connect to the database server of a started container.

A database container attaches it to its instance after startup, so it is read with Testcontainers::run(...)->getData(Endpoint::class).

Build the PDO data source name of a MySQL serverdoctest
$endpoint = new \Container\Endpoint('mysql', '127.0.0.1', 33060, 'test', 'root', 'root');
    assert($endpoint->dsn() === 'mysql:host=127.0.0.1;port=33060;dbname=test;charset=utf8mb4');
Build the PDO data source name of a PostgreSQL serverdoctest
$endpoint = new \Container\Endpoint('pgsql', '127.0.0.1', 54320, 'test', 'test', 'test');
    assert($endpoint->dsn() === 'pgsql:host=127.0.0.1;port=54320;dbname=test');

Properties§

public string $driver
public string $host
public int $port
public string $database
public string $username
public string $password

Methods§

public function __construct(
    public string $driver,
    public string $host,
    public int $port,
    public string $database,
    public string $username,
    public string $password,
)

Parameters

$driverstringPDO driver name, `mysql` or `pgsql`.
$hoststringHost that reaches the server over TCP.
$portintHost port mapped to the server port.
$databasestringDatabase created at startup.
$usernamestringUser that owns the database.
$passwordstringPassword of the user.
public function dsn(): string

Returns the PDO data source name of the server.

Returns

string Data source name; MySQL connections use `utf8mb4`.
Calls 1

Test cases 315§

Test cases that cover or call this symbol, from the coverage report and from the analyzed test sources.

Other tests reaching this symbol 315

Relations§

Instantiated in 2