intraworlds / phpunit-db-fixtures
Loading DB fixtures with ease
Installs: 72 197
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 3
Forks: 8
Open Issues: 8
Requires
- php: >=8.1
- phpunit/phpunit: ^9.5||^10.0
- symfony/yaml: ^6.0
Requires (Dev)
- mongodb/mongodb: ^1.5
- robmorgan/phinx: ^0.12
Suggests
- elasticsearch/elasticsearch: Needed to support Elasticsearch
- mongodb/mongodb: Needed to support MongoDB
- opensearch-project/opensearch-php: Needed for OpenSearch support
This package is auto-updated.
Last update: 2024-04-28 12:42:59 UTC
README
Simple DB fixtures loading, replacement for phpunit/dbunit
Usage
use IW\PHPUnit\DbFixtures\DbFixturesTrait; 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 } }