Git Product home page Git Product logo

phpunit-dynamic-fixture's Introduction

SensioLabsInsight Build Status Scrutinizer Quality Score Code Coverage

DynamicFixture

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

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.

Installation

Composer

Simply add this to your composer.json file:

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

Then run php composer.phar install

PhpUnit configuration

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

<?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.

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:

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

phpunit-dynamic-fixture's People

Contributors

grahamcampbell avatar nikoms avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

folsh

phpunit-dynamic-fixture's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.