matthiasnoback/doctrine-dbal-test-service-provider

Service provider for tests in need of a Doctrine DBAL connection

Maintainers

👁 matthiasnoback

Package info

github.com/matthiasnoback/doctrine-dbal-test-service-provider

pkg:composer/matthiasnoback/doctrine-dbal-test-service-provider

Statistics

Installs: 88 152

Dependents: 1

Suggesters: 0

Stars: 3

Open Issues: 2

v3.3.0 2025-11-05 12:06 UTC

Requires

Requires (Dev)

None

Suggests

None

Provides

None

Conflicts

None

Replaces

None

MIT 82d131d138a3d640bcb403e9f8e06b5f4d5e2c53

phpunitservice providerDoctrine DBAL

This package is auto-updated.

Last update: 2026-06-05 13:16:12 UTC


README

👁 CI

This library contains a service provider to be used with a service container for PHPUnit tests.

Usage

Use the trait Noback\PHPUnitTestServiceContainer\PHPUnit\TestCaseWithDoctrineDbalConnection in your test class. You then need to implement the createSchema() and return an instance of Doctrine\DBAL\Schema\Schema.

For each test method a database connection (of instance Doctrine\DBAL\Connection) will be available. Also the schema returned by createSchema() will be created in the database. The database itself is (by default) an SQLite in-memory database, which will leave no traces on the filesystem.

<?php

use Noback\PHPUnitTestServiceContainer\PHPUnit\TestCaseWithDoctrineDbalConnection;
use Doctrine\DBAL\Schema\Schema;

final class StorageTest
{
 use TestCaseWithDoctrineDbalConnection;
 
 /**
 * @test
 */
 public function something()
 {
 $connection = $this->getConnection();

 $connection->insert('some_table', array('some_column' => 'value'));

 ...
 }

 protected function createSchema()
 {
 $schema = new Schema();

 $table = $schema->createTable('some_table');

 $table->addColumn('some_column', 'string');

 return $schema;
 }
}

Read more