예제 #1
0
    // Check the callback is removed from the child.
    $child_ev_space->removeCallback($callback);
    $tf->assertNotInArray($callback, $child_ev_space->getCallbacks());
    // Check the root Eventspace sees the child.
    $tf->assertTrue($root_ev_space->hasChild($child_name));
    // Check the child is removed from the root.
    $root_ev_space->removeChild($child_name);
    $tf->assertFalse($root_ev_space->hasChild($child_name));
});
$tf->test('Add deep child eventspace with callbacks', function ($tf) {
    // Get the root Eventspace.
    $child_name = 'john';
    $grandchild_name = 'john:lucy';
    $root_ev_space = $tf->data->ev_space;
    // Create Callbacks.
    $callback_john = new \Happen\Callback('\\Happen\\Test\\onJohn');
    $callback_john_lucy = new \Happen\Callback('\\Happen\\Test\\onJohnLucy');
    // Create a deep namespace.
    $grandchild_ev_space = $root_ev_space->addChild($grandchild_name, array($callback_john_lucy));
    // Check a new Eventspace was created.
    $tf->assertTrue($grandchild_ev_space instanceof \Happen\Eventspace);
    // Check the child Eventspace was also created.
    $child_ev_space = $root_ev_space->getChild($child_name);
    $tf->assertTrue($child_ev_space instanceof \Happen\Eventspace);
    // Add a callback to the child event space and check the
    // grandchild space sees it in its callback bubbling hierarchy.
    $child_ev_space->addCallback($callback_john);
    $tf->assertInArray($callback_john, $grandchild_ev_space->getCallbacks(\Happen\Eventspace::BUBBLE));
});
$tf->run();