2017 © Pedro Peláez
 

library phpunit-doctrine-extension

Provides the base TestCase for functional ORM/DB tests.

image

airmedia/phpunit-doctrine-extension

Provides the base TestCase for functional ORM/DB tests.

  • Wednesday, March 28, 2018
  • by yethee
  • Repository
  • 1 Watchers
  • 1 Stars
  • 181 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 6 Versions
  • 7 % Grown

The README.md

Doctrine Extension for PHPUnit

Provides the base TestCase for functional ORM\DB tests., (*1)

Works with RDBMS:, (*2)

  • PostgreSQL > 9.4
  • SQLite

Installation

$ composer require airmedia\phpunit-doctrine-extension --dev

Support PostgreSQL

For work with PostgreSQL you need to modify your configuration file (phpunit.xml) for PHPUnit. Add some variables to configure connection to PostgreSQL server. For example:, (*3)

    <php>
        <var name="db_type" value="pdo_pgsql" />
        <var name="db_host" value="localhost" />
        <var name="db_username" value="postgres" />
        <var name="db_password" value="" />
        <var name="db_name" value="my_database_tests" />
        <var name="db_port" value="5432" />
    </php>

If these options are missing then will be used driver for SQLite as the fallback., (*4)

Usage

You must inherit from AirMedia\Test\OrmTestCase and implement createMappingDriver to provide configured mapping driver., (*5)

Also you may override the static field $customTypes to define the custom types for Doctrine., (*6)

Example:, (*7)

<?php

use AirMedia\Test\ORMTestCase;
use Doctrine\Common\Persistence\Mapping\Driver\MappingDriver;
use Doctrine\Common\Persistence\Mapping\Driver\MappingDriverChain;
use Doctrine\ORM\Configuration;
use Ramsey\Uuid\Doctrine\UuidType;

class RepositoryTestCase extends ORMTestCase
{
    static protected $customTypes = [
        UuidType::NAME => UuidType::class,
    ];

    public function testAnything()
    {
        $repository = $this->em->getRepository('Acme\Entity\User');

        // Action and asserts...
    }

    protected function createMappingDriver(Configuration $config): MappingDriver
    {
        $annotationDriver = $config->newDefaultAnnotationDriver([
            realpath(__DIR__ . '/../src/Entity'),
        ], false);

        $driver = new MappingDriverChain();
        $driver->addDriver($annotationDriver, 'Acme\Entity');

        return $driver;
    }
}

Doctrine Data Fixtures Extension

You may populate your database throught the data fixtures using trait AirMedia\Test\Helper\DataFixturesTrait., (*8)

<?php

use AirMedia\Test\ORMTestCase;
use AirMedia\Test\Helper\DataFixturesTrait;

class FooTestCase extends ORMTestCase
{
    use DataFixturesTrait;

    protected function setUp()
    {
        parent::setUp();

        $this->loadFixtures([
            new \Acme\DataFixtures\UserFixture(),
            'Acme\DataFixtures\GroupFixture', // or class name
        ]);
    }
}

License

This package is licensed using the MIT License., (*9)

The Versions

28/03 2018

dev-master

9999999-dev

Provides the base TestCase for functional ORM/DB tests.

  Sources   Download

MIT

The Requires

 

The Development Requires

database phpunit testing

28/03 2018

0.3.2

0.3.2.0

Provides the base TestCase for functional ORM/DB tests.

  Sources   Download

MIT

The Requires

 

The Development Requires

database phpunit testing

15/03 2018

0.3.1

0.3.1.0

Provides the base TestCase for functional ORM/DB tests.

  Sources   Download

MIT

The Requires

 

The Development Requires

database phpunit testing

22/03 2017

0.3.0

0.3.0.0

Provides the base TestCase for functional ORM/DB tests.

  Sources   Download

MIT

The Requires

 

The Development Requires

database phpunit testing

26/12 2016

0.2.0

0.2.0.0

Provides the base TestCase for functional ORM/DB tests.

  Sources   Download

MIT

The Requires

 

The Development Requires

database phpunit testing

11/12 2016

0.1.0

0.1.0.0

Provides the base TestCase for functional ORM/DB tests.

  Sources   Download

MIT

The Requires

 

The Development Requires

database phpunit testing