Service provider for tests in need of a Doctrine entity manager

v2.0.0 2015-01-20 18:16 UTC


Build Status

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


Extend your test class from Noback\PHPUnitTestServiceContainer\PHPUnit\AbstractTestCaseWithEntityManager. You then need to implement the getEntityClasses() which should return an array of entity class names.

For each test method a connection to an SQLite database will be available. Also the schema for the given entities will be created automatically.


use Noback\PHPUnitTestServiceContainer\PHPUnit\AbstractTestCaseWithEntityManager;

class StorageTest extends AbstractTestCaseWithEntityManager
    protected function getEntityClasses()
        return array(

     * @test
    public function it_persists_an_entity()
        $user = new User();


Of course, you would usually inject the entity manager into some object which is the subject-under-test.

To register Doctrine event listeners/subscribers, get the EventManager instance by calling $this->getEventManager(). To get the database Connection object, call $this->getConnection().

Read more