A PHP implementation of Testcontainers that supports PHP versions from 5.6 to 8.3, including EOL versions. This library enables you to use Docker containers for your integration tests with minimal dependencies.
If you are using a supported PHP version, consider using the official testcontainers/testcontainers instead.
- Supports PHP 5.6 to 8.3 (including EOL versions)
- Minimal dependencies for easy integration
- Complete container lifecycle management
- Various configuration options for containers
- Multiple wait strategies to ensure services are ready
- Support for remote Docker hosts and SSH port forwarding
- Docker command line tool (docker CLI)
- PHP 5.6 or later
composer require --dev k-kinzal/testcontainers-php
<?php
use PHPUnit\Framework\TestCase;
use Testcontainers\Containers\GenericContainer\GenericContainer;
use Testcontainers\Testcontainers;
class MyContainer extends GenericContainer
{
protected static $IMAGE = 'alpine:latest';
}
class MyTest extends TestCase
{
public function test(): void
{
// Start the container and get the container instance
$instance = Testcontainers::run(MyContainer::class);
// Your test code here
// Containers are automatically stopped when the test ends
}
}
For more detailed information, check out the documentation:
- Getting Started: A comprehensive guide to installing and using testcontainers-php
- Container Configuration: Learn how to configure containers with various settings
- Environments: Understand how to configure testcontainers-php using environment variables
- CI Setup: Guide for setting up testcontainers-php in CI environments (GitHub Actions, CircleCI)
This project is licensed under the MIT License - see the LICENSE file for details.
- Testcontainers for the original concept and implementation in other languages
- All contributors who have helped improve this project