PHP code example of toast / unit

1. Go to this page and download the library: Download toast/unit 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/ */

    

toast / unit example snippets




/** Description of this group */
return function () : Generator {
    /** Test if true == true */
    yield function () {
        assert(true);
    };
};



return function () : Generator {
    $obj = new My\Thing\Under\Test;
    /** Test method foo */
    yield function () use ($obj) {
        assert($obj->foo());
    };
    /** Test method bar */
    yield function () use ($obj) {
        assert($obj->bar());
    };
};



return function () : Generator {
    $this->beforeEach(function () {
        echo "1\n";
    });
    yield function () : Generator {
        $this->beforeEach(function () {
            echo "2\n";
        });
        yield function () { assert(true); };
    };
    yield function () {
        assert(true);
    };
};



//...
yield function () {
    $foo = new Foo;
    $e = null;
    try {
        $foo->bar();
    } catch (FooException $e) {
    }
    assert($e instanceof FooException);
};



//....
yield function () {
    ob_start();
    thisFunctionPrintsSomething();
    assert(ob_end_clean() == "Hello world!");
};



if (getenv("TOAST")) {
    $db = new PDO('mysql:test');
} else {
    $db = new PDO('mysql:dev');
}