Một mục mã nguồn mở trong kho dữ liệu GitHub của TopGit: testcontainers/testcontainers-php, 216 sao, PHP. https://www.testcontainers.org implementation for PHP
Tóm tắt dựng từ metadata GitHub của chính dự án — chưa có bài review TopGit. Trang sẽ tự động cập nhật khi bài review đầy đủ được xuất bản.
VÌ SAO CHƯA CÓ REVIEW
TopGit viết bài đầy đủ cho repo có nhiều sao nhất và được yêu cầu nhiều nhất. Trang này là snapshot trong thời gian chờ — xem README gốc ở tab READ ME.
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
Đọc thêm về testcontainers/testcontainers-php ở đâu?
Trang TopGit này là một snapshot — tab "Readme" hiển thị nguyên văn README của repo (đã bỏ link, giữ ảnh). Repo GitHub ở github.com/testcontainers/testcontainers-php là nguồn chính thức.
testcontainers/testcontainers-php có bao nhiêu sao?
testcontainers/testcontainers-php có 216 sao GitHub — tải lại trang để xem số mới nhất, hoặc xem trực tiếp github.com/testcontainers/testcontainers-php. TopGit phản chiếu số sao của GitHub nhưng không cam kết đến từng phút.
testcontainers/testcontainers-php có phải mã nguồn mở không?
Có — testcontainers/testcontainers-php phát hành theo license MIT, nghĩa là mã nguồn mở để đọc, fork và (tùy license) tái sử dụng. Mã: github.com/testcontainers/testcontainers-php.
testcontainers/testcontainers-php có website riêng không?
TopGit chưa ghi nhận URL trang chủ cho testcontainers/testcontainers-php. Phần README ở tab phía trên thường có link demo, hoặc xem mô tả GitHub của repo.
testcontainers/testcontainers-php là gì?
testcontainers/testcontainers-php (testcontainers/testcontainers-php) là dự án PHP trên GitHub. Theo mô tả gốc: https://www.testcontainers.org implementation for PHP
Đọc đầy đủ README ở tab phía trên.
Muốn nghe thêm một ý kiến về testcontainers-php?
Hỏi một AI đọc được trang này — một cú bấm là có ngay nhận định về testcontainers-php.