Skip to content

Latest commit

 

History

History
27 lines (23 loc) · 787 Bytes

README.md

File metadata and controls

27 lines (23 loc) · 787 Bytes

phpunit-db-fixtures

Simple DB fixtures loading, replacement for phpunit/dbunit

Usage

use IW\PHPUnit\DbFixtures\DbFixturesTrait;
use IW\PHPUnit\DbFixtures\Fixtures;

final class MyTest extends TestCase
{
  use DbFixturesTrait;

  // returns connections to your DB, implementation is up to you, a singleton should be returned probably
  protected function getConnections(string $connectionName): array {
    return match ($connectionName) {
      // key is name of DB, use it for distinction between multiple DBs
      'mysql' => new \PDO(...),
      'elastic' => new Elasticsearch\Client(...),
    };
  }

  #[Fixtures('mysql', 'read-only', 'fixtures.yml')]
  public function testWithFixtures() {
    // before test data from fixtures.yml will be loaded into mysql
  }
}