Skip to content

Commit

Permalink
Update test environment to report failed assertions
Browse files Browse the repository at this point in the history
  • Loading branch information
clue committed Oct 26, 2022
1 parent 1bc5337 commit 84e1373
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 6 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ jobs:
with:
php-version: ${{ matrix.php }}
coverage: xdebug
ini-file: development
- run: composer install
- run: vendor/bin/phpunit --coverage-text
if: ${{ matrix.php >= 7.3 }}
Expand All @@ -57,7 +58,7 @@ jobs:
continue-on-error: true
steps:
- uses: actions/checkout@v3
- run: cp `which composer` composer.phar && ./composer.phar self-update --2.2 # downgrade Composer for HHVM
- run: cp "$(which composer)" composer.phar && ./composer.phar self-update --2.2 # downgrade Composer for HHVM
- name: Run hhvm composer.phar install
uses: docker://hhvm/hhvm:3.30-lts-latest
with:
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"react/stream": "^1.2"
},
"require-dev": {
"phpunit/phpunit": "^9.3 || ^5.7 || ^4.8.35",
"phpunit/phpunit": "^9.5 || ^5.7 || ^4.8.35",
"react/async": "^4 || ^3 || ^2",
"react/promise-stream": "^1.4"
},
Expand Down
14 changes: 11 additions & 3 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>

<!-- PHPUnit configuration file with new format for PHPUnit 9.3+ -->
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd"
<!-- PHPUnit configuration file with new format for PHPUnit 9.5+ -->
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.5/phpunit.xsd"
bootstrap="vendor/autoload.php"
cacheResult="false"
colors="true"
Expand All @@ -17,4 +17,12 @@
<directory>./src/</directory>
</include>
</coverage>
<php>
<ini name="error_reporting" value="-1" />
<!-- Evaluate assertions, requires running with "php -d zend.assertions=1 vendor/bin/phpunit" -->
<!-- <ini name="zend.assertions=1" value="1" /> -->
<ini name="assert.active" value="1" />
<ini name="assert.exception" value="1" />
<ini name="assert.bail" value="0" />
</php>
</phpunit>
8 changes: 8 additions & 0 deletions phpunit.xml.legacy
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,12 @@
<directory>./src/</directory>
</whitelist>
</filter>
<php>
<ini name="error_reporting" value="-1" />
<!-- Evaluate assertions, requires running with "php -d zend.assertions=1 vendor/bin/phpunit" -->
<!-- <ini name="zend.assertions=1" value="1" /> -->
<ini name="assert.active" value="1" />
<ini name="assert.exception" value="1" />
<ini name="assert.bail" value="0" />
</php>
</phpunit>
6 changes: 6 additions & 0 deletions tests/IntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace React\Tests\Socket;

use React\Dns\Resolver\Factory as ResolverFactory;
use React\Socket\ConnectionInterface;
use React\Socket\Connector;
use React\Socket\DnsConnector;
use React\Socket\SecureConnector;
Expand All @@ -19,6 +20,7 @@ public function gettingStuffFromGoogleShouldWork()
$connector = new Connector(array());

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

$this->assertContainsString(':80', $conn->getRemoteAddress());
$this->assertNotEquals('google.com:80', $conn->getRemoteAddress());
Expand All @@ -40,6 +42,7 @@ public function gettingEncryptedStuffFromGoogleShouldWork()
$secureConnector = new Connector(array());

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

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

Expand All @@ -66,6 +69,7 @@ public function gettingEncryptedStuffFromGoogleShouldWorkIfHostIsResolvedFirst()
);

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

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

Expand All @@ -80,6 +84,7 @@ public function gettingPlaintextStuffFromEncryptedGoogleShouldNotWork()
$connector = new Connector(array());

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

$this->assertContainsString(':443', $conn->getRemoteAddress());
$this->assertNotEquals('google.com:443', $conn->getRemoteAddress());
Expand Down Expand Up @@ -377,6 +382,7 @@ public function testSelfSignedResolvesIfVerificationIsDisabled()
));

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

// if we reach this, then everything is good
Expand Down
10 changes: 9 additions & 1 deletion tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ protected function buffer(ReadableStreamInterface $stream, $timeout)
return '';
}

return \React\Async\await(\React\Promise\Timer\timeout(new Promise(
$buffer = \React\Async\await(\React\Promise\Timer\timeout(new Promise(
function ($resolve, $reject) use ($stream) {
$buffer = '';
$stream->on('data', function ($chunk) use (&$buffer) {
Expand All @@ -93,6 +93,14 @@ function () use ($stream) {
throw new \RuntimeException();
}
), $timeout));

// let loop tick for reactphp/async v4 to clean up any remaining stream resources
// @link https://github.com/reactphp/async/pull/65 reported upstream // TODO remove me once merged
if (function_exists('React\Async\async')) {
\React\Async\await(\React\Promise\Timer\sleep(0));
}

return $buffer;
}

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

0 comments on commit 84e1373

Please sign in to comment.