intraworlds / phpunit-db-fixtures
Loading DB fixtures with ease
Installs: 73 035
Dependents: 0
Suggesters: 0
Security: 0
Stars: 2
Watchers: 3
Forks: 8
Open Issues: 8
Requires
- php: >=8.3
- phpunit/phpunit: ^11.0
Requires (Dev)
- mongodb/mongodb: ^1.5
- rector/rector: ^1.2
- robmorgan/phinx: ^0.12
- symfony/yaml: ^7
Suggests
- elasticsearch/elasticsearch: Needed to support Elasticsearch
- mongodb/mongodb: Needed to support MongoDB
- opensearch-project/opensearch-php: Needed for OpenSearch support
- symfony/yaml: For YAML fixtures
README
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 } }