<?php namespace Happen; /** * Tests for \Happen\Eventspace */ include 'common.php'; $tf = new \Testify\Testify('Happen\\Eventspace'); // Create the root Eventspace. $tf->beforeEach(function ($tf) { $tf->data->ev_space = new \Happen\Eventspace(); }); $tf->test('Add child eventspace with callback', function ($tf) { // Get the root Eventspace. $child_name = 'john'; $root_ev_space = $tf->data->ev_space; // Create a Callback. $callback = new \Happen\Callback('\\Happen\\Test\\onJohn'); // Add the Callback to a child eventspace $child_ev_space = $root_ev_space->addChild($child_name, array($callback)); // Check a new Eventspace was created. $tf->assertTrue($child_ev_space instanceof \Happen\Eventspace); // Check the Eventspace name was set. $tf->assertEquals($child_ev_space->name, $child_name); // Check the Eventspace parent was set. $tf->assertIdentical($child_ev_space->parent, $root_ev_space); // Check the callback was added to the child Eventspace. $tf->assertInArray($callback, $child_ev_space->callbacks); $tf->assertInArray($callback, $child_ev_space->getCallbacks()); // Check the callback is removed from the child.
<?php namespace Happen; /** * Tests for \Happen\Emitter */ include 'common.php'; $tf = new \Testify\Testify("Happen\\Emitter"); // Create the Emitter. $tf->beforeEach(function ($tf) { $tf->data->emitter = new \Happen\Emitter(); }); /** * Check closures are bound. */ $tf->test('Bind a closure', function ($tf) { $emitter = $tf->data->emitter; // Check we can bind a closure $emitter->on('ev_a', function ($tf) { }); $emitter->trigger('ev_a', array($tf)); // Why not eh? $tf->pass(); }); \Happen\Happen::run(function () use($tf) { $tf->run(); });