Skip to content

Commit a5f48fd

Browse files
authored
Merge pull request #393 from SimonFrings/tests
Update PHPUnit configuration schema for PHPUnit 9.3 and replace deprecated at() Mocks
2 parents 913050f + c1cbd3b commit a5f48fd

File tree

9 files changed

+192
-148
lines changed

9 files changed

+192
-148
lines changed

.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@
33
/.travis.yml export-ignore
44
/examples export-ignore
55
/phpunit.xml.dist export-ignore
6+
/phpunit.xml.legacy export-ignore
67
/tests export-ignore

.travis.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ language: php
33
# lock distro so new future defaults will not break the build
44
dist: trusty
55

6-
matrix:
6+
jobs:
77
include:
88
- php: 5.3
99
dist: precise
@@ -23,9 +23,10 @@ matrix:
2323
- php: hhvm-3.18
2424

2525
install:
26-
- composer install --no-interaction
26+
- composer install
2727
- if [ "$DEPENDENCIES" = "lowest" ]; then composer update --prefer-lowest -n; fi
2828

2929
script:
30-
- ./vendor/bin/phpunit --coverage-text
30+
- if [[ "$TRAVIS_PHP_VERSION" > "7.2" ]]; then vendor/bin/phpunit --coverage-text; fi
31+
- if [[ "$TRAVIS_PHP_VERSION" < "7.3" ]]; then vendor/bin/phpunit --coverage-text -c phpunit.xml.legacy; fi
3132
- if [ "$DEPENDENCIES" = "lowest" ]; then php -n tests/benchmark-middleware-runner.php; fi

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
"clue/http-proxy-react": "^1.3",
4242
"clue/reactphp-ssh-proxy": "^1.0",
4343
"clue/socks-react": "^1.0",
44-
"phpunit/phpunit": "^9.0 || ^5.7 || ^4.8.35"
44+
"phpunit/phpunit": "^9.3 || ^5.7 || ^4.8.35"
4545
},
4646
"autoload": {
4747
"psr-4": { "React\\Http\\": "src" }

phpunit.xml.dist

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22

3-
<phpunit bootstrap="vendor/autoload.php" colors="true">
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"
6+
bootstrap="vendor/autoload.php"
7+
colors="true"
8+
cacheResult="false">
49
<testsuites>
510
<testsuite name="React Test Suite">
611
<directory>./tests/</directory>
712
</testsuite>
813
</testsuites>
9-
10-
<filter>
11-
<whitelist>
14+
<coverage>
15+
<include>
1216
<directory>./src/</directory>
13-
</whitelist>
14-
</filter>
17+
</include>
18+
</coverage>
1519
</phpunit>

phpunit.xml.legacy

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
<!-- PHPUnit configuration file with old format for PHPUnit 9.2 or older -->
4+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5+
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/4.8/phpunit.xsd"
6+
bootstrap="vendor/autoload.php"
7+
colors="true">
8+
<testsuites>
9+
<testsuite name="React Test Suite">
10+
<directory>./tests/</directory>
11+
</testsuite>
12+
</testsuites>
13+
<filter>
14+
<whitelist>
15+
<directory>./src/</directory>
16+
</whitelist>
17+
</filter>
18+
</phpunit>

tests/Client/RequestTest.php

Lines changed: 37 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -36,46 +36,21 @@ public function requestShouldBindToStreamEventsAndUseconnector()
3636

3737
$this->successfulConnectionMock();
3838

39-
$this->stream
40-
->expects($this->at(0))
41-
->method('on')
42-
->with('drain', $this->identicalTo(array($request, 'handleDrain')));
43-
$this->stream
44-
->expects($this->at(1))
45-
->method('on')
46-
->with('data', $this->identicalTo(array($request, 'handleData')));
47-
$this->stream
48-
->expects($this->at(2))
49-
->method('on')
50-
->with('end', $this->identicalTo(array($request, 'handleEnd')));
51-
$this->stream
52-
->expects($this->at(3))
53-
->method('on')
54-
->with('error', $this->identicalTo(array($request, 'handleError')));
55-
$this->stream
56-
->expects($this->at(4))
57-
->method('on')
58-
->with('close', $this->identicalTo(array($request, 'handleClose')));
59-
$this->stream
60-
->expects($this->at(6))
61-
->method('removeListener')
62-
->with('drain', $this->identicalTo(array($request, 'handleDrain')));
63-
$this->stream
64-
->expects($this->at(7))
65-
->method('removeListener')
66-
->with('data', $this->identicalTo(array($request, 'handleData')));
67-
$this->stream
68-
->expects($this->at(8))
69-
->method('removeListener')
70-
->with('end', $this->identicalTo(array($request, 'handleEnd')));
71-
$this->stream
72-
->expects($this->at(9))
73-
->method('removeListener')
74-
->with('error', $this->identicalTo(array($request, 'handleError')));
75-
$this->stream
76-
->expects($this->at(10))
77-
->method('removeListener')
78-
->with('close', $this->identicalTo(array($request, 'handleClose')));
39+
$this->stream->expects($this->exactly(6))->method('on')->withConsecutive(
40+
array('drain', $this->identicalTo(array($request, 'handleDrain'))),
41+
array('data', $this->identicalTo(array($request, 'handleData'))),
42+
array('end', $this->identicalTo(array($request, 'handleEnd'))),
43+
array('error', $this->identicalTo(array($request, 'handleError'))),
44+
array('close', $this->identicalTo(array($request, 'handleClose')))
45+
);
46+
47+
$this->stream->expects($this->exactly(5))->method('removeListener')->withConsecutive(
48+
array('drain', $this->identicalTo(array($request, 'handleDrain'))),
49+
array('data', $this->identicalTo(array($request, 'handleData'))),
50+
array('end', $this->identicalTo(array($request, 'handleEnd'))),
51+
array('error', $this->identicalTo(array($request, 'handleError'))),
52+
array('close', $this->identicalTo(array($request, 'handleClose')))
53+
);
7954

8055
$request->on('end', $this->expectCallableNever());
8156

@@ -223,18 +198,11 @@ public function writeWithAPostRequestShouldSendToTheStream()
223198

224199
$this->successfulConnectionMock();
225200

226-
$this->stream
227-
->expects($this->at(5))
228-
->method('write')
229-
->with($this->matchesRegularExpression("#^POST / HTTP/1\.0\r\nHost: www.example.com\r\nUser-Agent:.*\r\n\r\nsome$#"));
230-
$this->stream
231-
->expects($this->at(6))
232-
->method('write')
233-
->with($this->identicalTo("post"));
234-
$this->stream
235-
->expects($this->at(7))
236-
->method('write')
237-
->with($this->identicalTo("data"));
201+
$this->stream->expects($this->exactly(3))->method('write')->withConsecutive(
202+
array($this->matchesRegularExpression("#^POST / HTTP/1\.0\r\nHost: www.example.com\r\nUser-Agent:.*\r\n\r\nsome$#")),
203+
array($this->identicalTo("post")),
204+
array($this->identicalTo("data"))
205+
);
238206

239207
$request->write("some");
240208
$request->write("post");
@@ -253,15 +221,12 @@ public function writeWithAPostRequestShouldSendBodyAfterHeadersAndEmitDrainEvent
253221

254222
$resolveConnection = $this->successfulAsyncConnectionMock();
255223

256-
$this->stream
257-
->expects($this->at(5))
258-
->method('write')
259-
->with($this->matchesRegularExpression("#^POST / HTTP/1\.0\r\nHost: www.example.com\r\nUser-Agent:.*\r\n\r\nsomepost$#"))
260-
->willReturn(true);
261-
$this->stream
262-
->expects($this->at(6))
263-
->method('write')
264-
->with($this->identicalTo("data"));
224+
$this->stream->expects($this->exactly(2))->method('write')->withConsecutive(
225+
array($this->matchesRegularExpression("#^POST / HTTP/1\.0\r\nHost: www.example.com\r\nUser-Agent:.*\r\n\r\nsomepost$#")),
226+
array($this->identicalTo("data"))
227+
)->willReturn(
228+
true
229+
);
265230

266231
$this->assertFalse($request->write("some"));
267232
$this->assertFalse($request->write("post"));
@@ -292,15 +257,12 @@ public function writeWithAPostRequestShouldForwardDrainEventIfFirstChunkExceedsB
292257

293258
$resolveConnection = $this->successfulAsyncConnectionMock();
294259

295-
$this->stream
296-
->expects($this->at(0))
297-
->method('write')
298-
->with($this->matchesRegularExpression("#^POST / HTTP/1\.0\r\nHost: www.example.com\r\nUser-Agent:.*\r\n\r\nsomepost$#"))
299-
->willReturn(false);
300-
$this->stream
301-
->expects($this->at(1))
302-
->method('write')
303-
->with($this->identicalTo("data"));
260+
$this->stream->expects($this->exactly(2))->method('write')->withConsecutive(
261+
array($this->matchesRegularExpression("#^POST / HTTP/1\.0\r\nHost: www.example.com\r\nUser-Agent:.*\r\n\r\nsomepost$#")),
262+
array($this->identicalTo("data"))
263+
)->willReturn(
264+
false
265+
);
304266

305267
$this->assertFalse($request->write("some"));
306268
$this->assertFalse($request->write("post"));
@@ -327,18 +289,11 @@ public function pipeShouldPipeDataIntoTheRequestBody()
327289

328290
$this->successfulConnectionMock();
329291

330-
$this->stream
331-
->expects($this->at(5))
332-
->method('write')
333-
->with($this->matchesRegularExpression("#^POST / HTTP/1\.0\r\nHost: www.example.com\r\nUser-Agent:.*\r\n\r\nsome$#"));
334-
$this->stream
335-
->expects($this->at(6))
336-
->method('write')
337-
->with($this->identicalTo("post"));
338-
$this->stream
339-
->expects($this->at(7))
340-
->method('write')
341-
->with($this->identicalTo("data"));
292+
$this->stream->expects($this->exactly(3))->method('write')->withConsecutive(
293+
array($this->matchesRegularExpression("#^POST / HTTP/1\.0\r\nHost: www.example.com\r\nUser-Agent:.*\r\n\r\nsome$#")),
294+
array($this->identicalTo("post")),
295+
array($this->identicalTo("data"))
296+
);
342297

343298
$loop = $this
344299
->getMockBuilder('React\EventLoop\LoopInterface')

0 commit comments

Comments
 (0)