mirror of
https://github.com/danog/dns.git
synced 2024-12-13 09:57:23 +01:00
a50369e71e
- Add tests - Configure repo for use with Travis - Add some more Cache implementations
45 lines
1.6 KiB
PHP
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);
|
|
}
|
|
}
|
|
|
|
|