/** * Removes a connection from the connection list. * * @param Phergie_Connection|string $connection Instance or hostmask for * the connection to remove * * @return Phergie_Connection_Handler Provides a fluent interface */ public function removeConnection($connection) { if ($connection instanceof Phergie_Connection) { $hostmask = (string) $connection->getHostmask(); } elseif (is_string($connection) && isset($this->connections[$connection])) { $hostmask = $connection; } else { return $this; } unset($this->connections[$hostmask]); return $this; }
/** * Returns a mock connection object. * * @return Phergie_Connection */ protected function getMockConnection() { if (empty($this->connection)) { $this->connection = $this->getMock('Phergie_Connection'); $this->connection->expects($this->any())->method('getNick')->will($this->returnValue($this->nick)); } return $this->connection; }
/** * Sets the plugin to be tested * If a plugin requries config for testing, an array placed in * $this->config will be parsed into a Phergie_Config object and * attached to the plugin */ protected function setPlugin(Phergie_Plugin_Abstract $plugin) { $this->plugin = $plugin; $this->plugin->setEventHandler($this->handler); $this->plugin->setConnection($this->connection); $this->connection->setNick('test'); if (!empty($this->config)) { $config = new Phergie_Config(); foreach ($this->config as $configKey => $configValue) { $config[$configKey] = $configValue; } $plugin->setConfig($config); } }
/** * Tests that options can be set collectively after the connection is * instantiated. * * @return void */ public function testSetOptions() { $connection = new Phergie_Connection(); $connection->setOptions($this->options); foreach ($this->options as $key => $value) { $this->assertEquals($value, $connection->{'get' . ucfirst($key)}()); } }
/** * Overrides the parent class to set the currently active socket handler * when the active connection is changed. * * @param Phergie_Connection $connection Active connection * * @return Phergie_Driver_Streams Provides a fluent interface */ public function setConnection(Phergie_Connection $connection) { // Set the active socket handler $hostmask = (string) $connection->getHostmask(); if (!empty($this->sockets[$hostmask])) { $this->socket = $this->sockets[$hostmask]; } // Set the active connection return parent::setConnection($connection); }
/** * Outputs a prompt when the bot terminates a connection to a server. * * @param Phergie_Connection $connection Terminated connection * * @return void */ public function onQuit(Phergie_Connection $connection) { $host = $connection->getHostmask()->getHost(); $this->console('Disconnecting from ' . $host); }