testcontainers/testcontainers-php — an open-source project — sits at 214 GitHub stars. https://www.testcontainers.org implementation for PHP
Snapshot summary built from the project's own GitHub metadata — there's no written TopGit review yet. The page will update automatically when a full review is published.
WHY NO REVIEW YET
TopGit writes full reviews for the most-starred, most-requested repositories. This page is a snapshot until then — see the READ ME tab for the original README in full.
Testcontainers is a PHP package that makes it simple to create and clean up container-based dependencies for automated integration/smoke tests. The package is inspired by the Testcontainers project for Java.
Legacy PHP support
The official testcontainers/testcontainers-php library requires PHP 8.1 or newer. If you need to support older PHP versions, including those that are EOL, please check out the community-maintained k-kinzal/testcontainers-php project. The discussion about supporting legacy versions lives in issue #38.
Installation
Add this to your project with composer
composer req --dev testcontainers/testcontainers
Usage/Examples
Starting a general Container
<?php
use Testcontainers\Container\GenericContainer;
$container = new GenericContainer('nginx:alpine');
// set an environment variable
$container->withEnvironment([
'key1' => 'val1',
'key2' => 'val2'
]);
// enable health check for a container
$container->withHealthCheckCommand('curl --fail localhost');
// mount current dir to /var/www/html
$container->withMount(__DIR__, '/var/www/html');
Normally, you have to wait until the Container is ready. For this you can define a wait rule:
use Testcontainers\Container\GenericContainer;
use Testcontainers\Wait\WaitForExec;
use Testcontainers\Wait\WaitForLog;
use Testcontainers\Wait\WaitForHttp;
use Testcontainers\Wait\WaitForHealthCheck;
use Testcontainers\Wait\WaitForHostPort;
$container = new GenericContainer('nginx:alpine');
// Run mysqladmin ping until the command returns exit code 0
$container->withWait(new WaitForExec(['mysqladmin', 'ping', '-h', '127.0.0.1']));
$container->withWait(new WaitForExec(['mysqladmin', 'ping', '-h', '127.0.0.1']), function($exitCode, $contents) {
// throw exception if process result is bad
});
// Wait until that message is in the logs
$container->withWait(new WaitForLog('Ready to accept connections'));
// Wait for an http request to succeed
$container->withWait((new WaitForHttp($port))->withMethod('GET')->withPath('/'));
// Wait for all bound ports to be open
$container->withWait(new WaitForHostPort());
// Wait until the Docker heartcheck is green
$container->withWait(new WaitForHealthCheck());
MySQL
<?php
use Testcontainers\Modules\MySQLContainer;
$container = (new MySQLContainer('8.0'))
->withMySQLDatabase('foo')
->withMySQLUser('bar', 'baz')
->start();
$pdo = new \PDO(
sprintf(
'mysql:host=%s;port=%d',
$container->getHost(),
$container->getFirstMappedPort()
),
'bar',
'baz',
);
// Do something with PDO
MariaDB
<?php
use Testcontainers\Modules\MariaDBContainer;
$container = $container = (new MariaDBContainer())
->withMariaDBDatabase('foo')
->withMariaDBUser('bar', 'baz')
->start();
$pdo = new \PDO(
sprintf(
'mysql:host=%s;port=%d',
$container->getHost(),
$container->getFirstMappedPort()
),
'bar',
'baz',
);
// Do something with PDO
PostgreSQL
<?php
use Testcontainers\Modules\PostgresContainer;
$container = (new PostgresContainer())
->withPostgresUser('bar')
->withPostgresDatabase('foo')
->start();
$pdo = new \PDO(
sprintf(
'pgsql:host=%s;port=%d;dbname=foo',
self::$container->getHost(),
self::$container->getFirstMappedPort()
),
'bar',
'test',
);
// Do something with PDO
Redis
use Testcontainers\Modules\RedisContainer;
$container = (new RedisContainer())
->start();
$redis = new \Redis();
$redis->connect($container->getHost(), $container->getFirstMappedPort());
// Do something with Redis
OpenSearch
use Testcontainers\Modules\OpenSearchContainer;
$container = (new OpenSearchContainer())
->withDisabledSecurityPlugin()
->start();
// Do something with opensearch
Does testcontainers/testcontainers-php have a project website?
No homepage URL was recorded for testcontainers/testcontainers-php in TopGit's last sync. The README tab above frequently contains screenshots and demo links, or check the repository description on GitHub.
How many stars does testcontainers/testcontainers-php have?
testcontainers/testcontainers-php has 214 GitHub stars — refresh the page for the live number, or check github.com/testcontainers/testcontainers-php. TopGit mirrors GitHub's count but does not claim minute-by-minute accuracy.
Is testcontainers/testcontainers-php open source?
Yes — testcontainers/testcontainers-php ships under the MIT license, which makes its source code freely readable (and, depending on license terms, forkable and reusable). Source: github.com/testcontainers/testcontainers-php.
What is testcontainers/testcontainers-php?
testcontainers/testcontainers-php (testcontainers/testcontainers-php) is a PHP project on GitHub. From the project's own README: https://www.testcontainers.org implementation for PHP
Where do I read more about testcontainers/testcontainers-php?
This TopGit page is a snapshot — the READ ME tab shows the project's own README content (links stripped, images preserved). The GitHub repository at github.com/testcontainers/testcontainers-php is the definitive source.
Read full README in the tab above.
Still deciding about testcontainers-php?
One click hands the question to an AI along with this page — see what it says about testcontainers-php.