2017 © Pedro Peláez
 

library doctrine-test

Doctrine2 Testing Library

image

51systems/doctrine-test

Doctrine2 Testing Library

  • Saturday, November 26, 2016
  • by 51systems
  • Repository
  • 1 Watchers
  • 0 Stars
  • 155 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 3 Versions
  • 0 % Grown

The README.md

This is a basic Doctrine2 Test Library to be used with PHPUnit., (*1)

Contributors:

Features

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

Installation

Install via composer., (*2)

Writing tests

namespace Application\Test\Entity;

class MyModelTest extends EntityTestCase
{
    //If you need to set the application module configuration, because you are
    //not using a custom bootloader for tests, then use the trait
    use ServiceLocatorAwareTestTrait;

    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);

        //If using the ServiceLocatorAwareTestTrait
        $configOverrides = [];
        $this->setApplicationConfig(ArrayUtils::merge(
            include __DIR__ . '/PATH TO YOUR APPLICATION CONFIG/application.config.php',
            $configOverrides
        ));
    }

    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');

    }

    protected function getServiceLocator() {
        return \Application\Test\Bootstrap::getServiceManager();
    }
}

The Versions

26/11 2016

dev-master

9999999-dev https://github.com/51systems/doctrine-test

Doctrine2 Testing Library

  Sources   Download

LGPL-3.0

The Requires

 

The Development Requires

by Cameron Manderson

test phpunit doctrine

11/10 2013

0.1.2

0.1.2.0 https://github.com/51systems/doctrine-test

Doctrine2 Testing Library

  Sources   Download

LGPL-3.0

The Requires

 

by Cameron Manderson

test phpunit doctrine

21/09 2013

0.1

0.1.0.0 https://github.com/51systems/doctrine-test

Doctrine2 Testing Library

  Sources   Download

LGPL-3.0

The Requires

 

by Cameron Manderson

test phpunit doctrine