protected function setUp() { $this->Callbacks = array(); $this->Mediator = $this->getMockForAbstractClass('\\BLW\\Type\\IMediator'); $this->Event = $this->getMockForAbstractClass('\\BLW\\Type\\IEvent'); $this->Mediatable = $this->getMockForAbstractClass('\\BLW\\Type\\AMediatable'); $this->Mediator->expects($this->any())->method('register')->will($this->returnCallback(array($this, 'mock_register'))); $this->Mediator->expects($this->any())->method('trigger')->will($this->returnCallback(array($this, 'mock_trigger'))); }
/** * Unsets the value at the specified index * * @link http://www.php.net/manual/en/arrayaccess.offsetunset.php ArrayAccess::offsetUnset() * * @param mixed $index * The index being unset. */ public function offsetUnset($index) { // Does index exist? if (ArrayObject::offsetExists($index)) { // Deregister object $this->_Mediator->remSubscriber(ArrayObject::offsetGet($index)); // Unset object ArrayObject::offsetUnset($index); } }
/** * @covers ::offsetUnset */ public function test_offsetUnset() { $Subscriber = new MockEventSubscriber2(); $this->Container->append($Subscriber); $this->Container->append($Subscriber); $this->assertCount(2, $this->Container, 'SubscriberContainer::offsetSet() Failed to accept subscribers'); unset($this->Container[0]); $this->assertCount(1, $this->Container, 'SubscriberContainer::offsetSet() Failed to accept subscribers'); unset($this->Container[1]); $this->assertFalse($this->Mediator->isRegistered('pre.foo'), 'SubscriberContainer::offsetUnset() Failed to unsubscribe events'); # Invalid arguments unset($this->Container[100]); }
/** * @depends test_trigger * @covers ::_dispatch */ public function test_dispatch() { # Test call parameters $Test = new MockWithDispatcher(); $Event = new GenericEvent(); $this->Mediator->register('foo', array($Test, 'foo')); $this->Mediator->register('foo', function ($Event) { $Event->stopPropagation(); }, -100); $this->Mediator->trigger('foo', $Event); $this->assertSame($Event, $Test->Event, 'IMediator::trigger() did not pass event object to registered callback'); $this->assertSame('foo', $Test->Name, 'IMediator::trigger() did not pass event name to registered callback'); $this->assertSame($this->Mediator, $Test->Mediator, 'IMediator::trigger() did not pass event dispatcher to registered callback'); }