public function testInvoke() { $var = 'bar'; Debug::dump($var); $system = System::init([], true); $view = $this->getMock(View::CLASS, ['render']); $services = new Services(); $services->set('System', $system); $services->set('View', $view); $this->setServices($services); $html = '<body></body>'; $stream = Stream::make($html); $response = new Response(200, $stream, ['Content-Type' => ['text/html']]); $event = new SystemEvent(); $event->setResult(SystemEvent::FINISH, $response); $model = new ViewModel(); $listener = new InjectDumpListener(); $listener->setModel($model); $view->expects($this->once())->method('render')->with($this->identicalTo($model))->will($this->returnValue('foo')); $listener($event); $this->assertTrue(isset($model['dumps'])); $this->assertSame($model['dumps'], Debug::getDumpInstances()); $injected = $event->getResult(SystemEvent::FINISH); $this->assertInstanceOf(Response::CLASS, $injected); $body = $injected->getBody(); $this->assertSame('<body>foo</body>', (string) $body); }
public function testGetSystem() { $system = System::init(); $services = new Services(); $services->set('System', $system); $this->setServices($services); $template = new SystemTraitTemplate(); $this->assertSame($system, $template->getSystem()); }
public function testInvoke() { $system = System::init([], true); $events = $this->getMock(Events::CLASS, ['trigger']); $services = new Services(); $services->set('System', $system); $services->set('Events', $events); $this->setServices($services); $events->expects($this->once())->method('trigger')->with($this->isInstanceOf(ToolbarEvent::CLASS)); $listener = new CreateToolbarListener(); $listener(new SystemEvent()); }
public function testInvoke() { $config = ['components' => ['Es\\Debug\\Component']]; $system = System::init($config); $services = new Services(); $services->set('System', $system); $this->setServices($services); $rootModel = $this->getMock(ViewModel::CLASS, ['addChild']); $toolbarEvent = new ToolbarEvent($rootModel); $model = new ViewModel(); $listener = new ComponentsListener(); $listener->setModel($model); $rootModel->expects($this->once())->method('addChild')->with($this->identicalTo($model)); $listener($toolbarEvent); $this->assertTrue(isset($model['components'])); $items = $model['components']; $this->assertInternalType('array', $items); $this->assertSame(1, count($items)); $this->assertArrayHasKey('Es\\Debug\\Component', $items); }
public function testInvokeCallHtmlErrorStrategyToProcessProductionError() { SystemTestHelper::resetSystem(); $system = System::init([], false); $exception = new Exception(); $systemEvent = $system->getEvent(); $errorEvent = new ErrorEvent(ErrorEvent::FATAL_ERROR, $exception, $system); $server = new Server(); $strategy = $this->getMock(HtmlErrorStrategy::CLASS); $listener = new ErrorListener(); $listener->setDefaultErrorStrategy($strategy); $listener->setServer($server); $strategy->expects($this->once())->method('handleProductionError')->with($this->identicalTo($systemEvent), $this->identicalTo($exception)); $listener($errorEvent); }
public static function resetSystem() { System::$instance = null; }
public function testSetsFinishResultBreakCource() { $system = System::init(); $services = $this->services; $events = $this->getMock(Events::CLASS); $services->set('Events', $events); $course = [SystemEvent::BOOTSTRAP, SystemEvent::ROUTE, SystemEvent::FINISH]; $events->expects($this->atLeastOnce())->method('trigger')->will($this->returnCallback(function ($event) use(&$course) { if ($event->getName() == SystemEvent::ROUTE) { $event->setResult(SystemEvent::FINISH, 'foo'); } $this->assertTrue($event->getName() == array_shift($course)); })); $system->run(); }