FUnit::fixture PHP Method

fixture() public static method

I wish we didn't have to do this. In PHP 5.4 we may just be able to bind the tests to an object and access fixtures via $this
See also: FUnit::setup()
public static fixture ( string $key, mixed $val = null ) : mixed
$key string the key to set or retrieve
$val mixed the value to assign to the key. OPTIONAL
return mixed the value of the $key passed.
    public static function fixture($key, $val = null)
    {
        static::check_current_suite();
        $fix_val = static::get_current_suite()->fixture($key, $val);
        return $fix_val;
    }

Usage Example

<?php

require __DIR__ . '/../vendor/autoload.php';
use FUnit as fu;
use Zend\Stdlib\Hydrator\ObjectProperty;
use Knlv\Zf2\Hydrator\Strategy\MultilineTextStrategy;
fu::setup(function () {
    $hydrator = new ObjectProperty();
    $strategy = new MultilineTextStrategy();
    $hydrator->addStrategy('items', $strategy);
    fu::fixture('strategy', $strategy);
    fu::fixture('hydrator', $hydrator);
});
fu::test('Testing hydrate/extract methods', function () {
    $hydrator = fu::fixture('hydrator');
    $object = new stdClass();
    $object->name = 'test';
    $object->items = array('item1', 'item2', 'item3', 'item4', 'item5');
    $expected = array('name' => 'test', 'items' => <<<EOL
item1
item2
item3
item4
item5
EOL
);
    fu::equal($expected, $hydrator->extract($object), 'Assert extract works');
    fu::equal($object, $hydrator->hydrate($expected, new stdClass()), 'Assert hydrate works');
});
All Usage Examples Of FUnit::fixture