Skip to content

Commit

Permalink
Merge pull request #41 from BedrockStreaming/feat/php-80
Browse files Browse the repository at this point in the history
feat: allow for php version 8
  • Loading branch information
valentin-claras authored Oct 15, 2021
2 parents f99d578 + db42b73 commit 03b5ede
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 98 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:

strategy:
matrix:
php: [ '7.2', '7.3', '7.4' ]
php: [ '7.3', '7.4', '8.0' ]

steps:
- name: 'Init repository'
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
/vendor/
/composer.lock
/.php-cs-fixer.cache
/.phpunit.result.cache
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@
}
},
"require": {
"php": "^7.1",
"php": "^7.3|^8.0",
"psr/http-message": "^1.0"
},
"require-dev": {
"phpunit/phpunit": "^7.3",
"phpunit/phpunit": "^9.4.4",
"amphp/amp": "^2.0",
"guzzlehttp/guzzle": "^6.3",
"m6web/php-cs-fixer-config": "^2.0",
"ext-curl": "^7.1",
"ext-curl": "^7.3|^8.0",
"react/event-loop": "^1.0",
"react/promise": "^2.7",
"phpstan/phpstan": "^0.12",
Expand Down
44 changes: 20 additions & 24 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,32 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>

<!-- https://phpunit.de/manual/current/en/appendixes.configuration.html -->
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/6.1/phpunit.xsd"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd"
backupGlobals="false"
colors="true"
bootstrap="vendor/autoload.php"
>
<php>
<!-- define your env variables for the test env here -->
</php>

<listeners>
<listener class="M6WebTest\Tornado\Adapter\Amp\LoopReset" />
</listeners>

<testsuites>
<testsuite name="Tornado Test Suite">
<directory>tests</directory>
</testsuite>
<testsuite name="Tornado Examples">
<directory>examples/tests</directory>
</testsuite>
</testsuites>

<filter>
<whitelist>
<directory>src</directory>
</whitelist>
</filter>
<coverage>
<include>
<directory>src</directory>
</include>
</coverage>
<php>
<!-- define your env variables for the test env here -->
</php>
<listeners>
<listener class="M6WebTest\Tornado\Adapter\Amp\LoopReset"/>
</listeners>
<testsuites>
<testsuite name="Tornado Test Suite">
<directory>tests</directory>
</testsuite>
<testsuite name="Tornado Examples">
<directory>examples/tests</directory>
</testsuite>
</testsuites>
</phpunit>
2 changes: 2 additions & 0 deletions src/EventLoop.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,15 @@ public function deferred(): Deferred;

/**
* Returns a promise that will be resolved with the input stream when it becomes readable.
* ⚠️ Error handling (stream connection closed for example) might differ between implementations.
*
* @param resource $stream
*/
public function readable($stream): Promise;

/**
* Returns a promise that will be resolved with the input stream when it becomes writable.
* ⚠️ Error handling (stream connection closed for example) might differ between implementations.
*
* @param resource $stream
*/
Expand Down
16 changes: 0 additions & 16 deletions tests/Adapter/Amp/EventLoopTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,4 @@ public function testStreamShouldReadFromWritable(string $expectedSequence = ''):
// Because Amp resolve promises in a slightly different order.
parent::testStreamShouldReadFromWritable('W0R0W12345R12R34W6R56R');
}

public function testStreamShouldNotBeWritableIfClosed(): void
{
assert_options(ASSERT_EXCEPTION, 1);
$this->expectException(\Throwable::class);

parent::testStreamShouldNotBeWritableIfClosed();
}

public function testStreamShouldNotBeReadableIfClosed(): void
{
assert_options(ASSERT_EXCEPTION, 1);
$this->expectException(\Throwable::class);

parent::testStreamShouldNotBeReadableIfClosed();
}
}
50 changes: 0 additions & 50 deletions tests/EventLoopTest/StreamsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,54 +80,4 @@ public function testStreamShouldBeWritableIfOpened(): void
$stream = $eventLoop->wait($eventLoop->writable($streamIn));
$this->assertSame($streamIn, $stream);
}

public function testStreamShouldNotBeWritableIfClosed(): void
{
$eventLoop = $this->createEventLoop();
[$streamIn, $streamOut] = $this->createStreamPair();

$waitSomeTicks = function () use ($eventLoop) {
yield $eventLoop->idle();
yield $eventLoop->idle();
yield $eventLoop->idle();

return 'Aborted';
};

// If stream is closed, the promise will never be resolved
fclose($streamIn);
$result = $eventLoop->wait(
$eventLoop->promiseRace(
$eventLoop->async($waitSomeTicks()),
$eventLoop->writable($streamIn)
)
);

$this->assertSame('Aborted', $result);
}

public function testStreamShouldNotBeReadableIfClosed(): void
{
$eventLoop = $this->createEventLoop();
[$streamIn, $streamOut] = $this->createStreamPair();

$waitSomeTicks = function () use ($eventLoop) {
yield $eventLoop->idle();
yield $eventLoop->idle();
yield $eventLoop->idle();

return 'Aborted';
};

// If stream is closed, the promise will never be resolved
fclose($streamOut);
$result = $eventLoop->wait(
$eventLoop->promiseRace(
$eventLoop->async($waitSomeTicks()),
$eventLoop->readable($streamOut)
)
);

$this->assertSame('Aborted', $result);
}
}
8 changes: 4 additions & 4 deletions tests/HttpClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public function testGetValidUrl(EventLoop $eventLoop): void
$response = $eventLoop->wait($httpClient->sendRequest($request));

$this->assertSame(200, $response->getStatusCode());
$this->assertContains('This is a test', (string) $response->getBody());
$this->assertStringContainsString('This is a test', (string) $response->getBody());
}

/**
Expand Down Expand Up @@ -75,7 +75,7 @@ public function testGetServerErrorUrl(EventLoop $eventLoop): void
$response = $eventLoop->wait($httpClient->sendRequest($request));

$this->assertSame(500, $response->getStatusCode());
$this->assertContains('Error', (string) $response->getBody());
$this->assertStringContainsString('Error', (string) $response->getBody());
}

/**
Expand Down Expand Up @@ -112,11 +112,11 @@ public function testSynchronousRequests(EventLoop $eventLoop): void

$response = $eventLoop->wait($httpClient->sendRequest($request));
$this->assertSame(200, $response->getStatusCode());
$this->assertContains('Example Domain', (string) $response->getBody());
$this->assertStringContainsString('Example Domain', (string) $response->getBody());

$response = $eventLoop->wait($httpClient->sendRequest($request));
$this->assertSame(200, $response->getStatusCode());
$this->assertContains('Example Domain', (string) $response->getBody());
$this->assertStringContainsString('Example Domain', (string) $response->getBody());
}

/**
Expand Down

0 comments on commit 03b5ede

Please sign in to comment.