Skip to content

Commit 936546b

Browse files
authored
Merge pull request #300 from clue-labs/assert
Update test environment to report failed assertions
2 parents 1bc5337 + 4d44b5a commit 936546b

File tree

6 files changed

+49
-6
lines changed

6 files changed

+49
-6
lines changed

.github/workflows/ci.yml

+2-1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ jobs:
3232
with:
3333
php-version: ${{ matrix.php }}
3434
coverage: xdebug
35+
ini-file: development
3536
- run: composer install
3637
- run: vendor/bin/phpunit --coverage-text
3738
if: ${{ matrix.php >= 7.3 }}
@@ -57,7 +58,7 @@ jobs:
5758
continue-on-error: true
5859
steps:
5960
- uses: actions/checkout@v3
60-
- run: cp `which composer` composer.phar && ./composer.phar self-update --2.2 # downgrade Composer for HHVM
61+
- run: cp "$(which composer)" composer.phar && ./composer.phar self-update --2.2 # downgrade Composer for HHVM
6162
- name: Run hhvm composer.phar install
6263
uses: docker://hhvm/hhvm:3.30-lts-latest
6364
with:

composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
"react/stream": "^1.2"
3636
},
3737
"require-dev": {
38-
"phpunit/phpunit": "^9.3 || ^5.7 || ^4.8.35",
38+
"phpunit/phpunit": "^9.5 || ^5.7 || ^4.8.35",
3939
"react/async": "^4 || ^3 || ^2",
4040
"react/promise-stream": "^1.4"
4141
},

phpunit.xml.dist

+11-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22

3-
<!-- PHPUnit configuration file with new format for PHPUnit 9.3+ -->
4-
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5-
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd"
3+
<!-- PHPUnit configuration file with new format for PHPUnit 9.5+ -->
4+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5+
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.5/phpunit.xsd"
66
bootstrap="vendor/autoload.php"
77
cacheResult="false"
88
colors="true"
@@ -17,4 +17,12 @@
1717
<directory>./src/</directory>
1818
</include>
1919
</coverage>
20+
<php>
21+
<ini name="error_reporting" value="-1" />
22+
<!-- Evaluate assertions, requires running with "php -d zend.assertions=1 vendor/bin/phpunit" -->
23+
<!-- <ini name="zend.assertions=1" value="1" /> -->
24+
<ini name="assert.active" value="1" />
25+
<ini name="assert.exception" value="1" />
26+
<ini name="assert.bail" value="0" />
27+
</php>
2028
</phpunit>

phpunit.xml.legacy

+8
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,12 @@
1515
<directory>./src/</directory>
1616
</whitelist>
1717
</filter>
18+
<php>
19+
<ini name="error_reporting" value="-1" />
20+
<!-- Evaluate assertions, requires running with "php -d zend.assertions=1 vendor/bin/phpunit" -->
21+
<!-- <ini name="zend.assertions=1" value="1" /> -->
22+
<ini name="assert.active" value="1" />
23+
<ini name="assert.exception" value="1" />
24+
<ini name="assert.bail" value="0" />
25+
</php>
1826
</phpunit>

tests/IntegrationTest.php

+18
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
namespace React\Tests\Socket;
44

55
use React\Dns\Resolver\Factory as ResolverFactory;
6+
use React\EventLoop\Loop;
7+
use React\Socket\ConnectionInterface;
68
use React\Socket\Connector;
79
use React\Socket\DnsConnector;
810
use React\Socket\SecureConnector;
@@ -19,13 +21,15 @@ public function gettingStuffFromGoogleShouldWork()
1921
$connector = new Connector(array());
2022

2123
$conn = \React\Async\await($connector->connect('google.com:80'));
24+
assert($conn instanceof ConnectionInterface);
2225

2326
$this->assertContainsString(':80', $conn->getRemoteAddress());
2427
$this->assertNotEquals('google.com:80', $conn->getRemoteAddress());
2528

2629
$conn->write("GET / HTTP/1.0\r\n\r\n");
2730

2831
$response = $this->buffer($conn, self::TIMEOUT);
32+
assert(!$conn->isReadable());
2933

3034
$this->assertMatchesRegExp('#^HTTP/1\.0#', $response);
3135
}
@@ -40,10 +44,12 @@ public function gettingEncryptedStuffFromGoogleShouldWork()
4044
$secureConnector = new Connector(array());
4145

4246
$conn = \React\Async\await($secureConnector->connect('tls://google.com:443'));
47+
assert($conn instanceof ConnectionInterface);
4348

4449
$conn->write("GET / HTTP/1.0\r\n\r\n");
4550

4651
$response = $this->buffer($conn, self::TIMEOUT);
52+
assert(!$conn->isReadable());
4753

4854
$this->assertMatchesRegExp('#^HTTP/1\.0#', $response);
4955
}
@@ -66,10 +72,12 @@ public function gettingEncryptedStuffFromGoogleShouldWorkIfHostIsResolvedFirst()
6672
);
6773

6874
$conn = \React\Async\await($connector->connect('google.com:443'));
75+
assert($conn instanceof ConnectionInterface);
6976

7077
$conn->write("GET / HTTP/1.0\r\n\r\n");
7178

7279
$response = $this->buffer($conn, self::TIMEOUT);
80+
assert(!$conn->isReadable());
7381

7482
$this->assertMatchesRegExp('#^HTTP/1\.0#', $response);
7583
}
@@ -80,13 +88,15 @@ public function gettingPlaintextStuffFromEncryptedGoogleShouldNotWork()
8088
$connector = new Connector(array());
8189

8290
$conn = \React\Async\await($connector->connect('google.com:443'));
91+
assert($conn instanceof ConnectionInterface);
8392

8493
$this->assertContainsString(':443', $conn->getRemoteAddress());
8594
$this->assertNotEquals('google.com:443', $conn->getRemoteAddress());
8695

8796
$conn->write("GET / HTTP/1.0\r\n\r\n");
8897

8998
$response = $this->buffer($conn, self::TIMEOUT);
99+
assert(!$conn->isReadable());
90100

91101
$this->assertDoesNotMatchRegExp('#^HTTP/1\.0#', $response);
92102
}
@@ -148,6 +158,13 @@ public function testWaitingForRejectedConnectionShouldNotCreateAnyGarbageReferen
148158
$this->markTestSkipped('Not supported on legacy Promise v1 API');
149159
}
150160

161+
// let loop tick for reactphp/async v4 to clean up any remaining stream resources
162+
// @link https://github.com/reactphp/async/pull/65 reported upstream // TODO remove me once merged
163+
if (function_exists('React\Async\async')) {
164+
\React\Async\await(\React\Promise\Timer\sleep(0));
165+
Loop::run();
166+
}
167+
151168
$connector = new Connector(array('timeout' => false));
152169

153170
gc_collect_cycles();
@@ -377,6 +394,7 @@ public function testSelfSignedResolvesIfVerificationIsDisabled()
377394
));
378395

379396
$conn = \React\Async\await(\React\Promise\Timer\timeout($connector->connect('tls://self-signed.badssl.com:443'), self::TIMEOUT));
397+
assert($conn instanceof ConnectionInterface);
380398
$conn->close();
381399

382400
// if we reach this, then everything is good

tests/TestCase.php

+9-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ protected function buffer(ReadableStreamInterface $stream, $timeout)
7575
return '';
7676
}
7777

78-
return \React\Async\await(\React\Promise\Timer\timeout(new Promise(
78+
$buffer = \React\Async\await(\React\Promise\Timer\timeout(new Promise(
7979
function ($resolve, $reject) use ($stream) {
8080
$buffer = '';
8181
$stream->on('data', function ($chunk) use (&$buffer) {
@@ -93,6 +93,14 @@ function () use ($stream) {
9393
throw new \RuntimeException();
9494
}
9595
), $timeout));
96+
97+
// let loop tick for reactphp/async v4 to clean up any remaining stream resources
98+
// @link https://github.com/reactphp/async/pull/65 reported upstream // TODO remove me once merged
99+
if (function_exists('React\Async\async')) {
100+
\React\Async\await(\React\Promise\Timer\sleep(0));
101+
}
102+
103+
return $buffer;
96104
}
97105

98106
public function setExpectedException($exception, $exceptionMessage = '', $exceptionCode = null)

0 commit comments

Comments
 (0)