mirror of
https://github.com/danog/dns.git
synced 2024-12-13 09:57:23 +01:00
a30ead4952
I am anal. I am also sorry. Deal with it.
45 lines
1.6 KiB
PHP
45 lines
1.6 KiB
PHP
<?php
|
|
|
|
namespace AddrTest;
|
|
|
|
use Addr\ResponseInterpreter;
|
|
|
|
class ResponseInterpreterTest extends \PHPUnit_Framework_TestCase
|
|
{
|
|
public function testCatchesExceptionAndReturnsNull()
|
|
{
|
|
$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);
|
|
}
|
|
|
|
public function testInvalidMessage()
|
|
{
|
|
$message = \Mockery::mock('LibDNS\Messages\Message');
|
|
$message->shouldReceive('getType')->once()->andReturn(\LibDNS\Messages\MessageTypes::QUERY);
|
|
|
|
$decoder = \Mockery::mock('LibDNS\Decoder\Decoder');
|
|
$decoder->shouldReceive('decode')->once()->andReturn($message);
|
|
|
|
$responseInterpreter = new ResponseInterpreter($decoder);
|
|
$result = $responseInterpreter->decode("SomePacket");
|
|
$this->assertNull($result);
|
|
}
|
|
|
|
public function testInvalidResponseCode()
|
|
{
|
|
$message = \Mockery::mock('LibDNS\Messages\Message');
|
|
$message->shouldReceive('getType')->once()->andReturn(\LibDNS\Messages\MessageTypes::RESPONSE);
|
|
$message->shouldReceive('getResponseCode')->once()->andReturn(42);
|
|
|
|
$decoder = \Mockery::mock('LibDNS\Decoder\Decoder');
|
|
$decoder->shouldReceive('decode')->once()->andReturn($message);
|
|
|
|
$responseInterpreter = new ResponseInterpreter($decoder);
|
|
$result = $responseInterpreter->decode("SomePacket");
|
|
$this->assertNull($result);
|
|
}
|
|
}
|