X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=plugins%2FIrc%2Fextlib%2Fphergie%2FTests%2FPhergie%2FPlugin%2FHandlerTest.php;h=9ecdd327ae4f2eb52f01cea60321c942a9845ff1;hb=326258bfef7282509d719238234038d0f6a8d3ff;hp=0d6ac454a8913c8a58df85d8fcba17fd4de81548;hpb=884b26229d74cc5b386406e3e9125629b4e3ecd0;p=quix0rs-gnu-social.git diff --git a/plugins/Irc/extlib/phergie/Tests/Phergie/Plugin/HandlerTest.php b/plugins/Irc/extlib/phergie/Tests/Phergie/Plugin/HandlerTest.php index 0d6ac454a8..9ecdd327ae 100644 --- a/plugins/Irc/extlib/phergie/Tests/Phergie/Plugin/HandlerTest.php +++ b/plugins/Irc/extlib/phergie/Tests/Phergie/Plugin/HandlerTest.php @@ -108,6 +108,77 @@ class Phergie_Plugin_HandlerTest extends PHPUnit_Framework_TestCase ); } + /** + * Tests that a default iterator is returned if none is explicitly set. + * + * @return void + */ + public function testGetIteratorReturnsDefault() + { + $this->assertType( + 'Phergie_Plugin_Iterator', + $this->handler->getIterator() + ); + } + + /** + * Tests the ability to change the handler's iterator class when a valid + * class is specified. + * + * @return void + */ + public function testSetIteratorClassWithValidClass() + { + eval(' + class DummyIterator extends FilterIterator { + public function accept() { + return true; + } + } + '); + + $this->handler->setIteratorClass('DummyIterator'); + + $this->assertType( + 'DummyIterator', + $this->handler->getIterator() + ); + } + + /** + * Tests that a failure occurs when a nonexistent iterator class is + * specified. + * + * @return void + */ + public function testSetIteratorClassWithNonexistentClass() + { + try { + $this->handler->setIteratorClass('FooIterator'); + $this->fail('Expected exception was not thrown'); + } catch (Phergie_Plugin_Exception $e) { + return; + } + $this->fail('Unexpected exception was thrown'); + } + + /** + * Tests that a failure occurs when a class that is not a subclass of + * FilterIterator is specified. + * + * @return void + */ + public function testSetIteratorClassWithNonFilterIteratorClass() + { + try { + $this->handler->setIteratorClass('ArrayIterator'); + $this->fail('Expected exception was not thrown'); + } catch (Phergie_Plugin_Exception $e) { + return; + } + $this->fail('Unexpected exception was thrown'); + } + /** * Tests countability of the plugin handler. * @@ -178,35 +249,11 @@ class Phergie_Plugin_HandlerTest extends PHPUnit_Framework_TestCase /** * Tests the plugin handler executing a callback on all contained - * plugins where one plugin short-circuits the process. - * - * @return void - */ - public function testImplementsCallWithShortCircuit() - { - $plugin1 = $this->getMockPlugin('TestPlugin1', array('callback')); - $plugin1 - ->expects($this->once()) - ->method('callback') - ->will($this->returnValue(false)); - $this->handler->addPlugin($plugin1); - - $plugin2 = $this->getMockPlugin('TestPlugin2', array('callback')); - $plugin2 - ->expects($this->exactly(0)) - ->method('callback'); - $this->handler->addPlugin($plugin2); - - $this->assertFalse($this->handler->callback()); - } - - /** - * Tests the plugin handler executing a callback on all contained - * plugins where no plugins short-circuit the process. + * plugins. * * @return void */ - public function testImplementsCallWithoutShortCircuit() + public function testImplementsCall() { foreach (range(1, 2) as $index) { $plugin = $this->getMockPlugin('TestPlugin' . $index, array('callback')); @@ -736,4 +783,55 @@ class Phergie_Plugin_HandlerTest extends PHPUnit_Framework_TestCase $actual = $this->handler->getPlugins(array('testplugin1', 'testplugin2')); $this->assertEquals($expected, $actual); } + + /** + * Tests that multiple plugin iterators can be used concurrently. + * + * @return void + */ + public function testUseMultiplePluginIteratorsConcurrently() + { + $plugin1 = $this->getMockPlugin('TestPlugin1'); + $this->handler->addPlugin($plugin1); + + $plugin2 = $this->getMockPlugin('TestPlugin2'); + $this->handler->addPlugin($plugin2); + + $iterator1 = $this->handler->getIterator(); + $iterator1->next(); + $this->assertSame($plugin2, $iterator1->current()); + + $iterator2 = $this->handler->getIterator(); + $this->assertSame($plugin1, $iterator2->current()); + } + + /** + * 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'); + } }