/** * Tests adding plugin paths via configuration. * * @return void */ public function testAddPluginPathsViaConfiguration() { $dir = dirname(__FILE__); $prefix = 'Phergie_Plugin_'; $this->settings['plugins.paths'] = array($dir => $prefix); // Reinitialize the handler so the configuration change takes effect // within the constructor $this->handler = new Phergie_Plugin_Handler($this->config, $this->events); $this->handler->setAutoload(true); $this->handler->getPlugin('Mock'); }
/** * Tests an exception is thrown when trying to get a plugin * that is not already loaded and autoload is off * * @depends testDefaultsToNotAutoload * @return void */ public function testExceptionThrownWhenLoadingPluginWithoutAutoload() { $this->handler->addPath(dirname(__FILE__), 'Phergie_Plugin_'); try { $this->handler->getPlugin('Mock'); } catch (Phergie_Plugin_Exception $expected) { $this->assertEquals(Phergie_Plugin_Exception::ERR_PLUGIN_NOT_LOADED, $expected->getCode()); return; } $this->fail('An expected exception has not been raised.'); }
/** * Tests adding plugin paths via configuration. * * @return void */ public function testAddPluginPathsViaConfiguration() { $dir = dirname(__FILE__); $prefix = 'Phergie_Plugin_'; $paths = array($dir => $prefix); $this->config->expects($this->any())->method('offsetExists')->will($this->returnValue(true)); $this->config->expects($this->any())->method('offsetGet')->will($this->returnValue($paths)); // Reinitialize the handler so the configuration change takes effect // within the constructor $this->handler = new Phergie_Plugin_Handler($this->config, $this->events); $this->handler->setAutoload(true); $this->handler->getPlugin('Mock'); }
/** * 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(); }
/** * Modifies the plugin handler to include an expectation of a plugin * being retrieved, indicating a dependency. Note that this must be * called BEFORE executing the plugin code that may load that plugin * dependency, which is usually located in onLoad(). * * @param string $name Short name of the plugin required as a dependency * * @return void */ public function assertRequiresPlugin($name) { $this->plugins->expects($this->atLeastOnce())->method('getPlugin')->with($name); }