/** * Overrides the runTest method to add additional annotations * @return PHPUnit_Framework_TestResult */ protected function runTest() { if (null === $this->plugin) { throw new RuntimeException('Tests cannot be run before plugin is set'); } // Clean the event handler... important! $this->handler->clearEvents(); $info = $this->getAnnotations(); $event = null; $eventArgs = array(); if (isset($info['method']['event']) && isset($info['method']['event'][0])) { if (!is_string($info['method']['event'][0])) { throw new InvalidArgumentException('Only one event may be specified'); } $event = $info['method']['event'][0]; if (stristr($event, '::')) { $event = explode('::', $event); } } if (isset($info['method']['eventArg'])) { $eventArgs = $info['method']['eventArg']; } if (null !== $event) { $this->setEvent($event, $eventArgs); } $testResult = parent::runTest(); // Clean the event handler again... just incase this time. $this->handler->clearEvents(); return $testResult; }
/** * Tests that the events contained within the handler can be * collectively removed. * * @return void * @depends testGetEvents * @depends testAddEventWithValidData */ public function testClearEvents() { $this->addMockEvent(); $this->events->clearEvents(); $expected = array(); $actual = $this->events->getEvents(); $this->assertSame($expected, $actual); }
/** * Sends resulting outgoing events from earlier processing in handleEvents(). * * @param Phergie_Connection $connection Active connection * * @return void */ protected function processEvents(Phergie_Connection $connection) { $this->plugins->preDispatch(); if (count($this->events)) { foreach ($this->events as $event) { $this->ui->onCommand($event, $connection); $method = 'do' . ucfirst(strtolower($event->getType())); call_user_func_array(array($this->driver, $method), $event->getArguments()); } } $this->plugins->postDispatch(); if ($this->events->hasEventOfType(Phergie_Event_Request::TYPE_QUIT)) { $this->ui->onQuit($connection); $this->connections->removeConnection($connection); } $this->events->clearEvents(); }