Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/Query/RetryExecutor.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ public function tryQuery(Query $query, $retries)
// avoid garbage references by replacing all closures in call stack.
// what a lovely piece of code!
$r = new \ReflectionProperty(\Exception::class, 'trace');
$r->setAccessible(true);
if (\PHP_VERSION_ID < 80100) {
$r->setAccessible(true);
}
$trace = $r->getValue($e);

// Exception trace arguments are not available on some PHP 7.4 installs
Expand Down
48 changes: 36 additions & 12 deletions tests/Query/TcpTransportExecutorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ public function testCtorShouldAcceptNameserverAddresses($input, $expected)
$executor = new TcpTransportExecutor($input, $loop);

$ref = new \ReflectionProperty($executor, 'nameserver');
$ref->setAccessible(true);
if (\PHP_VERSION_ID < 80100) {
$ref->setAccessible(true);
}
$value = $ref->getValue($executor);

$this->assertEquals($expected, $value);
Expand Down Expand Up @@ -70,7 +72,9 @@ public function testCtorWithoutLoopShouldAssignDefaultLoop()
$executor = new TcpTransportExecutor('127.0.0.1');

$ref = new \ReflectionProperty($executor, 'loop');
$ref->setAccessible(true);
if (\PHP_VERSION_ID < 80100) {
$ref->setAccessible(true);
}
$loop = $ref->getValue($executor);

$this->assertInstanceOf(LoopInterface::class, $loop);
Expand Down Expand Up @@ -128,7 +132,9 @@ public function testQueryRejectsIfServerConnectionFails()
$executor = new TcpTransportExecutor('::1', $loop);

$ref = new \ReflectionProperty($executor, 'nameserver');
$ref->setAccessible(true);
if (\PHP_VERSION_ID < 80100) {
$ref->setAccessible(true);
}
$ref->setValue($executor, '///');

$query = new Query('google.com', Message::TYPE_A, Message::CLASS_IN);
Expand Down Expand Up @@ -307,7 +313,9 @@ public function testQueryStaysPendingWhenClientCanNotSendExcessiveMessageInOneCh
$promise->then($this->expectCallableNever(), $this->expectCallableNever());

$ref = new \ReflectionProperty($executor, 'writePending');
$ref->setAccessible(true);
if (\PHP_VERSION_ID < 80100) {
$ref->setAccessible(true);
}
$writePending = $ref->getValue($executor);

$this->assertTrue($writePending);
Expand Down Expand Up @@ -349,7 +357,9 @@ public function testQueryStaysPendingWhenClientCanNotSendExcessiveMessageInOneCh
$promise->then($this->expectCallableNever(), $this->expectCallableNever());

$ref = new \ReflectionProperty($executor, 'writePending');
$ref->setAccessible(true);
if (\PHP_VERSION_ID < 80100) {
$ref->setAccessible(true);
}
$writePending = $ref->getValue($executor);

$this->assertTrue($writePending);
Expand Down Expand Up @@ -390,7 +400,9 @@ public function testQueryRejectsWhenClientKeepsSendingWhenServerClosesSocketWith
$executor->handleWritable();

$ref = new \ReflectionProperty($executor, 'writePending');
$ref->setAccessible(true);
if (\PHP_VERSION_ID < 80100) {
$ref->setAccessible(true);
}
$writePending = $ref->getValue($executor);

// We expect an EPIPE (Broken pipe) on second write.
Expand Down Expand Up @@ -745,7 +757,9 @@ public function testQueryResolvesIfServerSendsBackResponseMessageAndWillStartIdl

// use outgoing buffer as response message
$ref = new \ReflectionProperty($executor, 'writeBuffer');
$ref->setAccessible(true);
if (\PHP_VERSION_ID < 80100) {
$ref->setAccessible(true);
}
$data = $ref->getValue($executor);

$client = stream_socket_accept($server);
Expand Down Expand Up @@ -780,7 +794,9 @@ public function testQueryResolvesIfServerSendsBackResponseMessageAfterCancelling

// use outgoing buffer as response message
$ref = new \ReflectionProperty($executor, 'writeBuffer');
$ref->setAccessible(true);
if (\PHP_VERSION_ID < 80100) {
$ref->setAccessible(true);
}
$data = $ref->getValue($executor);

$client = stream_socket_accept($server);
Expand Down Expand Up @@ -813,7 +829,9 @@ public function testQueryResolvesIfServerSendsBackResponseMessageAfterCancelling

// use outgoing buffer as response message
$ref = new \ReflectionProperty($executor, 'writeBuffer');
$ref->setAccessible(true);
if (\PHP_VERSION_ID < 80100) {
$ref->setAccessible(true);
}
$data = $ref->getValue($executor);

$client = stream_socket_accept($server);
Expand Down Expand Up @@ -854,7 +872,9 @@ public function testTriggerIdleTimerAfterPreviousQueryResolvedWillCloseIdleSocke

// use outgoing buffer as response message
$ref = new \ReflectionProperty($executor, 'writeBuffer');
$ref->setAccessible(true);
if (\PHP_VERSION_ID < 80100) {
$ref->setAccessible(true);
}
$data = $ref->getValue($executor);

$client = stream_socket_accept($server);
Expand Down Expand Up @@ -892,7 +912,9 @@ public function testClosingConnectionAfterPreviousQueryResolvedWillCancelIdleTim

// use outgoing buffer as response message
$ref = new \ReflectionProperty($executor, 'writeBuffer');
$ref->setAccessible(true);
if (\PHP_VERSION_ID < 80100) {
$ref->setAccessible(true);
}
$data = $ref->getValue($executor);

$client = stream_socket_accept($server);
Expand Down Expand Up @@ -930,7 +952,9 @@ public function testQueryAgainAfterPreviousQueryResolvedWillReuseSocketAndCancel

// use outgoing buffer as response message
$ref = new \ReflectionProperty($executor, 'writeBuffer');
$ref->setAccessible(true);
if (\PHP_VERSION_ID < 80100) {
$ref->setAccessible(true);
}
$data = $ref->getValue($executor);

$client = stream_socket_accept($server);
Expand Down
4 changes: 3 additions & 1 deletion tests/Query/TimeoutExecutorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ public function testCtorWithoutLoopShouldAssignDefaultLoop()
$executor = new TimeoutExecutor($this->executor, 5.0);

$ref = new \ReflectionProperty($executor, 'loop');
$ref->setAccessible(true);
if (\PHP_VERSION_ID < 80100) {
$ref->setAccessible(true);
}
$loop = $ref->getValue($executor);

$this->assertInstanceOf(LoopInterface::class, $loop);
Expand Down
16 changes: 12 additions & 4 deletions tests/Query/UdpTransportExecutorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ public function testCtorShouldAcceptNameserverAddresses($input, $expected)
$executor = new UdpTransportExecutor($input, $loop);

$ref = new \ReflectionProperty($executor, 'nameserver');
$ref->setAccessible(true);
if (\PHP_VERSION_ID < 80100) {
$ref->setAccessible(true);
}
$value = $ref->getValue($executor);

$this->assertEquals($expected, $value);
Expand Down Expand Up @@ -69,7 +71,9 @@ public function testCtorWithoutLoopShouldAssignDefaultLoop()
$executor = new UdpTransportExecutor('127.0.0.1');

$ref = new \ReflectionProperty($executor, 'loop');
$ref->setAccessible(true);
if (\PHP_VERSION_ID < 80100) {
$ref->setAccessible(true);
}
$loop = $ref->getValue($executor);

$this->assertInstanceOf(LoopInterface::class, $loop);
Expand Down Expand Up @@ -132,7 +136,9 @@ public function testQueryRejectsIfServerConnectionFails()
$executor = new UdpTransportExecutor('::1', $loop);

$ref = new \ReflectionProperty($executor, 'nameserver');
$ref->setAccessible(true);
if (\PHP_VERSION_ID < 80100) {
$ref->setAccessible(true);
}
$ref->setValue($executor, '///');

$query = new Query('google.com', Message::TYPE_A, Message::CLASS_IN);
Expand Down Expand Up @@ -161,7 +167,9 @@ public function testQueryRejectsIfSendToServerFailsAfterConnectionWithoutCalling

// increase hard-coded maximum packet size to allow sending excessive data
$ref = new \ReflectionProperty($executor, 'maxPacketSize');
$ref->setAccessible(true);
if (\PHP_VERSION_ID < 80100) {
$ref->setAccessible(true);
}
$ref->setValue($executor, PHP_INT_MAX);

$error = null;
Expand Down
Loading