public function testInvoke() { $request = $this->getMock(ServerRequest::CLASS, ['getServerParam']); $server = new Server($request); $profiler = $this->getMock(ProfilerListener::CLASS, ['getTimers']); $listeners = new Listeners(); $listeners->set('SystemProfiler', $profiler); $services = new Services(); $services->set('Server', $server); $services->set('Listeners', $listeners); $this->setServices($services); $rootModel = $this->getMock(ViewModel::CLASS, ['addChild']); $toolbarEvent = new ToolbarEvent($rootModel); $timers = ['foo' => ['start' => time() - 100, 'stop' => time()]]; $profiler->expects($this->once())->method('getTimers')->will($this->returnValue($timers)); $request->expects($this->once())->method('getServerParam')->with('REQUEST_TIME_FLOAT')->will($this->returnValue(time() - 360)); $model = new ViewModel(); $listener = new TimersListener(); $listener->setModel($model); $rootModel->expects($this->once())->method('addChild')->with($this->identicalTo($model)); $listener($toolbarEvent); $this->assertTrue(isset($model['timers'])); $items = $model['timers']; $this->assertInternalType('array', $items); $this->assertSame(2, count($items)); $this->assertArrayHasKey('foo', $items); $this->assertTrue($items['foo'] > 360); $this->assertArrayHasKey('Total', $items); $this->assertSame($items['Total'], $items['foo']); }
public function testInvokeThrowExceptionIfListenerMethodIsNotCallable() { $listeners = new Listeners(); $listeners->set('TriggerTest', $this); $trigger = new Trigger('TriggerTest', 'bar'); $trigger->setListeners($listeners); $event = new Event(); $this->setExpectedException('\\RuntimeException'); $trigger($event); }
public function testMergeInstances() { $targetConfig = ['foo' => new \stdClass(), 'bar' => new \stdClass()]; $target = new Listeners(); foreach ($targetConfig as $key => $item) { $target->set($key, $item); } $sourceConfig = ['bar' => new \stdClass(), 'baz' => new \stdClass()]; $source = new Listeners(); 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 testInvoke() { $listeners = new Listeners(); $listeners->set('foo', new \stdClass()); $services = new Services(); $services->set('Listeners', $listeners); $this->setServices($services); $rootModel = $this->getMock(ViewModel::CLASS, ['addChild']); $toolbarEvent = new ToolbarEvent($rootModel); $model = new ViewModel(); $listener = new ListenersListener(); $listener->setModel($model); $rootModel->expects($this->once())->method('addChild')->with($this->identicalTo($model)); $listener($toolbarEvent); $this->assertTrue(isset($model['listeners'])); $items = $model['listeners']; $this->assertInternalType('array', $items); $this->assertSame(1, count($items)); $this->assertArrayHasKey('foo', $items); }
public function testInitOnSuccess() { $events = new Events(); $config = new SystemConfig(); $services = new Services(); $listeners = new Listeners(); $listeners->set('FakeListener', FakeListener::CLASS); $services->set('Listeners', $listeners); Provider::setServices($services); $components = new Components(); $components->register(FakeComponent::CLASS); $components->init($services, $listeners, $events, $config); $component = $components->get(FakeComponent::CLASS); $this->assertSame($component->getServicesConfig(), $services->getRegistry()); $this->assertSame($component->getListenersConfig(), $listeners->getRegistry()); $this->assertSame($component->getSystemConfig(), $config->toArray()); $event = new SystemEvent(); $events->trigger($event); $this->assertTrue($event->getResult(SystemEvent::INIT)); }