2017 © Pedro Peláez
 

library unitarum

The PHPUnit library is providing and flexible changing fixtures to database

image

englishdom/unitarum

The PHPUnit library is providing and flexible changing fixtures to database

  • Tuesday, June 26, 2018
  • by newage
  • Repository
  • 2 Watchers
  • 0 Stars
  • 675 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 2 Forks
  • 3 Open issues
  • 11 Versions
  • 238 % Grown

The README.md

Unitarum

The library for providing and flexible changing fixtures for PHPUnit, (*1)

Default fixtures

Fixtures use entities. Entities must provide methods getId and setId. The library propose interface EntityIdentifierInterface with this two methods if it need., (*2)

An entity's example

class User
{
    protected $id;
    protected $name;
    protected $email;

    public function getId()
    {
        return $this->id;
    }

    public function setId($id)
    {
        $this->id = $id;
    }

    public function getName()
    {
        return $this->name;
    }

    public function setName($name)
    {
        $this->name = $name;
    }

    public function getEmail()
    {
        return $this->email;
    }

    public function setEmail($email)
    {
        $this->email = $email;
    }
}

A fixture's example:

$entity = new Entity\User();
$entity->setId(1);
$entity->setName('Test');
$entity->setEmail('test@test.no');

return ['table_name' => $entity];

PhpUnit test

In the test's start need initialize the Unitarum object with two parameters. The first parameter is path to folder with fixtures. The second parameter is dsn connection string to sqlite., (*3)

Test example

use PHPUnit\Framework\TestCase;

class DatabaseTest extends TestCase
{
    protected static $unitarum;

    public static function setUpBeforeClass()
    {
        self::$unitarum = new Unitarum([
            OptionsInterface::FIXTURE_FOLDER_OPTION => '../data',
            OptionsInterface::DSN_OPTION => 'sqlite:data/sqlite.db',
        ]);
    }
}

In the every test's cases need to start and rollback a transaction., (*4)

Test example

class DatabaseTest extends TestCase
{
    protected static $unitarum;

    public static function setUpBeforeClass()
    {
        ...
    }

    public function setUp()
    {
        self::$unitarum->getDataBase()->startTransaction();
        // or notning
    }

    public function tearDown()
    {
        self::$unitarum->getDataBase()->rollbackTransaction();
        //or
        self::$unitarun->truncate();
    }
}

If you don't want to use transaction, you can use TRUNCATE data., (*5)

Setup fixtures

In the test you can apply fixtures and change any data from it. You can call methods from the initialized unitarum object. Called method name must be equals name of fixture file. A method can get one parameter, is it Entity. An entity can rewrite default data from fixture., (*6)

Test example

class DatabaseTest extends TestCase
{
    ...

    public function testApplication()
    {
        $user = new Entity\User();
        $user->setEmail('newemail@email.no');

        $role = new Entity\Role();
        $role->setRole('viewer');
        $role->setUserId($user->getId());

        self::$unitarum->user($user)->role($role);

        // test
        ...
    }
}

The Versions

26/06 2018

dev-master

9999999-dev https://github.com/englishdom/unitarum

The PHPUnit library is providing and flexible changing fixtures to database

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

26/06 2018

0.3.5

0.3.5.0 https://github.com/englishdom/unitarum

The PHPUnit library is providing and flexible changing fixtures to database

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

13/06 2018

0.3.4

0.3.4.0 https://github.com/englishdom/unitarum

The PHPUnit library is providing and flexible changing fixtures to database

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

13/02 2018

0.3.3

0.3.3.0 https://github.com/englishdom/unitarum

The PHPUnit library is providing and flexible changing fixtures to database

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

29/01 2018

0.3.2

0.3.2.0 https://github.com/englishdom/unitarum

The PHPUnit library is providing and flexible changing fixtures to database

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

29/01 2018

0.3.1

0.3.1.0 https://github.com/englishdom/unitarum

The PHPUnit library is providing and flexible changing fixtures to database

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

28/01 2018

0.3.0

0.3.0.0 https://github.com/englishdom/unitarum

The PHPUnit library is providing and flexible changing fixtures to database

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

22/01 2018

0.2.2

0.2.2.0 https://github.com/englishdom/unitarum

The PHPUnit library is providing and flexible changing fixtures to database

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

20/01 2018

0.2.1

0.2.1.0 https://github.com/englishdom/unitarum

The PHPUnit library is providing and flexible changing fixtures to database

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

19/01 2018

0.2

0.2.0.0 https://github.com/englishdom/unitarum

The PHPUnit library is providing and flexible changing fixtures to database

  Sources   Download

Apache 2.0

The Requires

 

The Development Requires

18/01 2018

0.1

0.1.0.0 https://github.com/englishdom/unitarum

The PHPUnit library is providing and flexible changing fixtures to database

  Sources   Download

MIT

The Requires