2014-07-19 15:37:48 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace AddrTest;
|
|
|
|
|
|
|
|
use Addr\ResponseInterpreter;
|
|
|
|
|
2014-07-21 18:48:36 +02:00
|
|
|
class ResponseInterpreterTest extends \PHPUnit_Framework_TestCase
|
|
|
|
{
|
|
|
|
public function testCatchesExceptionAndReturnsNull()
|
|
|
|
{
|
2014-07-19 15:37:48 +02:00
|
|
|
$decoder = \Mockery::mock('LibDNS\Decoder\Decoder');
|
|
|
|
$decoder->shouldReceive('decode')->withAnyArgs()->andThrow("Exception", "Testing bad packet");
|
|
|
|
$responseInterpreter = new ResponseInterpreter($decoder);
|
|
|
|
$result = $responseInterpreter->decode("SomePacket");
|
|
|
|
$this->assertNull($result);
|
|
|
|
}
|
|
|
|
|
2014-07-21 18:48:36 +02:00
|
|
|
public function testInvalidMessage()
|
|
|
|
{
|
2014-07-19 15:37:48 +02:00
|
|
|
$message = \Mockery::mock('LibDNS\Messages\Message');
|
|
|
|
$message->shouldReceive('getType')->once()->andReturn(\LibDNS\Messages\MessageTypes::QUERY);
|
2014-07-21 18:48:36 +02:00
|
|
|
|
2014-07-19 15:37:48 +02:00
|
|
|
$decoder = \Mockery::mock('LibDNS\Decoder\Decoder');
|
|
|
|
$decoder->shouldReceive('decode')->once()->andReturn($message);
|
|
|
|
|
|
|
|
$responseInterpreter = new ResponseInterpreter($decoder);
|
|
|
|
$result = $responseInterpreter->decode("SomePacket");
|
|
|
|
$this->assertNull($result);
|
|
|
|
}
|
|
|
|
|
2014-07-21 18:48:36 +02:00
|
|
|
public function testInvalidResponseCode()
|
|
|
|
{
|
2014-07-19 15:37:48 +02:00
|
|
|
$message = \Mockery::mock('LibDNS\Messages\Message');
|
|
|
|
$message->shouldReceive('getType')->once()->andReturn(\LibDNS\Messages\MessageTypes::RESPONSE);
|
|
|
|
$message->shouldReceive('getResponseCode')->once()->andReturn(42);
|
2014-07-21 18:48:36 +02:00
|
|
|
|
2014-07-19 15:37:48 +02:00
|
|
|
$decoder = \Mockery::mock('LibDNS\Decoder\Decoder');
|
|
|
|
$decoder->shouldReceive('decode')->once()->andReturn($message);
|
|
|
|
|
|
|
|
$responseInterpreter = new ResponseInterpreter($decoder);
|
|
|
|
$result = $responseInterpreter->decode("SomePacket");
|
|
|
|
$this->assertNull($result);
|
|
|
|
}
|
|
|
|
}
|