예제 #1
0
namespace Happen;

/**
 * Tests for \Happen\Callback
 */
include 'common.php';
$tf = new \Testify\Testify('Happen\\Callback');
/**
 * Check closures are wrapped correctly.
 */
$tf->test('\\Closure wrapping', function ($tf) {
    $callback = new \Happen\Callback(function ($x) {
        return $x + 1;
    });
    $result = $callback(123);
    $tf->assertEqual($result, 124);
});
/**
 * Check functions are wrapped correctly.
 */
$tf->test('Function wrapping', function ($tf) {
    $callback = new \Happen\Callback('\\Happen\\Test\\addOne');
    $result = $callback(123);
    $tf->assertEqual($result, 124);
    // Check we can't set context on a function.
    try {
        $callback->bind((object) array());
        $tf->fail();
    } catch (\Exception $e) {
        $tf->pass();
    }