2017 © Pedro Peláez
 

library phpunit-dynamic-fixture

Dynamic setUp to create an appropriate context in your tests

image

nikoms/phpunit-dynamic-fixture

Dynamic setUp to create an appropriate context in your tests

  • Wednesday, February 15, 2017
  • by Nikoms
  • Repository
  • 2 Watchers
  • 4 Stars
  • 19 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 2 Versions
  • 0 % Grown

The README.md

SensioLabsInsight Build Status Scrutinizer Quality Score Code Coverage, (*1)

DynamicFixture

**This project is dead. Please use this one instead: https://github.com/Nikoms/phpunit-arrange. You won't regret it ;) **, (*2)

Thanks to annotations, this library allows you to call dynamic/custom "setUp" methods before each one of your test. It eases the understanding of your test because you explicitly set which context/variables you will use. It also can speed up your tests as you only initialize what they need., (*3)

Installation

Composer

Simply add this to your composer.json file:, (*4)

"require": {
    "nikoms/phpunit-dynamic-fixture": "dev-master"
}

Then run php composer.phar install, (*5)

PhpUnit configuration

To activate the plugin. Add the listener to your phpunit.xml(.dist) file:, (*6)

<?xml version="1.0" encoding="UTF-8"?>
<phpunit>
    ...
    <listeners>
        <listener class="Nikoms\DynamicFixture\DynamicFixtureListener" file="vendor/nikoms/phpunit-dynamic-fixture/src/DynamicFixtureListener.php" />
    </listeners>
</phpunit>

Usage

Use the annotation "@setUpContext" to call the specified method(s) just before the test. Of course, you can add as many annotations as you want., (*7)

class MyTest extends PHPUnit_Framework_TestCase {

    private $name;

    /**
     * Must be public
     */
    public function setUpName()
    {
        $this->name = 'Nicolas';
    }

    public function initContext()
    {
        //...
    }

    /**
     * @setUpContext setUpName
     * @setUpContext initContext
     * @setUpContext ...
     *
     */
    public function testSetUpName()
    {
        //$this->name is "Nicolas"
    }
}

Customize

If you don't like the name of the annotation, you can change it by passing a new one in the constructor:, (*8)

 <listener class="Nikoms\DynamicFixture\DynamicFixtureListener" file="vendor/nikoms/phpunit-dynamic-fixture/src/DynamicFixtureListener.php">
    <arguments>
        <string>myCustomSetUp</string>
    </arguments>
</listener>

The Versions

15/02 2017

dev-master

9999999-dev

Dynamic setUp to create an appropriate context in your tests

  Sources   Download

MIT

The Development Requires

by Nicolas De Boose

25/08 2014

0.2.0

0.2.0.0

Dynamic setUp to create an appropriate context in your tests

  Sources   Download

MIT

The Development Requires

by Nicolas De Boose