Example #1
0
 /**
  * @param MvcEvent $e
  */
 public function onBootstrap(MvcEvent $e)
 {
     $eventManager = $e->getApplication()->getEventManager();
     $moduleRouteListener = new ModuleRouteListener();
     $moduleRouteListener->attach($eventManager);
     $eventManager->attach(new Request($e->getApplication()->getServiceManager()->get('EddieJaoude\\Zf2Logger')));
     $config = $e->getApplication()->getServiceManager()->get('Config');
     $moduleConfig = $config['EddieJaoude\\Zf2Logger'];
     $response = new Response($e->getApplication()->getServiceManager()->get('EddieJaoude\\Zf2Logger'));
     $mediaTypes = empty($moduleConfig['doNotLog']['mediaTypes']) ? array() : $moduleConfig['doNotLog']['mediaTypes'];
     $response->setIgnoreMediaTypes($mediaTypes);
     $eventManager->attach($response);
     return;
 }
Example #2
0
 public function testLogResponseForBinary()
 {
     $this->instance->setLog($this->logger);
     $this->instance->setIgnoreMediaTypes(array('image/png', 'application/pdf'));
     $request = \Mockery::mock('Zend\\Http\\PhpEnvironment\\Request');
     $request->shouldReceive('getUri')->andReturn(\Mockery::self());
     $request->shouldReceive('getHost')->andReturn('mock.host');
     $eventManager = \Mockery::mock('Zend\\EventManager\\Event')->shouldDeferMissing();
     $eventManager->shouldReceive('getRequest')->andReturn($request);
     $eventManager->shouldReceive('getResponse')->andReturn(\Mockery::self());
     $eventManager->shouldReceive('getHeaders')->andReturn(\Mockery::self());
     $contentType = new \Zend\Http\Header\ContentType();
     $eventManager->shouldReceive('get')->with('Content-Type')->andReturn($contentType->setMediaType('image/png'));
     $eventManager->shouldReceive('getStatusCode')->andReturn('200');
     $eventManager->shouldReceive('getContent')->andReturn(json_encode(array('user' => array('id' => 123, 'name' => 'Test me'))));
     $this->instance->logResponse($eventManager);
     $this->assertTrue(is_int(strpos($this->writer->events[0]['message'], 'mock.host')));
     $this->assertTrue(is_int(strpos($this->writer->events[0]['message'], '200')));
     $this->assertTrue(is_int(strpos($this->writer->events[0]['message'], 'BINARY')));
     $this->assertFalse(is_int(strpos($this->writer->events[0]['message'], '123')));
     $this->assertFalse(is_int(strpos($this->writer->events[0]['message'], 'Test me')));
 }