Skip to content

Commit a1dfe66

Browse files
committed
Update test suite and remove legacy PHPUnit workarounds
1 parent 42ff85f commit a1dfe66

9 files changed

+50
-66
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

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public function testLoadsFromExplicitPath()
3434

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

tests/Config/HostsFileTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public function testDefaultShouldHaveLocalhostMapped()
2727

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

tests/Protocol/ParserTest.php

+27-27
Original file line numberDiff line numberDiff line change
@@ -768,7 +768,7 @@ public function testParseIncompleteQuestionThrows()
768768

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

771-
$this->setExpectedException('InvalidArgumentException');
771+
$this->expectException('InvalidArgumentException');
772772
$this->parser->parseMessage($data);
773773
}
774774

@@ -780,7 +780,7 @@ public function testParseIncompleteQuestionLabelThrows()
780780
781781
$data = $this->convertTcpDumpToBinary($data);
782782

783-
$this->setExpectedException('InvalidArgumentException');
783+
$this->expectException('InvalidArgumentException');
784784
$this->parser->parseMessage($data);
785785
}
786786

@@ -792,7 +792,7 @@ public function testParseIncompleteQuestionNameThrows()
792792
793793
$data = $this->convertTcpDumpToBinary($data);
794794

795-
$this->setExpectedException('InvalidArgumentException');
795+
$this->expectException('InvalidArgumentException');
796796
$this->parser->parseMessage($data);
797797
}
798798

@@ -804,7 +804,7 @@ public function testParseIncompleteOffsetPointerInQuestionNameThrows()
804804

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

807-
$this->setExpectedException('InvalidArgumentException');
807+
$this->expectException('InvalidArgumentException');
808808
$this->parser->parseMessage($data);
809809
}
810810

@@ -816,7 +816,7 @@ public function testParseInvalidOffsetPointerInQuestionNameThrows()
816816

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

819-
$this->setExpectedException('InvalidArgumentException');
819+
$this->expectException('InvalidArgumentException');
820820
$this->parser->parseMessage($data);
821821
}
822822

@@ -828,7 +828,7 @@ public function testParseInvalidOffsetPointerToSameLabelInQuestionNameThrows()
828828

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

831-
$this->setExpectedException('InvalidArgumentException');
831+
$this->expectException('InvalidArgumentException');
832832
$this->parser->parseMessage($data);
833833
}
834834

@@ -840,7 +840,7 @@ public function testParseInvalidOffsetPointerToPreviousLabelInQuestionNameThrows
840840

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

843-
$this->setExpectedException('InvalidArgumentException');
843+
$this->expectException('InvalidArgumentException');
844844
$this->parser->parseMessage($data);
845845
}
846846

@@ -852,7 +852,7 @@ public function testParseInvalidOffsetPointerToStartOfMessageInQuestionNameThrow
852852

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

855-
$this->setExpectedException('InvalidArgumentException');
855+
$this->expectException('InvalidArgumentException');
856856
$this->parser->parseMessage($data);
857857
}
858858

@@ -866,7 +866,7 @@ public function testParseIncompleteAnswerFieldsThrows()
866866

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

869-
$this->setExpectedException('InvalidArgumentException');
869+
$this->expectException('InvalidArgumentException');
870870
$this->parser->parseMessage($data);
871871
}
872872

@@ -880,7 +880,7 @@ public function testParseMessageResponseWithIncompleteAuthorityRecordThrows()
880880

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

883-
$this->setExpectedException('InvalidArgumentException');
883+
$this->expectException('InvalidArgumentException');
884884
$this->parser->parseMessage($data);
885885
}
886886

@@ -894,7 +894,7 @@ public function testParseMessageResponseWithIncompleteAdditionalRecordThrows()
894894

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

897-
$this->setExpectedException('InvalidArgumentException');
897+
$this->expectException('InvalidArgumentException');
898898
$this->parser->parseMessage($data);
899899
}
900900

@@ -911,7 +911,7 @@ public function testParseIncompleteAnswerRecordDataThrows()
911911

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

914-
$this->setExpectedException('InvalidArgumentException');
914+
$this->expectException('InvalidArgumentException');
915915
$this->parser->parseMessage($data);
916916
}
917917

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

926-
$this->setExpectedException('InvalidArgumentException');
926+
$this->expectException('InvalidArgumentException');
927927
$this->parseAnswer($data);
928928
}
929929

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

938-
$this->setExpectedException('InvalidArgumentException');
938+
$this->expectException('InvalidArgumentException');
939939
$this->parseAnswer($data);
940940
}
941941

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

950-
$this->setExpectedException('InvalidArgumentException');
950+
$this->expectException('InvalidArgumentException');
951951
$this->parseAnswer($data);
952952
}
953953

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

963-
$this->setExpectedException('InvalidArgumentException');
963+
$this->expectException('InvalidArgumentException');
964964
$this->parseAnswer($data);
965965
}
966966

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

976-
$this->setExpectedException('InvalidArgumentException');
976+
$this->expectException('InvalidArgumentException');
977977
$this->parseAnswer($data);
978978
}
979979

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

989-
$this->setExpectedException('InvalidArgumentException');
989+
$this->expectException('InvalidArgumentException');
990990
$this->parseAnswer($data);
991991
}
992992

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

1002-
$this->setExpectedException('InvalidArgumentException');
1002+
$this->expectException('InvalidArgumentException');
10031003
$this->parseAnswer($data);
10041004
}
10051005

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

1015-
$this->setExpectedException('InvalidArgumentException');
1015+
$this->expectException('InvalidArgumentException');
10161016
$this->parseAnswer($data);
10171017
}
10181018

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

1028-
$this->setExpectedException('InvalidArgumentException');
1028+
$this->expectException('InvalidArgumentException');
10291029
$this->parseAnswer($data);
10301030
}
10311031

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

1041-
$this->setExpectedException('InvalidArgumentException');
1041+
$this->expectException('InvalidArgumentException');
10421042
$this->parseAnswer($data);
10431043
}
10441044

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

1054-
$this->setExpectedException('InvalidArgumentException');
1054+
$this->expectException('InvalidArgumentException');
10551055
$this->parseAnswer($data);
10561056
}
10571057

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

1068-
$this->setExpectedException('InvalidArgumentException');
1068+
$this->expectException('InvalidArgumentException');
10691069
$this->parseAnswer($data);
10701070
}
10711071

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

1080-
$this->setExpectedException('InvalidArgumentException');
1080+
$this->expectException('InvalidArgumentException');
10811081
$this->parseAnswer($data);
10821082
}
10831083

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

1093-
$this->setExpectedException('InvalidArgumentException');
1093+
$this->expectException('InvalidArgumentException');
10941094
$this->parseAnswer($data);
10951095
}
10961096

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

1107-
$this->setExpectedException('InvalidArgumentException');
1107+
$this->expectException('InvalidArgumentException');
11081108
$this->parseAnswer($data);
11091109
}
11101110

tests/Query/TcpTransportExecutorTest.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -75,23 +75,23 @@ public function testCtorShouldThrowWhenNameserverAddressIsInvalid()
7575
{
7676
$loop = $this->getMockBuilder('React\EventLoop\LoopInterface')->getMock();
7777

78-
$this->setExpectedException('InvalidArgumentException');
78+
$this->expectException('InvalidArgumentException');
7979
new TcpTransportExecutor('///', $loop);
8080
}
8181

8282
public function testCtorShouldThrowWhenNameserverAddressContainsHostname()
8383
{
8484
$loop = $this->getMockBuilder('React\EventLoop\LoopInterface')->getMock();
8585

86-
$this->setExpectedException('InvalidArgumentException');
86+
$this->expectException('InvalidArgumentException');
8787
new TcpTransportExecutor('localhost', $loop);
8888
}
8989

9090
public function testCtorShouldThrowWhenNameserverSchemeIsInvalid()
9191
{
9292
$loop = $this->getMockBuilder('React\EventLoop\LoopInterface')->getMock();
9393

94-
$this->setExpectedException('InvalidArgumentException');
94+
$this->expectException('InvalidArgumentException');
9595
new TcpTransportExecutor('udp://1.2.3.4', $loop);
9696
}
9797

@@ -400,7 +400,7 @@ public function testQueryRejectsWhenClientKeepsSendingWhenServerClosesSocketWith
400400
$this->assertNull($error);
401401

402402
// expect EPIPE (Broken pipe), except for macOS kernel race condition
403-
$this->setExpectedException(
403+
$this->expectException(
404404
'RuntimeException',
405405
'Unable to send query to DNS server tcp://' . $address . ' (',
406406
defined('SOCKET_EPIPE') ? (PHP_OS !== 'Darwin' || $writePending ? SOCKET_EPIPE : SOCKET_EPROTOTYPE) : null

tests/Query/UdpTransportExecutorTest.php

+7-7
Original file line numberDiff line numberDiff line change
@@ -75,23 +75,23 @@ public function testCtorShouldThrowWhenNameserverAddressIsInvalid()
7575
{
7676
$loop = $this->getMockBuilder('React\EventLoop\LoopInterface')->getMock();
7777

78-
$this->setExpectedException('InvalidArgumentException');
78+
$this->expectException('InvalidArgumentException');
7979
new UdpTransportExecutor('///', $loop);
8080
}
8181

8282
public function testCtorShouldThrowWhenNameserverAddressContainsHostname()
8383
{
8484
$loop = $this->getMockBuilder('React\EventLoop\LoopInterface')->getMock();
8585

86-
$this->setExpectedException('InvalidArgumentException');
86+
$this->expectException('InvalidArgumentException');
8787
new UdpTransportExecutor('localhost', $loop);
8888
}
8989

9090
public function testCtorShouldThrowWhenNameserverSchemeIsInvalid()
9191
{
9292
$loop = $this->getMockBuilder('React\EventLoop\LoopInterface')->getMock();
9393

94-
$this->setExpectedException('InvalidArgumentException');
94+
$this->expectException('InvalidArgumentException');
9595
new UdpTransportExecutor('tcp://1.2.3.4', $loop);
9696
}
9797

@@ -112,7 +112,7 @@ public function testQueryRejectsIfMessageExceedsUdpSize()
112112
$exception = $reason;
113113
});
114114

115-
$this->setExpectedException(
115+
$this->expectException(
116116
'RuntimeException',
117117
'DNS query for ' . $query->name . ' (A) failed: Query too large for UDP transport',
118118
defined('SOCKET_EMSGSIZE') ? SOCKET_EMSGSIZE : 90
@@ -141,7 +141,7 @@ public function testQueryRejectsIfServerConnectionFails()
141141
$exception = $reason;
142142
});
143143

144-
$this->setExpectedException(
144+
$this->expectException(
145145
'RuntimeException',
146146
'DNS query for google.com (A) failed: Unable to connect to DNS server /// (Failed to parse address "///")'
147147
);
@@ -179,7 +179,7 @@ public function testQueryRejectsIfSendToServerFailsAfterConnectionWithoutCalling
179179
});
180180

181181
// ECONNREFUSED (Connection refused) on Linux, EMSGSIZE (Message too long) on macOS
182-
$this->setExpectedException(
182+
$this->expectException(
183183
'RuntimeException',
184184
'DNS query for ' . $query->name . ' (A) failed: Unable to send query to DNS server udp://0.0.0.0:53 ('
185185
);
@@ -336,7 +336,7 @@ public function testQueryRejectsIfServerSendsTruncatedResponse()
336336

337337
$promise = $executor->query($query);
338338

339-
$this->setExpectedException(
339+
$this->expectException(
340340
'RuntimeException',
341341
'DNS query for google.com (A) failed: The DNS server udp://' . $address . ' returned a truncated result for a UDP query',
342342
defined('SOCKET_EMSGSIZE') ? SOCKET_EMSGSIZE : 90

0 commit comments

Comments
 (0)