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);
 }
Ejemplo n.º 2
0
 public function testGetDumpInstances()
 {
     Debug::dump($this);
     $line = __LINE__ - 1;
     $instances = Debug::getDumpInstances();
     $this->assertInternalType('array', $instances);
     $this->assertSame(1, count($instances));
     $this->assertInstanceOf(Dump::CLASS, $instances[0]);
     $dump = $instances[0];
     $this->assertSame($dump->getLine(), $line);
     $this->assertSame($dump->getFile(), __FILE__);
 }
Ejemplo n.º 3
0
 /**
  * Creates the report about debugging dump.
  *
  * @param \Es\System\SystemEvent $event The system event
  */
 public function __invoke(SystemEvent $event)
 {
     $system = $this->getSystem();
     if ($system->isDevMode()) {
         $result = $event->getResult(SystemEvent::FINISH);
         if ($result instanceof ResponseInterface) {
             $contentType = $result->getHeaderLine('Content-Type');
             if (0 === strpos($contentType, 'text/html')) {
                 $model = $this->getModel();
                 $view = $this->getView();
                 $model['dumps'] = Debug::getDumpInstances();
                 $injection = $view->render($model);
                 $body = (string) $result->getBody();
                 $html = str_replace('</body>', $injection . '</body>', $body);
                 $stream = Stream::make($html);
                 $event->setResult(SystemEvent::FINISH, $result->withBody($stream));
             }
         }
     }
 }
Ejemplo n.º 4
0
 public static function resetDebug()
 {
     Debug::$instances = [];
 }