Skip to content

Commit 03b5ede

Browse files
Merge pull request #41 from BedrockStreaming/feat/php-80
feat: allow for php version 8
2 parents f99d578 + db42b73 commit 03b5ede

File tree

8 files changed

+31
-98
lines changed

8 files changed

+31
-98
lines changed

.github/workflows/ci.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313

1414
strategy:
1515
matrix:
16-
php: [ '7.2', '7.3', '7.4' ]
16+
php: [ '7.3', '7.4', '8.0' ]
1717

1818
steps:
1919
- name: 'Init repository'

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
/vendor/
33
/composer.lock
44
/.php-cs-fixer.cache
5+
/.phpunit.result.cache

composer.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,15 @@
2020
}
2121
},
2222
"require": {
23-
"php": "^7.1",
23+
"php": "^7.3|^8.0",
2424
"psr/http-message": "^1.0"
2525
},
2626
"require-dev": {
27-
"phpunit/phpunit": "^7.3",
27+
"phpunit/phpunit": "^9.4.4",
2828
"amphp/amp": "^2.0",
2929
"guzzlehttp/guzzle": "^6.3",
3030
"m6web/php-cs-fixer-config": "^2.0",
31-
"ext-curl": "^7.1",
31+
"ext-curl": "^7.3|^8.0",
3232
"react/event-loop": "^1.0",
3333
"react/promise": "^2.7",
3434
"phpstan/phpstan": "^0.12",

phpunit.xml.dist

+20-24
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,28 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
32
<!-- https://phpunit.de/manual/current/en/appendixes.configuration.html -->
43
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5-
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/6.1/phpunit.xsd"
4+
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd"
65
backupGlobals="false"
76
colors="true"
87
bootstrap="vendor/autoload.php"
98
>
10-
<php>
11-
<!-- define your env variables for the test env here -->
12-
</php>
13-
14-
<listeners>
15-
<listener class="M6WebTest\Tornado\Adapter\Amp\LoopReset" />
16-
</listeners>
17-
18-
<testsuites>
19-
<testsuite name="Tornado Test Suite">
20-
<directory>tests</directory>
21-
</testsuite>
22-
<testsuite name="Tornado Examples">
23-
<directory>examples/tests</directory>
24-
</testsuite>
25-
</testsuites>
26-
27-
<filter>
28-
<whitelist>
29-
<directory>src</directory>
30-
</whitelist>
31-
</filter>
9+
<coverage>
10+
<include>
11+
<directory>src</directory>
12+
</include>
13+
</coverage>
14+
<php>
15+
<!-- define your env variables for the test env here -->
16+
</php>
17+
<listeners>
18+
<listener class="M6WebTest\Tornado\Adapter\Amp\LoopReset"/>
19+
</listeners>
20+
<testsuites>
21+
<testsuite name="Tornado Test Suite">
22+
<directory>tests</directory>
23+
</testsuite>
24+
<testsuite name="Tornado Examples">
25+
<directory>examples/tests</directory>
26+
</testsuite>
27+
</testsuites>
3228
</phpunit>

src/EventLoop.php

+2
Original file line numberDiff line numberDiff line change
@@ -69,13 +69,15 @@ public function deferred(): Deferred;
6969

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

7778
/**
7879
* Returns a promise that will be resolved with the input stream when it becomes writable.
80+
* ⚠️ Error handling (stream connection closed for example) might differ between implementations.
7981
*
8082
* @param resource $stream
8183
*/

tests/Adapter/Amp/EventLoopTest.php

-16
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,4 @@ public function testStreamShouldReadFromWritable(string $expectedSequence = ''):
1717
// Because Amp resolve promises in a slightly different order.
1818
parent::testStreamShouldReadFromWritable('W0R0W12345R12R34W6R56R');
1919
}
20-
21-
public function testStreamShouldNotBeWritableIfClosed(): void
22-
{
23-
assert_options(ASSERT_EXCEPTION, 1);
24-
$this->expectException(\Throwable::class);
25-
26-
parent::testStreamShouldNotBeWritableIfClosed();
27-
}
28-
29-
public function testStreamShouldNotBeReadableIfClosed(): void
30-
{
31-
assert_options(ASSERT_EXCEPTION, 1);
32-
$this->expectException(\Throwable::class);
33-
34-
parent::testStreamShouldNotBeReadableIfClosed();
35-
}
3620
}

tests/EventLoopTest/StreamsTest.php

-50
Original file line numberDiff line numberDiff line change
@@ -80,54 +80,4 @@ public function testStreamShouldBeWritableIfOpened(): void
8080
$stream = $eventLoop->wait($eventLoop->writable($streamIn));
8181
$this->assertSame($streamIn, $stream);
8282
}
83-
84-
public function testStreamShouldNotBeWritableIfClosed(): void
85-
{
86-
$eventLoop = $this->createEventLoop();
87-
[$streamIn, $streamOut] = $this->createStreamPair();
88-
89-
$waitSomeTicks = function () use ($eventLoop) {
90-
yield $eventLoop->idle();
91-
yield $eventLoop->idle();
92-
yield $eventLoop->idle();
93-
94-
return 'Aborted';
95-
};
96-
97-
// If stream is closed, the promise will never be resolved
98-
fclose($streamIn);
99-
$result = $eventLoop->wait(
100-
$eventLoop->promiseRace(
101-
$eventLoop->async($waitSomeTicks()),
102-
$eventLoop->writable($streamIn)
103-
)
104-
);
105-
106-
$this->assertSame('Aborted', $result);
107-
}
108-
109-
public function testStreamShouldNotBeReadableIfClosed(): void
110-
{
111-
$eventLoop = $this->createEventLoop();
112-
[$streamIn, $streamOut] = $this->createStreamPair();
113-
114-
$waitSomeTicks = function () use ($eventLoop) {
115-
yield $eventLoop->idle();
116-
yield $eventLoop->idle();
117-
yield $eventLoop->idle();
118-
119-
return 'Aborted';
120-
};
121-
122-
// If stream is closed, the promise will never be resolved
123-
fclose($streamOut);
124-
$result = $eventLoop->wait(
125-
$eventLoop->promiseRace(
126-
$eventLoop->async($waitSomeTicks()),
127-
$eventLoop->readable($streamOut)
128-
)
129-
);
130-
131-
$this->assertSame('Aborted', $result);
132-
}
13383
}

tests/HttpClientTest.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public function testGetValidUrl(EventLoop $eventLoop): void
4040
$response = $eventLoop->wait($httpClient->sendRequest($request));
4141

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

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

7777
$this->assertSame(500, $response->getStatusCode());
78-
$this->assertContains('Error', (string) $response->getBody());
78+
$this->assertStringContainsString('Error', (string) $response->getBody());
7979
}
8080

8181
/**
@@ -112,11 +112,11 @@ public function testSynchronousRequests(EventLoop $eventLoop): void
112112

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

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

122122
/**

0 commit comments

Comments
 (0)