PHP code example of folsh / phpunit-dynamic-fixture

1. Go to this page and download the library: Download folsh/phpunit-dynamic-fixture library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

folsh / phpunit-dynamic-fixture example snippets


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"
    }
}

class MyTest extends PHPUnit_Framework_TestCase {

    private $name1;
    private $name2;
    private $list;

    /**
     * Must be public
     */
    public function setUpNames($name1, $name2)
    {
        $this->name1 = $name1;
        $this->name2 = $name2;
    }

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

    /**
     * @setUpContext setUpNames("Nicolas", "Cedric")
     */
    public function testSetUpNames()
    {
        //$this->name1 is "Nicolas"
        //$this->name2 is "Cedric"
    }
}

class MyTest extends PHPUnit_Framework_TestCase {

    private $list;

    /**
     * Must be public
     */
    public function setUpArray(array $list)
    {
        $this->list = $list;
    }

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

    /**
     * @setUpContext setUpArray(["Nicolas", "Cedric"])
     */
    public function testSetUpArray()
    {
        //$this->list is array("Nicolas", "Cedric")
    }
}
xml
 <listener class="folsh\DynamicFixture\DynamicFixtureListener" file="vendor/folsh/phpunit-dynamic-fixture/src/DynamicFixtureListener.php">
    <arguments>
        <string>myCustomSetUp</string>
    </arguments>
</listener>