Example #1
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')));
 }