Skip to content

Commit 41f11e0

Browse files
committed
Update test suite and remove legacy PHPUnit workarounds
1 parent 10b37e0 commit 41f11e0

19 files changed

+455
-444
lines changed

composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
"react/promise": "^3.0 || ^2.7 || ^1.2.1"
3333
},
3434
"require-dev": {
35-
"phpunit/phpunit": "^9.6 || ^5.7",
35+
"phpunit/phpunit": "^9.6 || ^7.5",
3636
"react/async": "^4 || ^3 || ^2",
3737
"react/promise-timer": "^1.9"
3838
},

phpunit.xml.legacy

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<!-- PHPUnit configuration file with old format for legacy PHPUnit -->
44
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5-
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/5.7/phpunit.xsd"
5+
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/7.5/phpunit.xsd"
66
bootstrap="vendor/autoload.php"
77
colors="true">
88
<testsuites>

tests/Config/ConfigTest.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,16 @@
22

33
namespace React\Tests\Dns\Config;
44

5-
use React\Tests\Dns\TestCase;
65
use React\Dns\Config\Config;
6+
use React\Tests\Dns\TestCase;
77

88
class ConfigTest extends TestCase
99
{
1010
public function testLoadsSystemDefault()
1111
{
1212
$config = Config::loadSystemConfigBlocking();
1313

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

1717
public function testLoadsDefaultPath()
@@ -22,7 +22,7 @@ public function testLoadsDefaultPath()
2222

2323
$config = Config::loadResolvConfBlocking();
2424

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

2828
public function testLoadsFromExplicitPath()
@@ -34,7 +34,7 @@ public function testLoadsFromExplicitPath()
3434

3535
public function testLoadThrowsWhenPathIsInvalid()
3636
{
37-
$this->setExpectedException('RuntimeException');
37+
$this->expectException(\RuntimeException::class);
3838
Config::loadResolvConfBlocking(__DIR__ . '/invalid.conf');
3939
}
4040

tests/Config/HostsFileTest.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,16 @@
22

33
namespace React\Tests\Dns\Config;
44

5-
use React\Tests\Dns\TestCase;
65
use React\Dns\Config\HostsFile;
6+
use React\Tests\Dns\TestCase;
77

88
class HostsFileTest extends TestCase
99
{
1010
public function testLoadsFromDefaultPath()
1111
{
1212
$hosts = HostsFile::loadFromPathBlocking();
1313

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

1717
public function testDefaultShouldHaveLocalhostMapped()
@@ -27,7 +27,7 @@ public function testDefaultShouldHaveLocalhostMapped()
2727

2828
public function testLoadThrowsForInvalidPath()
2929
{
30-
$this->setExpectedException('RuntimeException');
30+
$this->expectException(\RuntimeException::class);
3131
HostsFile::loadFromPathBlocking('does/not/exist');
3232
}
3333

tests/FunctionalResolverTest.php

+6-4
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22

33
namespace React\Tests\Dns;
44

5-
use React\Dns\Resolver\Factory;
65
use React\Dns\Model\Message;
6+
use React\Dns\Query\CancellationException;
7+
use React\Dns\RecordNotFoundException;
8+
use React\Dns\Resolver\Factory;
79
use React\EventLoop\Loop;
810

911
class FunctionalResolverTest extends TestCase
@@ -116,7 +118,7 @@ public function testResolveInvalidRejects()
116118
});
117119

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

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

@@ -157,7 +159,7 @@ public function testResolveAllInvalidTypeRejects()
157159
});
158160

159161
/** @var \React\Dns\RecordNotFoundException $exception */
160-
$this->assertInstanceOf('React\Dns\RecordNotFoundException', $exception);
162+
$this->assertInstanceOf(RecordNotFoundException::class, $exception);
161163
$this->assertEquals('DNS query for google.com (PTR) did not return a valid answer (NOERROR / NODATA)', $exception->getMessage());
162164
$this->assertEquals(0, $exception->getCode());
163165
}

tests/Protocol/ParserTest.php

+31-33
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,10 @@ public function testConvertTcpDumpToBinary($expected, $data)
2828

2929
public function provideConvertTcpDumpToBinary()
3030
{
31-
return [
32-
[chr(0x72).chr(0x62), "72 62"],
33-
[chr(0x72).chr(0x62).chr(0x01).chr(0x00), "72 62 01 00"],
34-
[chr(0x72).chr(0x62).chr(0x01).chr(0x00).chr(0x00).chr(0x01), "72 62 01 00 00 01"],
35-
[chr(0x01).chr(0x00).chr(0x01), "01 00 01"],
36-
];
31+
yield [chr(0x72).chr(0x62), "72 62"];
32+
yield [chr(0x72).chr(0x62).chr(0x01).chr(0x00), "72 62 01 00"];
33+
yield [chr(0x72).chr(0x62).chr(0x01).chr(0x00).chr(0x00).chr(0x01), "72 62 01 00 00 01"];
34+
yield [chr(0x01).chr(0x00).chr(0x01), "01 00 01"];
3735
}
3836

3937
public function testParseRequest()
@@ -768,7 +766,7 @@ public function testParseIncompleteQuestionThrows()
768766

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

771-
$this->setExpectedException('InvalidArgumentException');
769+
$this->expectException(\InvalidArgumentException::class);
772770
$this->parser->parseMessage($data);
773771
}
774772

@@ -780,7 +778,7 @@ public function testParseIncompleteQuestionLabelThrows()
780778
781779
$data = $this->convertTcpDumpToBinary($data);
782780

783-
$this->setExpectedException('InvalidArgumentException');
781+
$this->expectException(\InvalidArgumentException::class);
784782
$this->parser->parseMessage($data);
785783
}
786784

@@ -792,7 +790,7 @@ public function testParseIncompleteQuestionNameThrows()
792790
793791
$data = $this->convertTcpDumpToBinary($data);
794792

795-
$this->setExpectedException('InvalidArgumentException');
793+
$this->expectException(\InvalidArgumentException::class);
796794
$this->parser->parseMessage($data);
797795
}
798796

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

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

807-
$this->setExpectedException('InvalidArgumentException');
805+
$this->expectException(\InvalidArgumentException::class);
808806
$this->parser->parseMessage($data);
809807
}
810808

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

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

819-
$this->setExpectedException('InvalidArgumentException');
817+
$this->expectException(\InvalidArgumentException::class);
820818
$this->parser->parseMessage($data);
821819
}
822820

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

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

831-
$this->setExpectedException('InvalidArgumentException');
829+
$this->expectException(\InvalidArgumentException::class);
832830
$this->parser->parseMessage($data);
833831
}
834832

@@ -840,7 +838,7 @@ public function testParseInvalidOffsetPointerToPreviousLabelInQuestionNameThrows
840838

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

843-
$this->setExpectedException('InvalidArgumentException');
841+
$this->expectException(\InvalidArgumentException::class);
844842
$this->parser->parseMessage($data);
845843
}
846844

@@ -852,7 +850,7 @@ public function testParseInvalidOffsetPointerToStartOfMessageInQuestionNameThrow
852850

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

855-
$this->setExpectedException('InvalidArgumentException');
853+
$this->expectException(\InvalidArgumentException::class);
856854
$this->parser->parseMessage($data);
857855
}
858856

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

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

869-
$this->setExpectedException('InvalidArgumentException');
867+
$this->expectException(\InvalidArgumentException::class);
870868
$this->parser->parseMessage($data);
871869
}
872870

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

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

883-
$this->setExpectedException('InvalidArgumentException');
881+
$this->expectException(\InvalidArgumentException::class);
884882
$this->parser->parseMessage($data);
885883
}
886884

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

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

897-
$this->setExpectedException('InvalidArgumentException');
895+
$this->expectException(\InvalidArgumentException::class);
898896
$this->parser->parseMessage($data);
899897
}
900898

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

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

914-
$this->setExpectedException('InvalidArgumentException');
912+
$this->expectException(\InvalidArgumentException::class);
915913
$this->parser->parseMessage($data);
916914
}
917915

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

926-
$this->setExpectedException('InvalidArgumentException');
924+
$this->expectException(\InvalidArgumentException::class);
927925
$this->parseAnswer($data);
928926
}
929927

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

938-
$this->setExpectedException('InvalidArgumentException');
936+
$this->expectException(\InvalidArgumentException::class);
939937
$this->parseAnswer($data);
940938
}
941939

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

950-
$this->setExpectedException('InvalidArgumentException');
948+
$this->expectException(\InvalidArgumentException::class);
951949
$this->parseAnswer($data);
952950
}
953951

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

963-
$this->setExpectedException('InvalidArgumentException');
961+
$this->expectException(\InvalidArgumentException::class);
964962
$this->parseAnswer($data);
965963
}
966964

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

976-
$this->setExpectedException('InvalidArgumentException');
974+
$this->expectException(\InvalidArgumentException::class);
977975
$this->parseAnswer($data);
978976
}
979977

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

989-
$this->setExpectedException('InvalidArgumentException');
987+
$this->expectException(\InvalidArgumentException::class);
990988
$this->parseAnswer($data);
991989
}
992990

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

1002-
$this->setExpectedException('InvalidArgumentException');
1000+
$this->expectException(\InvalidArgumentException::class);
10031001
$this->parseAnswer($data);
10041002
}
10051003

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

1015-
$this->setExpectedException('InvalidArgumentException');
1013+
$this->expectException(\InvalidArgumentException::class);
10161014
$this->parseAnswer($data);
10171015
}
10181016

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

1028-
$this->setExpectedException('InvalidArgumentException');
1026+
$this->expectException(\InvalidArgumentException::class);
10291027
$this->parseAnswer($data);
10301028
}
10311029

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

1041-
$this->setExpectedException('InvalidArgumentException');
1039+
$this->expectException(\InvalidArgumentException::class);
10421040
$this->parseAnswer($data);
10431041
}
10441042

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

1054-
$this->setExpectedException('InvalidArgumentException');
1052+
$this->expectException(\InvalidArgumentException::class);
10551053
$this->parseAnswer($data);
10561054
}
10571055

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

1068-
$this->setExpectedException('InvalidArgumentException');
1066+
$this->expectException(\InvalidArgumentException::class);
10691067
$this->parseAnswer($data);
10701068
}
10711069

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

1080-
$this->setExpectedException('InvalidArgumentException');
1078+
$this->expectException(\InvalidArgumentException::class);
10811079
$this->parseAnswer($data);
10821080
}
10831081

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

1093-
$this->setExpectedException('InvalidArgumentException');
1091+
$this->expectException(\InvalidArgumentException::class);
10941092
$this->parseAnswer($data);
10951093
}
10961094

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

1107-
$this->setExpectedException('InvalidArgumentException');
1105+
$this->expectException(\InvalidArgumentException::class);
11081106
$this->parseAnswer($data);
11091107
}
11101108

0 commit comments

Comments
 (0)