k-kinzal/testcontainers-php

PHP library for Testcontainers

v0.3.1 2025-05-07 05:55 UTC

This package is auto-updated.

Last update: 2025-06-01 03:52:43 UTC


README

GitHub Actions CircleCI License: MIT

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.

Features

  • 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

Requirements

  • Docker command line tool (docker CLI)
  • PHP 5.6 or later

Installation

composer require --dev k-kinzal/testcontainers-php

Quick Start

<?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
    }
}

Documentation

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)

License

This project is licensed under the MIT License - see the LICENSE file for details.

Acknowledgements

  • Testcontainers for the original concept and implementation in other languages
  • All contributors who have helped improve this project