1
0
mirror of https://github.com/danog/dns.git synced 2024-12-13 09:57:23 +01:00
dns/test/AddrTest/ResponseInterpreterTest.php
Chris Wright a30ead4952 Whitespace and code style fixes
I am anal. I am also sorry. Deal with it.
2014-07-21 17:48:36 +01:00

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);
}
}