Skip to content
Permalink
Browse files

Renaming event stack to event list.

  • Loading branch information...
burzum committed May 31, 2016
1 parent 06af84b commit 75a9863fb5dae050a6a5185a7ac20c19ab177bdb
@@ -15,9 +15,9 @@
namespace Cake\Event;
/**
* The Event Stack
* The Event List
*/
class EventStack implements \ArrayAccess, \Countable
class EventList implements \ArrayAccess, \Countable
{
/**
@@ -38,7 +38,7 @@ public function flush()
}
/**
* Adds an event to the list when stacking is enabled.
* Adds an event to the list when event listing is enabled.
*
* @param \Cake\Event\Event $event An event to the list of dispatched events.
* @return void
@@ -112,7 +112,7 @@ public function count()
}
/**
* Checks if an event is in the stack.
* Checks if an event is in the list.
*
* @param string $name Event name.
* @return bool
@@ -56,16 +56,16 @@ class EventManager
/**
* The event stack object.
*
* @var \Cake\Event\EventStack|null
* @var \Cake\Event\EventList|null
*/
protected $_eventStack;
protected $_eventList;
/**
* Enables automatic adding of events to the event stack object if it is present.
*
* @param bool
*/
protected $_stackEvents = false;
protected $_listEvents = false;
/**
* Returns the globally available instance of a Cake\Event\EventManager
@@ -360,8 +360,8 @@ public function dispatch($event)
$listeners = $this->listeners($event->name());
if (empty($listeners)) {
if ($this->_stackEvents) {
$this->stackEvent($event);
if ($this->_listEvents) {
$this->listEvent($event);
}
return $event;
}
@@ -379,8 +379,8 @@ public function dispatch($event)
}
}
if ($this->_stackEvents) {
$this->stackEvent($event);
if ($this->_listEvents) {
$this->listEvent($event);
}
return $event;
}
@@ -482,13 +482,13 @@ public function matchingListeners($eventKeyPattern)
}
/**
* Returns the event stack.
* Returns the event list.
*
* @return array
*/
public function eventStack()
public function eventList()
{
return $this->_eventStack;
return $this->_eventList;
}
/**
@@ -497,10 +497,10 @@ public function eventStack()
* @param \Cake\Event\Event $event An event to add to the stack.
* @return void
*/
public function stackEvent(Event $event)
public function listEvent(Event $event)
{
if ($this->_eventStack) {
$this->_eventStack->add($event);
if ($this->_eventList) {
$this->_eventList->add($event);
}
}
@@ -510,32 +510,32 @@ public function stackEvent(Event $event)
* @param bool $enabled True or false to enable / disable it.
* @return void
*/
public function stackEvents($enabled)
public function listEvents($enabled)
{
$this->_stackEvents = (bool)$enabled;
$this->_listEvents = (bool)$enabled;
}
/**
* Enables the stacking of dispatched events.
*
* @param \Cake\Event\EventStack $eventStack The event stack object to use.
* @param \Cake\Event\EventList $eventList The event stack object to use.
* @return void
*/
public function attachEventStack(EventStack $eventStack)
public function attachEventList(EventList $eventList)
{
$this->_eventStack = $eventStack;
$this->_stackEvents = true;
$this->_eventList = $eventList;
$this->_listEvents = true;
}
/**
* Disables the stacking of dispatched events.
*
* @return void
*/
public function detachEventStack()
public function detachEventList()
{
$this->_eventStack = null;
$this->_stackEvents = false;
$this->_eventList = null;
$this->_listEvents = false;
}
/**
@@ -551,8 +551,8 @@ public function __debugInfo()
foreach ($this->_listeners as $key => $listeners) {
$properties['_listeners'][$key] = count($listeners) . ' listener(s)';
}
if ($this->_eventStack) {
foreach ($this->_eventStack as $event) {
if ($this->_eventList) {
foreach ($this->_eventList as $event) {
$properties['_dispatchedEvents'][] = $event->name() . ' with subject ' . get_class($event->subject());
}
}
@@ -15,13 +15,13 @@
namespace Cake\Test\TestCase\Event;
use Cake\Event\Event;
use Cake\Event\EventStack;
use Cake\Event\EventList;
use Cake\TestSuite\TestCase;
/**
* Tests the Cake\Event\EvenStack class functionality
* Tests the Cake\Event\EvenList class functionality
*/
class EvenStackTest extends TestCase
class EvenListTest extends TestCase
{
/**
@@ -31,20 +31,20 @@ class EvenStackTest extends TestCase
*/
public function testAddEventAndFlush()
{
$eventStack = new EventStack();
$eventList = new EventList();
$event = new Event('my_event', $this);
$event2 = new Event('my_second_event', $this);
$eventStack->add($event);
$eventStack->add($event2);
$this->assertCount(2, $eventStack);
$eventList->add($event);
$eventList->add($event2);
$this->assertCount(2, $eventList);
$this->assertEquals($eventStack[0], $event);
$this->assertEquals($eventStack[1], $event2);
$this->assertEquals($eventList[0], $event);
$this->assertEquals($eventList[1], $event2);
$eventStack->flush();
$eventList->flush();
$this->assertCount(0, $eventStack);
$this->assertCount(0, $eventList);
}
/**
@@ -54,28 +54,28 @@ public function testAddEventAndFlush()
*/
public function testArrayAccess()
{
$eventStack = new EventStack();
$eventList = new EventList();
$event = new Event('my_event', $this);
$event2 = new Event('my_second_event', $this);
$eventStack->add($event);
$eventStack->add($event2);
$this->assertCount(2, $eventStack);
$eventList->add($event);
$eventList->add($event2);
$this->assertCount(2, $eventList);
$this->assertTrue($eventStack->hasEvent('my_event'));
$this->assertFalse($eventStack->hasEvent('does-not-exist'));
$this->assertTrue($eventList->hasEvent('my_event'));
$this->assertFalse($eventList->hasEvent('does-not-exist'));
$this->assertEquals($eventStack->offsetGet(0), $event);
$this->assertEquals($eventStack->offsetGet(1), $event2);
$this->assertTrue($eventStack->offsetExists(0));
$this->assertTrue($eventStack->offsetExists(1));
$this->assertFalse($eventStack->offsetExists(2));
$this->assertEquals($eventList->offsetGet(0), $event);
$this->assertEquals($eventList->offsetGet(1), $event2);
$this->assertTrue($eventList->offsetExists(0));
$this->assertTrue($eventList->offsetExists(1));
$this->assertFalse($eventList->offsetExists(2));
$eventStack->offsetUnset(1);
$this->assertCount(1, $eventStack);
$eventList->offsetUnset(1);
$this->assertCount(1, $eventList);
$eventStack->flush();
$eventList->flush();
$this->assertCount(0, $eventStack);
$this->assertCount(0, $eventList);
}
}
@@ -15,9 +15,9 @@
namespace Cake\Test\TestCase\Event;
use Cake\Event\Event;
use Cake\Event\EventList;
use Cake\Event\EventListenerInterface;
use Cake\Event\EventManager;
use Cake\Event\EventStack;
use Cake\TestSuite\TestCase;
/**
@@ -26,7 +26,7 @@
class EventTestListener
{
public $callStack = [];
public $callList = [];
/**
* Test function to be used in event dispatching
@@ -35,7 +35,7 @@ class EventTestListener
*/
public function listenerFunction()
{
$this->callStack[] = __FUNCTION__;
$this->callList[] = __FUNCTION__;
}
/**
@@ -45,7 +45,7 @@ public function listenerFunction()
*/
public function secondListenerFunction()
{
$this->callStack[] = __FUNCTION__;
$this->callList[] = __FUNCTION__;
}
/**
@@ -85,7 +85,7 @@ public function implementedEvents()
*/
public function thirdListenerFunction()
{
$this->callStack[] = __FUNCTION__;
$this->callList[] = __FUNCTION__;
}
}
@@ -393,7 +393,7 @@ public function testDispatchWithKeyName()
$manager->dispatch($event);
$expected = ['listenerFunction'];
$this->assertEquals($expected, $listener->callStack);
$this->assertEquals($expected, $listener->callList);
}
/**
@@ -470,7 +470,7 @@ public function testDispatchPrioritized()
$manager->dispatch($event);
$expected = ['secondListenerFunction', 'listenerFunction'];
$this->assertEquals($expected, $listener->callStack);
$this->assertEquals($expected, $listener->callList);
}
/**
@@ -490,7 +490,7 @@ public function testAttachSubscriber()
$manager->dispatch($event);
$expected = ['listenerFunction'];
$this->assertEquals($expected, $listener->callStack);
$this->assertEquals($expected, $listener->callList);
$event = new Event('another.event', $this, ['some' => 'data']);
$listener->expects($this->at(0))
@@ -600,7 +600,7 @@ public function testStopPropagation()
$manager->dispatch($event);
$expected = ['secondListenerFunction'];
$this->assertEquals($expected, $listener->callStack);
$this->assertEquals($expected, $listener->callList);
EventManager::instance(new EventManager());
}
@@ -633,7 +633,7 @@ public function testDispatchPrioritizedWithGlobal()
$manager->dispatch($event);
$expected = ['listenerFunction', 'secondListenerFunction', 'thirdListenerFunction'];
$this->assertEquals($expected, $listener->callStack);
$this->assertEquals($expected, $listener->callList);
EventManager::instance(new EventManager());
}
@@ -665,7 +665,7 @@ public function testDispatchGlobalBeforeLocal()
$manager->dispatch($event);
$expected = ['listenerFunction', 'secondListenerFunction'];
$this->assertEquals($expected, $listener->callStack);
$this->assertEquals($expected, $listener->callList);
EventManager::instance(new EventManager());
}
@@ -708,8 +708,8 @@ public function testDispatchWithGlobalAndLocalEvents()
$manager->attach([$listener2, 'listenerFunction'], 'fake.event');
$manager->dispatch(new Event('fake.event', $this));
$this->assertEquals(['listenerFunction'], $listener->callStack);
$this->assertEquals(['listenerFunction'], $listener2->callStack);
$this->assertEquals(['listenerFunction'], $listener->callList);
$this->assertEquals(['listenerFunction'], $listener2->callList);
}
/**
@@ -721,29 +721,30 @@ public function testDispatchWithGlobalAndLocalEvents()
*/
public function testGetDispatchedEvents()
{
$eventStack = new EventStack();
$eventList = new EventList();
$event = new Event('my_event', $this);
$event2 = new Event('my_second_event', $this);
$manager = new EventManager();
$manager->attachEventStack($eventStack);
$manager->attachEventList($eventList);
$manager->dispatch($event);
$manager->dispatch($event2);
$result = $manager->eventStack();
$result = $manager->eventList();
$this->assertInstanceOf('\Cake\Event\EventList', $result);
$this->assertCount(2, $result);
$this->assertEquals($result[0], $event);
$this->assertEquals($result[1], $event2);
$manager->eventStack()->flush();
$result = $manager->eventStack();
$manager->eventList()->flush();
$result = $manager->eventList();
$this->assertCount(0, $result);
$manager->detachEventStack();
$manager->detachEventList();
$manager->dispatch($event);
$manager->dispatch($event2);
$result = $manager->eventStack();
$result = $manager->eventList();
$this->assertNull($result);
}
}

0 comments on commit 75a9863

Please sign in to comment.
You can’t perform that action at this time.