Testcontainer Magento Data (PHP)

View on GitHub

PHP library to launch pre-seeded MariaDB, MySQL, and OpenSearch Testcontainers in under a second directly from PHPUnit suites.

Overview

ecomdev/testcontainers-magento-data is the official PHP client for testcontainer-magento-data. It manages container lifecycle, ephemeral port mapping, fast log readiness detection, and clean teardown so you can run real database and search engine queries inside PHPUnit without maintaining shared local databases.

Installation

composer require --dev ecomdev/testcontainers-magento-data

Example Usage

<?php

use EcomDev\TestContainers\MagentoData\DatabaseContainer;

$container = DatabaseContainer::magento248()
    ->withSampleData()
    ->start();

$pdo = new PDO(
    sprintf(
        'mysql:host=%s;port=%d;dbname=%s',
        $container->getHost(),
        $container->getPort(),
        $container->getDatabase()
    ),
    $container->getUsername(),
    $container->getPassword()
);

Why Teams Use It

  • Isolated test runs: Every suite starts against a clean, deterministic schema with zero leftover state.
  • Fast local feedback: Version 2.1+ pairs 50ms readiness polling with force-remove teardown to cut total suite overhead to a few seconds.
  • CI parity: The exact same image tag runs on Apple Silicon laptops and Linux GitHub Actions runners.

More in Automation Tools

View all Automation Tools →