51systems/doctrine-test

Doctrine2 Testing Library

Installs: 118

Dependents: 0

Watchers: 1

Forks: 1

Language: PHP

0.1.2 2013-10-11 00:44 UTC

README

This is a basic Doctrine2 Test Library to be used with PHPUnit.

Features

  • SQLite in-memory database used for tests
  • Fixture Support
  • Subscriber support

Installation

Install via composer.

Writing tests

namespace Application\Test\Entity;

class MyModelTest extends EntityTestCase
{

    public function setUp()
    {
        // Load the database schemas
        $this->loadSchemas(array('Entity\MyEntity')); // Load as many needed for the tests

        // Optionally, you can load fixtures
        $this->loadFixture('DataFixtures\ORM\MyFixture');

        // You can also load subscribers, like registering sluggable, timestampable etc behaviour
        //$myListener = new Listener\MyListener();
        //$this->addLifecycleEventSubscriber($myListener);
    }

    public function testCreate()
    {
        // Get the entity manager for managing persistence etc.
        $em = $this->getEntityManager();

        // Test a create
        $myEntity = new Entity\MyEntity;
        $myEntity->setTitle('Hello World');
        $em->persist();

        // Test we issued SQL to the database
        $this->assertEquals(1, $this->getQueryCount(), 'Should have executed one query to the database');

        // Test the generation of an ID
        $this->assertNotEmpty($myEntity->getId(), 'Should have got an ID for my entity');

    }
}