1
0
mirror of https://github.com/danog/dns.git synced 2024-12-13 09:57:23 +01:00
dns/test/AddrTest/ResponseInterpreterTest.php
Danack a50369e71e Tests, Travis and Cache implementations
- Add tests
 - Configure repo for use with Travis
 - Add some more Cache implementations
2014-07-21 12:24:35 +01:00

45 lines
1.6 KiB
PHP

<?php
namespace AddrTest;
use Addr\ResponseInterpreter;
class ResponseInterpreterTest extends \PHPUnit_Framework_TestCase{
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);
}
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);
}
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);
}
}