public function nextAfterClose()
 {
     $c = new MockCollection('~');
     $c->open();
     $c->close();
     $c->next();
 }
 /**
  * Returns a collection 
  *
  * @param   string name
  * @param   io.collections.IOElement[] elements
  * @return  io.collections.IOCollection
  */
 protected function newCollection($name, $elements = array())
 {
     $c = new MockCollection($name);
     foreach ($elements as $element) {
         $c->addElement($element);
     }
     return $c;
 }
Example #3
0
 function testLoadPlugins()
 {
     //The hooks
     $hook_A = array('hook' => 'hook_A', 'callback' => 'CallHook', 'recallHook' => true);
     $hook_B = array('hook' => 'hook_B', 'callback' => 'CallHook', 'recallHook' => true);
     $it_hook_p1 = new MockIterator($this);
     $it_hook_p1->setReturnValue('valid', true);
     $it_hook_p1->setReturnValueAt(2, 'valid', false);
     $it_hook_p1->setReturnReferenceAt(0, 'current', $hook_A);
     $it_hook_p1->setReturnReferenceAt(1, 'current', $hook_B);
     $hooks_p1 = new MockCollection($this);
     $hooks_p1->setReturnReference('iterator', $it_hook_p1);
     $it_hook_p2 = new MockIterator($this);
     $it_hook_p2->setReturnValue('valid', true);
     $it_hook_p2->setReturnValueAt(1, 'valid', false);
     $it_hook_p2->setReturnReferenceAt(0, 'current', $hook_A);
     $hooks_p2 = new MockCollection($this);
     $hooks_p2->setReturnReference('iterator', $it_hook_p2);
     //A plugin (available)        --listen A & B
     $plugin_1 = new MockPlugin($this);
     $plugin_1->expectCallCount('getHooksAndCallbacks', 1);
     $plugin_1->setReturnValue('getId', 123);
     $plugin_1->setReturnReference('getHooksAndCallbacks', $hooks_p1);
     //Another Plugin (available)  --listen only A
     $plugin_2 = new MockPlugin($this);
     $plugin_2->expectCallCount('getHooksAndCallbacks', 1);
     $plugin_2->setReturnValue('getId', 124);
     $plugin_2->setReturnReference('getHooksAndCallbacks', $hooks_p2);
     //The plugin factory
     $plugin_factory = new MockPluginFactory($this);
     $plugin_factory->setReturnValue('getAvailablePlugins', array($plugin_1, $plugin_2));
     //The event manager
     $em = new MockEventManager($this);
     $em->expectCallCount('addListener', 3);
     // 2*A+1*B hooks
     $args_0 = array();
     $args_0[] = $hook_A['hook'];
     $args_0[] = $plugin_1;
     $args_0[] = $hook_A['callback'];
     $args_0[] = $hook_A['recallHook'];
     $args_0[] = 0;
     $args_1 = array();
     $args_1[] = $hook_B['hook'];
     $args_1[] = $plugin_1;
     $args_1[] = $hook_B['callback'];
     $args_1[] = $hook_B['recallHook'];
     $args_1[] = 0;
     $args_2 = array();
     $args_2[] = $hook_A['hook'];
     $args_2[] = $plugin_2;
     $args_2[] = $hook_A['callback'];
     $args_2[] = $hook_A['recallHook'];
     $args_2[] = 10;
     $em->expectAt(0, 'addListener', $args_0);
     $em->expectAt(1, 'addListener', $args_1);
     $em->expectAt(2, 'addListener', $args_2);
     //The priorities
     $phgm = new MockPluginHookPriorityManager($this);
     $phgm->expectCallCount('getPriorityForPluginHook', 3);
     $args_phgm_0 = array();
     $args_phgm_0[] = $plugin_1;
     $args_phgm_0[] = $hook_A['hook'];
     $args_phgm_1 = array();
     $args_phgm_1[] = $plugin_1;
     $args_phgm_1[] = $hook_B['hook'];
     $args_phgm_2 = array();
     $args_phgm_2[] = $plugin_2;
     $args_phgm_2[] = $hook_A['hook'];
     $phgm->expectAt(0, 'getPriorityForPluginHook', $args_phgm_0);
     $phgm->expectAt(1, 'getPriorityForPluginHook', $args_phgm_1);
     $phgm->expectAt(2, 'getPriorityForPluginHook', $args_phgm_2);
     $phgm->setReturnValue('getPriorityForPluginHook', 0);
     $phgm->setReturnValueAt(2, 'getPriorityForPluginHook', 10);
     //124|hook_A
     //The plugins manager
     $pm = new PluginManagerTestVersion($this);
     $pm->setReturnReference('_getPluginFactory', $plugin_factory);
     $pm->setReturnReference('_getEventManager', $em);
     $pm->setReturnReference('_getPluginHookPriorityManager', $phgm);
     $pm->PluginManager();
     $this->assertFalse($pm->isPluginsLoaded());
     $pm->loadPlugins();
     $this->assertTrue($pm->isPluginsLoaded());
 }