Skip to content

Commit

Permalink
Merge pull request #393 from SimonFrings/tests
Browse files Browse the repository at this point in the history
Update PHPUnit configuration schema for PHPUnit 9.3 and replace deprecated at() Mocks
  • Loading branch information
jsor authored Sep 4, 2020
2 parents 913050f + c1cbd3b commit a5f48fd
Show file tree
Hide file tree
Showing 9 changed files with 192 additions and 148 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
/.travis.yml export-ignore
/examples export-ignore
/phpunit.xml.dist export-ignore
/phpunit.xml.legacy export-ignore
/tests export-ignore
7 changes: 4 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ language: php
# lock distro so new future defaults will not break the build
dist: trusty

matrix:
jobs:
include:
- php: 5.3
dist: precise
Expand All @@ -23,9 +23,10 @@ matrix:
- php: hhvm-3.18

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

script:
- ./vendor/bin/phpunit --coverage-text
- if [[ "$TRAVIS_PHP_VERSION" > "7.2" ]]; then vendor/bin/phpunit --coverage-text; fi
- if [[ "$TRAVIS_PHP_VERSION" < "7.3" ]]; then vendor/bin/phpunit --coverage-text -c phpunit.xml.legacy; fi
- if [ "$DEPENDENCIES" = "lowest" ]; then php -n tests/benchmark-middleware-runner.php; fi
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"clue/http-proxy-react": "^1.3",
"clue/reactphp-ssh-proxy": "^1.0",
"clue/socks-react": "^1.0",
"phpunit/phpunit": "^9.0 || ^5.7 || ^4.8.35"
"phpunit/phpunit": "^9.3 || ^5.7 || ^4.8.35"
},
"autoload": {
"psr-4": { "React\\Http\\": "src" }
Expand Down
16 changes: 10 additions & 6 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>

<phpunit bootstrap="vendor/autoload.php" colors="true">
<!-- 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"
bootstrap="vendor/autoload.php"
colors="true"
cacheResult="false">
<testsuites>
<testsuite name="React Test Suite">
<directory>./tests/</directory>
</testsuite>
</testsuites>

<filter>
<whitelist>
<coverage>
<include>
<directory>./src/</directory>
</whitelist>
</filter>
</include>
</coverage>
</phpunit>
18 changes: 18 additions & 0 deletions phpunit.xml.legacy
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>

<!-- PHPUnit configuration file with old format for PHPUnit 9.2 or older -->
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/4.8/phpunit.xsd"
bootstrap="vendor/autoload.php"
colors="true">
<testsuites>
<testsuite name="React Test Suite">
<directory>./tests/</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>
<directory>./src/</directory>
</whitelist>
</filter>
</phpunit>
119 changes: 37 additions & 82 deletions tests/Client/RequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,46 +36,21 @@ public function requestShouldBindToStreamEventsAndUseconnector()

$this->successfulConnectionMock();

$this->stream
->expects($this->at(0))
->method('on')
->with('drain', $this->identicalTo(array($request, 'handleDrain')));
$this->stream
->expects($this->at(1))
->method('on')
->with('data', $this->identicalTo(array($request, 'handleData')));
$this->stream
->expects($this->at(2))
->method('on')
->with('end', $this->identicalTo(array($request, 'handleEnd')));
$this->stream
->expects($this->at(3))
->method('on')
->with('error', $this->identicalTo(array($request, 'handleError')));
$this->stream
->expects($this->at(4))
->method('on')
->with('close', $this->identicalTo(array($request, 'handleClose')));
$this->stream
->expects($this->at(6))
->method('removeListener')
->with('drain', $this->identicalTo(array($request, 'handleDrain')));
$this->stream
->expects($this->at(7))
->method('removeListener')
->with('data', $this->identicalTo(array($request, 'handleData')));
$this->stream
->expects($this->at(8))
->method('removeListener')
->with('end', $this->identicalTo(array($request, 'handleEnd')));
$this->stream
->expects($this->at(9))
->method('removeListener')
->with('error', $this->identicalTo(array($request, 'handleError')));
$this->stream
->expects($this->at(10))
->method('removeListener')
->with('close', $this->identicalTo(array($request, 'handleClose')));
$this->stream->expects($this->exactly(6))->method('on')->withConsecutive(
array('drain', $this->identicalTo(array($request, 'handleDrain'))),
array('data', $this->identicalTo(array($request, 'handleData'))),
array('end', $this->identicalTo(array($request, 'handleEnd'))),
array('error', $this->identicalTo(array($request, 'handleError'))),
array('close', $this->identicalTo(array($request, 'handleClose')))
);

$this->stream->expects($this->exactly(5))->method('removeListener')->withConsecutive(
array('drain', $this->identicalTo(array($request, 'handleDrain'))),
array('data', $this->identicalTo(array($request, 'handleData'))),
array('end', $this->identicalTo(array($request, 'handleEnd'))),
array('error', $this->identicalTo(array($request, 'handleError'))),
array('close', $this->identicalTo(array($request, 'handleClose')))
);

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

Expand Down Expand Up @@ -223,18 +198,11 @@ public function writeWithAPostRequestShouldSendToTheStream()

$this->successfulConnectionMock();

$this->stream
->expects($this->at(5))
->method('write')
->with($this->matchesRegularExpression("#^POST / HTTP/1\.0\r\nHost: www.example.com\r\nUser-Agent:.*\r\n\r\nsome$#"));
$this->stream
->expects($this->at(6))
->method('write')
->with($this->identicalTo("post"));
$this->stream
->expects($this->at(7))
->method('write')
->with($this->identicalTo("data"));
$this->stream->expects($this->exactly(3))->method('write')->withConsecutive(
array($this->matchesRegularExpression("#^POST / HTTP/1\.0\r\nHost: www.example.com\r\nUser-Agent:.*\r\n\r\nsome$#")),
array($this->identicalTo("post")),
array($this->identicalTo("data"))
);

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

$resolveConnection = $this->successfulAsyncConnectionMock();

$this->stream
->expects($this->at(5))
->method('write')
->with($this->matchesRegularExpression("#^POST / HTTP/1\.0\r\nHost: www.example.com\r\nUser-Agent:.*\r\n\r\nsomepost$#"))
->willReturn(true);
$this->stream
->expects($this->at(6))
->method('write')
->with($this->identicalTo("data"));
$this->stream->expects($this->exactly(2))->method('write')->withConsecutive(
array($this->matchesRegularExpression("#^POST / HTTP/1\.0\r\nHost: www.example.com\r\nUser-Agent:.*\r\n\r\nsomepost$#")),
array($this->identicalTo("data"))
)->willReturn(
true
);

$this->assertFalse($request->write("some"));
$this->assertFalse($request->write("post"));
Expand Down Expand Up @@ -292,15 +257,12 @@ public function writeWithAPostRequestShouldForwardDrainEventIfFirstChunkExceedsB

$resolveConnection = $this->successfulAsyncConnectionMock();

$this->stream
->expects($this->at(0))
->method('write')
->with($this->matchesRegularExpression("#^POST / HTTP/1\.0\r\nHost: www.example.com\r\nUser-Agent:.*\r\n\r\nsomepost$#"))
->willReturn(false);
$this->stream
->expects($this->at(1))
->method('write')
->with($this->identicalTo("data"));
$this->stream->expects($this->exactly(2))->method('write')->withConsecutive(
array($this->matchesRegularExpression("#^POST / HTTP/1\.0\r\nHost: www.example.com\r\nUser-Agent:.*\r\n\r\nsomepost$#")),
array($this->identicalTo("data"))
)->willReturn(
false
);

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

$this->successfulConnectionMock();

$this->stream
->expects($this->at(5))
->method('write')
->with($this->matchesRegularExpression("#^POST / HTTP/1\.0\r\nHost: www.example.com\r\nUser-Agent:.*\r\n\r\nsome$#"));
$this->stream
->expects($this->at(6))
->method('write')
->with($this->identicalTo("post"));
$this->stream
->expects($this->at(7))
->method('write')
->with($this->identicalTo("data"));
$this->stream->expects($this->exactly(3))->method('write')->withConsecutive(
array($this->matchesRegularExpression("#^POST / HTTP/1\.0\r\nHost: www.example.com\r\nUser-Agent:.*\r\n\r\nsome$#")),
array($this->identicalTo("post")),
array($this->identicalTo("data"))
);

$loop = $this
->getMockBuilder('React\EventLoop\LoopInterface')
Expand Down
Loading

0 comments on commit a5f48fd

Please sign in to comment.