public function testMergeInstances()
 {
     $targetConfig = ['foo' => new \stdClass(), 'bar' => new \stdClass()];
     $target = new Controllers();
     foreach ($targetConfig as $key => $item) {
         $target->set($key, $item);
     }
     $sourceConfig = ['bar' => new \stdClass(), 'baz' => new \stdClass()];
     $source = new Controllers();
     foreach ($sourceConfig as $key => $item) {
         $source->set($key, $item);
     }
     $return = $target->merge($source);
     $this->assertSame($return, $target);
     $expected = ['foo' => $targetConfig['foo'], 'bar' => $sourceConfig['bar'], 'baz' => $sourceConfig['baz']];
     $this->assertSame($expected, $target->getInstances());
 }
 public function testInvokeSpecifiedActionAsIndexIfActionIsNotProvided()
 {
     $controller = new FakeController();
     $controllers = new Controllers();
     $controllers->set('FakeController', $controller);
     $events = $this->getMock(Events::CLASS, ['trigger']);
     $plugin = new Forward();
     $plugin->setControllers($controllers);
     $plugin->setEvents($events);
     $events->expects($this->once())->method('trigger')->with($this->callback(function ($event) {
         if (!$event instanceof DispatchEvent) {
             return false;
         }
         if ('index' !== $event->getParam('action')) {
             return false;
         }
         return true;
     }));
     $plugin('FakeController');
 }
 public function testInvoke()
 {
     $controllers = new Controllers();
     $controllers->set('foo', new \stdClass());
     $services = new Services();
     $services->set('Controllers', $controllers);
     $this->setServices($services);
     $rootModel = $this->getMock(ViewModel::CLASS, ['addChild']);
     $toolbarEvent = new ToolbarEvent($rootModel);
     $model = new ViewModel();
     $listener = new ControllersListener();
     $listener->setModel($model);
     $rootModel->expects($this->once())->method('addChild')->with($this->identicalTo($model));
     $listener($toolbarEvent);
     $this->assertTrue(isset($model['controllers']));
     $items = $model['controllers'];
     $this->assertInternalType('array', $items);
     $this->assertSame(1, count($items));
     $this->assertArrayHasKey('foo', $items);
 }