Skip to content

Commit

Permalink
Update test suite and remove legacy PHPUnit workarounds
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonFrings committed May 17, 2024
1 parent 10b37e0 commit edfcecd
Show file tree
Hide file tree
Showing 19 changed files with 455 additions and 444 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"react/promise": "^3.0 || ^2.7 || ^1.2.1"
},
"require-dev": {
"phpunit/phpunit": "^9.6 || ^5.7",
"phpunit/phpunit": "^9.6 || ^7.5",
"react/async": "^4 || ^3 || ^2",
"react/promise-timer": "^1.9"
},
Expand Down
2 changes: 1 addition & 1 deletion phpunit.xml.legacy
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<!-- PHPUnit configuration file with old format for legacy PHPUnit -->
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/5.7/phpunit.xsd"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/7.5/phpunit.xsd"
bootstrap="vendor/autoload.php"
colors="true">
<testsuites>
Expand Down
8 changes: 4 additions & 4 deletions tests/Config/ConfigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@

namespace React\Tests\Dns\Config;

use React\Tests\Dns\TestCase;
use React\Dns\Config\Config;
use React\Tests\Dns\TestCase;

class ConfigTest extends TestCase
{
public function testLoadsSystemDefault()
{
$config = Config::loadSystemConfigBlocking();

$this->assertInstanceOf('React\Dns\Config\Config', $config);
$this->assertInstanceOf(Config::class, $config);
}

public function testLoadsDefaultPath()
Expand All @@ -22,7 +22,7 @@ public function testLoadsDefaultPath()

$config = Config::loadResolvConfBlocking();

$this->assertInstanceOf('React\Dns\Config\Config', $config);
$this->assertInstanceOf(Config::class, $config);
}

public function testLoadsFromExplicitPath()
Expand All @@ -34,7 +34,7 @@ public function testLoadsFromExplicitPath()

public function testLoadThrowsWhenPathIsInvalid()
{
$this->setExpectedException('RuntimeException');
$this->expectException(\RuntimeException::class);
Config::loadResolvConfBlocking(__DIR__ . '/invalid.conf');
}

Expand Down
6 changes: 3 additions & 3 deletions tests/Config/HostsFileTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@

namespace React\Tests\Dns\Config;

use React\Tests\Dns\TestCase;
use React\Dns\Config\HostsFile;
use React\Tests\Dns\TestCase;

class HostsFileTest extends TestCase
{
public function testLoadsFromDefaultPath()
{
$hosts = HostsFile::loadFromPathBlocking();

$this->assertInstanceOf('React\Dns\Config\HostsFile', $hosts);
$this->assertInstanceOf(HostsFile::class, $hosts);
}

public function testDefaultShouldHaveLocalhostMapped()
Expand All @@ -27,7 +27,7 @@ public function testDefaultShouldHaveLocalhostMapped()

public function testLoadThrowsForInvalidPath()
{
$this->setExpectedException('RuntimeException');
$this->expectException(\RuntimeException::class);
HostsFile::loadFromPathBlocking('does/not/exist');
}

Expand Down
10 changes: 6 additions & 4 deletions tests/FunctionalResolverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

namespace React\Tests\Dns;

use React\Dns\Resolver\Factory;
use React\Dns\Model\Message;
use React\Dns\Query\CancellationException;
use React\Dns\RecordNotFoundException;
use React\Dns\Resolver\Factory;
use React\EventLoop\Loop;

class FunctionalResolverTest extends TestCase
Expand Down Expand Up @@ -116,7 +118,7 @@ public function testResolveInvalidRejects()
});

/** @var \React\Dns\RecordNotFoundException $exception */
$this->assertInstanceOf('React\Dns\RecordNotFoundException', $exception);
$this->assertInstanceOf(RecordNotFoundException::class, $exception);
$this->assertEquals('DNS query for example.invalid (A) returned an error response (Non-Existent Domain / NXDOMAIN)', $exception->getMessage());
$this->assertEquals(Message::RCODE_NAME_ERROR, $exception->getCode());
}
Expand All @@ -138,7 +140,7 @@ public function testResolveCancelledRejectsImmediately()
});

/** @var \React\Dns\Query\CancellationException $exception */
$this->assertInstanceOf('React\Dns\Query\CancellationException', $exception);
$this->assertInstanceOf(CancellationException::class, $exception);
$this->assertEquals('DNS query for google.com (A) has been cancelled', $exception->getMessage());
}

Expand All @@ -157,7 +159,7 @@ public function testResolveAllInvalidTypeRejects()
});

/** @var \React\Dns\RecordNotFoundException $exception */
$this->assertInstanceOf('React\Dns\RecordNotFoundException', $exception);
$this->assertInstanceOf(RecordNotFoundException::class, $exception);
$this->assertEquals('DNS query for google.com (PTR) did not return a valid answer (NOERROR / NODATA)', $exception->getMessage());
$this->assertEquals(0, $exception->getCode());
}
Expand Down
64 changes: 31 additions & 33 deletions tests/Protocol/ParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,10 @@ public function testConvertTcpDumpToBinary($expected, $data)

public function provideConvertTcpDumpToBinary()
{
return [
[chr(0x72).chr(0x62), "72 62"],
[chr(0x72).chr(0x62).chr(0x01).chr(0x00), "72 62 01 00"],
[chr(0x72).chr(0x62).chr(0x01).chr(0x00).chr(0x00).chr(0x01), "72 62 01 00 00 01"],
[chr(0x01).chr(0x00).chr(0x01), "01 00 01"],
];
yield [chr(0x72).chr(0x62), "72 62"];
yield [chr(0x72).chr(0x62).chr(0x01).chr(0x00), "72 62 01 00"];
yield [chr(0x72).chr(0x62).chr(0x01).chr(0x00).chr(0x00).chr(0x01), "72 62 01 00 00 01"];
yield [chr(0x01).chr(0x00).chr(0x01), "01 00 01"];
}

public function testParseRequest()
Expand Down Expand Up @@ -768,7 +766,7 @@ public function testParseIncompleteQuestionThrows()

$data = $this->convertTcpDumpToBinary($data);

$this->setExpectedException('InvalidArgumentException');
$this->expectException(\InvalidArgumentException::class);
$this->parser->parseMessage($data);
}

Expand All @@ -780,7 +778,7 @@ public function testParseIncompleteQuestionLabelThrows()
$data = $this->convertTcpDumpToBinary($data);

$this->setExpectedException('InvalidArgumentException');
$this->expectException(\InvalidArgumentException::class);
$this->parser->parseMessage($data);
}

Expand All @@ -792,7 +790,7 @@ public function testParseIncompleteQuestionNameThrows()
$data = $this->convertTcpDumpToBinary($data);

$this->setExpectedException('InvalidArgumentException');
$this->expectException(\InvalidArgumentException::class);
$this->parser->parseMessage($data);
}

Expand All @@ -804,7 +802,7 @@ public function testParseIncompleteOffsetPointerInQuestionNameThrows()

$data = $this->convertTcpDumpToBinary($data);

$this->setExpectedException('InvalidArgumentException');
$this->expectException(\InvalidArgumentException::class);
$this->parser->parseMessage($data);
}

Expand All @@ -816,7 +814,7 @@ public function testParseInvalidOffsetPointerInQuestionNameThrows()

$data = $this->convertTcpDumpToBinary($data);

$this->setExpectedException('InvalidArgumentException');
$this->expectException(\InvalidArgumentException::class);
$this->parser->parseMessage($data);
}

Expand All @@ -828,7 +826,7 @@ public function testParseInvalidOffsetPointerToSameLabelInQuestionNameThrows()

$data = $this->convertTcpDumpToBinary($data);

$this->setExpectedException('InvalidArgumentException');
$this->expectException(\InvalidArgumentException::class);
$this->parser->parseMessage($data);
}

Expand All @@ -840,7 +838,7 @@ public function testParseInvalidOffsetPointerToPreviousLabelInQuestionNameThrows

$data = $this->convertTcpDumpToBinary($data);

$this->setExpectedException('InvalidArgumentException');
$this->expectException(\InvalidArgumentException::class);
$this->parser->parseMessage($data);
}

Expand All @@ -852,7 +850,7 @@ public function testParseInvalidOffsetPointerToStartOfMessageInQuestionNameThrow

$data = $this->convertTcpDumpToBinary($data);

$this->setExpectedException('InvalidArgumentException');
$this->expectException(\InvalidArgumentException::class);
$this->parser->parseMessage($data);
}

Expand All @@ -866,7 +864,7 @@ public function testParseIncompleteAnswerFieldsThrows()

$data = $this->convertTcpDumpToBinary($data);

$this->setExpectedException('InvalidArgumentException');
$this->expectException(\InvalidArgumentException::class);
$this->parser->parseMessage($data);
}

Expand All @@ -880,7 +878,7 @@ public function testParseMessageResponseWithIncompleteAuthorityRecordThrows()

$data = $this->convertTcpDumpToBinary($data);

$this->setExpectedException('InvalidArgumentException');
$this->expectException(\InvalidArgumentException::class);
$this->parser->parseMessage($data);
}

Expand All @@ -894,7 +892,7 @@ public function testParseMessageResponseWithIncompleteAdditionalRecordThrows()

$data = $this->convertTcpDumpToBinary($data);

$this->setExpectedException('InvalidArgumentException');
$this->expectException(\InvalidArgumentException::class);
$this->parser->parseMessage($data);
}

Expand All @@ -911,7 +909,7 @@ public function testParseIncompleteAnswerRecordDataThrows()

$data = $this->convertTcpDumpToBinary($data);

$this->setExpectedException('InvalidArgumentException');
$this->expectException(\InvalidArgumentException::class);
$this->parser->parseMessage($data);
}

Expand All @@ -923,7 +921,7 @@ public function testParseInvalidNSResponseWhereDomainNameIsMissing()
$data .= "00 01 51 80"; // answer: ttl 86400
$data .= "00 00"; // answer: rdlength 0

$this->setExpectedException('InvalidArgumentException');
$this->expectException(\InvalidArgumentException::class);
$this->parseAnswer($data);
}

Expand All @@ -935,7 +933,7 @@ public function testParseInvalidAResponseWhereIPIsMissing()
$data .= "00 01 51 80"; // answer: ttl 86400
$data .= "00 00"; // answer: rdlength 0

$this->setExpectedException('InvalidArgumentException');
$this->expectException(\InvalidArgumentException::class);
$this->parseAnswer($data);
}

Expand All @@ -947,7 +945,7 @@ public function testParseInvalidAAAAResponseWhereIPIsMissing()
$data .= "00 01 51 80"; // answer: ttl 86400
$data .= "00 00"; // answer: rdlength 0

$this->setExpectedException('InvalidArgumentException');
$this->expectException(\InvalidArgumentException::class);
$this->parseAnswer($data);
}

Expand All @@ -960,7 +958,7 @@ public function testParseInvalidTXTResponseWhereTxtChunkExceedsLimit()
$data .= "00 06"; // answer: rdlength 6
$data .= "06 68 65 6c 6c 6f 6f"; // answer: rdata length 6: helloo

$this->setExpectedException('InvalidArgumentException');
$this->expectException(\InvalidArgumentException::class);
$this->parseAnswer($data);
}

Expand All @@ -973,7 +971,7 @@ public function testParseInvalidMXResponseWhereDomainNameIsIncomplete()
$data .= "00 08"; // answer: rdlength 8
$data .= "00 0a 05 68 65 6c 6c 6f"; // answer: rdata priority 10: hello (missing label end)

$this->setExpectedException('InvalidArgumentException');
$this->expectException(\InvalidArgumentException::class);
$this->parseAnswer($data);
}

Expand All @@ -986,7 +984,7 @@ public function testParseInvalidMXResponseWhereDomainNameIsMissing()
$data .= "00 02"; // answer: rdlength 2
$data .= "00 0a"; // answer: rdata priority 10

$this->setExpectedException('InvalidArgumentException');
$this->expectException(\InvalidArgumentException::class);
$this->parseAnswer($data);
}

Expand All @@ -999,7 +997,7 @@ public function testParseInvalidSRVResponseWhereDomainNameIsIncomplete()
$data .= "00 0b"; // answer: rdlength 11
$data .= "00 0a 00 14 1F 90 04 74 65 73 74"; // answer: rdata priority 10, weight 20, port 8080 test (missing label end)

$this->setExpectedException('InvalidArgumentException');
$this->expectException(\InvalidArgumentException::class);
$this->parseAnswer($data);
}

Expand All @@ -1012,7 +1010,7 @@ public function testParseInvalidSRVResponseWhereDomainNameIsMissing()
$data .= "00 06"; // answer: rdlength 6
$data .= "00 0a 00 14 1F 90"; // answer: rdata priority 10, weight 20, port 8080

$this->setExpectedException('InvalidArgumentException');
$this->expectException(\InvalidArgumentException::class);
$this->parseAnswer($data);
}

Expand All @@ -1025,7 +1023,7 @@ public function testParseInvalidSSHFPResponseWhereRecordIsTooSmall()
$data .= "00 02"; // answer: rdlength 2
$data .= "01 01"; // answer: algorithm 1 (RSA), type 1 (SHA), missing fingerprint

$this->setExpectedException('InvalidArgumentException');
$this->expectException(\InvalidArgumentException::class);
$this->parseAnswer($data);
}

Expand All @@ -1038,7 +1036,7 @@ public function testParseInvalidOPTResponseWhereRecordIsTooSmall()
$data .= "00 03"; // answer: rdlength 3
$data .= "00 00 00"; // answer: type 0, length incomplete

$this->setExpectedException('InvalidArgumentException');
$this->expectException(\InvalidArgumentException::class);
$this->parseAnswer($data);
}

Expand All @@ -1051,7 +1049,7 @@ public function testParseInvalidOPTResponseWhereRecordLengthDoesNotMatchOptType(
$data .= "00 07"; // answer: rdlength 7
$data .= "00 0b 00 03 01 02 03"; // answer: type OPT_TCP_KEEPALIVE, length 3 instead of 2

$this->setExpectedException('InvalidArgumentException');
$this->expectException(\InvalidArgumentException::class);
$this->parseAnswer($data);
}

Expand All @@ -1065,7 +1063,7 @@ public function testParseInvalidSOAResponseWhereFlagsAreMissing()
$data .= "02 6e 73 05 68 65 6c 6c 6f 00"; // answer: rdata ns.hello (mname)
$data .= "01 65 05 68 65 6c 6c 6f 00"; // answer: rdata e.hello (rname)

$this->setExpectedException('InvalidArgumentException');
$this->expectException(\InvalidArgumentException::class);
$this->parseAnswer($data);
}

Expand All @@ -1077,7 +1075,7 @@ public function testParseInvalidCAAResponseEmtpyData()
$data .= "00 01 51 80"; // answer: ttl 86400
$data .= "00 00"; // answer: rdlength 0

$this->setExpectedException('InvalidArgumentException');
$this->expectException(\InvalidArgumentException::class);
$this->parseAnswer($data);
}

Expand All @@ -1090,7 +1088,7 @@ public function testParseInvalidCAAResponseMissingValue()
$data .= "00 07"; // answer: rdlength 22
$data .= "00 05 69 73 73 75 65"; // answer: rdata 0, issue

$this->setExpectedException('InvalidArgumentException');
$this->expectException(\InvalidArgumentException::class);
$this->parseAnswer($data);
}

Expand All @@ -1104,7 +1102,7 @@ public function testParseInvalidCAAResponseIncompleteTag()
$data .= "00 ff 69 73 73 75 65"; // answer: rdata 0, issue (incomplete due to invalid tag length)
$data .= "68 65 6c 6c 6f"; // answer: hello

$this->setExpectedException('InvalidArgumentException');
$this->expectException(\InvalidArgumentException::class);
$this->parseAnswer($data);
}

Expand Down
Loading

0 comments on commit edfcecd

Please sign in to comment.