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 4d44b5a
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 6 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/ci.yml
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
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
@@ -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
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>
18 changes: 18 additions & 0 deletions tests/IntegrationTest.php
Expand Up @@ -3,6 +3,8 @@
namespace React\Tests\Socket;

use React\Dns\Resolver\Factory as ResolverFactory;
use React\EventLoop\Loop;
use React\Socket\ConnectionInterface;
use React\Socket\Connector;
use React\Socket\DnsConnector;
use React\Socket\SecureConnector;
Expand All @@ -19,13 +21,15 @@ 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());

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

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

$this->assertMatchesRegExp('#^HTTP/1\.0#', $response);
}
Expand All @@ -40,10 +44,12 @@ 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");

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

$this->assertMatchesRegExp('#^HTTP/1\.0#', $response);
}
Expand All @@ -66,10 +72,12 @@ 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");

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

$this->assertMatchesRegExp('#^HTTP/1\.0#', $response);
}
Expand All @@ -80,13 +88,15 @@ 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());

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

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

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

// 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));
Loop::run();
}

$connector = new Connector(array('timeout' => false));

gc_collect_cycles();
Expand Down Expand Up @@ -377,6 +394,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
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 4d44b5a

Please sign in to comment.