mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 11:28:25 +00:00
Testing the subscriber object attaching to the manager
This commit is contained in:
parent
bef20e6175
commit
adf95a7ac6
1 changed files with 46 additions and 0 deletions
|
@ -21,6 +21,7 @@
|
|||
|
||||
App::uses('CakeEvent', 'Event');
|
||||
App::uses('CakeEventManager', 'Event');
|
||||
App::uses('CakeEventListener', 'Event');
|
||||
|
||||
/**
|
||||
* Mock class used to test event dispatching
|
||||
|
@ -50,6 +51,30 @@ class CakeEventTestListener {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Mock used for testing the subscriber objects
|
||||
*
|
||||
* @package Cake.Test.Case.Event
|
||||
*/
|
||||
class CustomTestEventListerner extends CakeEventTestListener implements CakeEventListener {
|
||||
|
||||
public function implementedEvents() {
|
||||
return array(
|
||||
'fake.event' => 'listenerFunction',
|
||||
'another.event' => array('callable' => 'secondListenerFunction', 'passParams' => true)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test function to be used in event dispatching
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function thirdListenerFunction() {
|
||||
$this->callStack[] = __FUNCTION__;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the CakeEventManager class functionality
|
||||
*
|
||||
|
@ -205,4 +230,25 @@ class CakeEventManagerTest extends CakeTestCase {
|
|||
$anotherListener->expects($this->once())->method('secondListenerFunction')->with('data');
|
||||
$manager->dispatch($event);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests subscribing a listener object and firing the events it subscribed to
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testAttachSubscriber() {
|
||||
$manager = new CakeEventManager;
|
||||
$listener = $this->getMock('CustomTestEventListerner', array('secondListenerFunction'));
|
||||
$manager->attach($listener);
|
||||
$event = new CakeEvent('fake.event');
|
||||
|
||||
$manager->dispatch($event);
|
||||
|
||||
$expected = array('listenerFunction');
|
||||
$this->assertEquals($expected, $listener->callStack);
|
||||
|
||||
$listener->expects($this->once())->method('secondListenerFunction')->with('data');
|
||||
$event = new CakeEvent('another.event', $this, array('some' => 'data'));
|
||||
$manager->dispatch($event);
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue