addEvent() public method

Adds an event to the queue.
public addEvent ( Phergie_Plugin_Abstract $plugin, string $type, array $args = [] ) : Phergie_Event_Handler
$plugin Phergie_Plugin_Abstract Plugin originating the event
$type string Event type, corresponding to a Phergie_Event_Command::TYPE_* constant
$args array Optional event arguments
return Phergie_Event_Handler Provides a fluent interface
Example #1
0
 /**
  * Tests that attempting to add an event to the handler with an invalid
  * type results in an exception.
  *
  * @return void
  */
 public function testAddEventWithInvalidType()
 {
     $type = 'foo';
     try {
         $this->events->addEvent($this->plugin, $type);
         $this->fail('Expected exception was not thrown');
     } catch (Phergie_Event_Exception $e) {
         if ($e->getCode() != Phergie_Event_Exception::ERR_UNKNOWN_EVENT_TYPE) {
             $this->fail('Unexpected exception code ' . $e->getCode());
         }
     }
 }
Example #2
0
 /**
  * addPlugin passes Phergie_Event_Handler to instantiated plugin
  *
  * @return null
  */
 public function testAddPluginPassesPhergieEventHandlerToInstantiatedPlugin()
 {
     $plugin = $this->getMock('Phergie_Plugin_Abstract');
     $plugin->expects($this->any())->method('getName')->will($this->returnValue('TestPlugin'));
     $my_event_handler = new Phergie_Event_Handler();
     $my_event_handler->addEvent($plugin, 'ping');
     // create a new plugin handler with this event handler
     unset($this->handler);
     $this->handler = new Phergie_Plugin_Handler(new Phergie_Config(), $my_event_handler);
     $plugin_name = 'Mock';
     $this->handler->addPath(dirname(__FILE__), 'Phergie_Plugin_');
     $plugin = $this->handler->addPlugin($plugin_name);
     $this->assertSame($my_event_handler, $plugin->getEventHandler(), 'addPlugin passes Phergie_Event_Handler to instantiated plugin');
 }