Skip to content

Commit 4a443f1

Browse files
authored
Merge pull request #17 from SimonFrings/test_suite
Update tests suite to PHPUnit 9.6 and improve documentation
2 parents 456e37a + 724bff4 commit 4a443f1

File tree

10 files changed

+106
-57
lines changed

10 files changed

+106
-57
lines changed

.gitattributes

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

.github/workflows/ci.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ on:
77
jobs:
88
PHPUnit:
99
name: PHPUnit (PHP ${{ matrix.php }})
10-
runs-on: ubuntu-20.04
10+
runs-on: ubuntu-22.04
1111
strategy:
1212
matrix:
1313
php:
@@ -20,10 +20,13 @@ jobs:
2020
- 5.4
2121
- 5.3
2222
steps:
23-
- uses: actions/checkout@v2
23+
- uses: actions/checkout@v4
2424
- uses: shivammathur/setup-php@v2
2525
with:
2626
php-version: ${{ matrix.php }}
2727
coverage: xdebug
2828
- run: composer install
2929
- run: vendor/bin/phpunit --coverage-text
30+
if: ${{ matrix.php >= 7.3 }}
31+
- run: vendor/bin/phpunit --coverage-text -c phpunit.xml.legacy
32+
if: ${{ matrix.php < 7.3 }}

README.md

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# clue/sse-react
22

3-
[![CI status](https://github.com/clue/php-sse-react/workflows/CI/badge.svg)](https://github.com/clue/php-sse-react/actions)
3+
[![CI status](https://github.com/clue/php-sse-react/actions/workflows/ci.yml/badge.svg)](https://github.com/clue/php-sse-react/actions)
44
[![installs on Packagist](https://img.shields.io/packagist/dt/clue/sse-react?color=blue&label=installs%20on%20Packagist)](https://packagist.org/packages/clue/sse-react)
55

66
Streaming, async HTML5 Server-Sent Events server (aka. SSE or EventSource), built on top of [React PHP](http://reactphp.org/).
@@ -13,7 +13,11 @@ See the [examples](examples).
1313

1414
## Install
1515

16-
The recommended way to install this library is [through composer](http://getcomposer.org). [New to composer?](http://getcomposer.org/doc/00-intro.md)
16+
The recommended way to install this library is [through Composer](https://getcomposer.org/).
17+
[New to Composer?](https://getcomposer.org/doc/00-intro.md)
18+
19+
Once released, this project will follow [SemVer](https://semver.org/).
20+
At the moment, this will install the latest development version:
1721

1822
```JSON
1923
{
@@ -23,21 +27,25 @@ The recommended way to install this library is [through composer](http://getcomp
2327
}
2428
```
2529

30+
This project aims to run on any platform and thus does not require any PHP
31+
extensions and supports running on legacy PHP 5.3 through PHP 7.3.
32+
It's *highly recommended to use the latest supported PHP version* for this project.
33+
2634
## Tests
2735

2836
To run the test suite, you first need to clone this repo and then install all
29-
dependencies [through Composer](http://getcomposer.org):
37+
dependencies [through Composer](http://getcomposer.org/):
3038

3139
```bash
32-
$ composer install
40+
composer install
3341
```
3442

3543
To run the test suite, go to the project root and run:
3644

3745
```bash
38-
$ php vendor/bin/phpunit
46+
php vendor/bin/phpunit
3947
```
4048

4149
## License
4250

43-
MIT
51+
MIT, see [LICENSE file](LICENSE).

composer.json

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,6 @@
1010
"email": "christian@lueck.tv"
1111
}
1212
],
13-
"autoload": {
14-
"psr-4": { "Clue\\React\\Sse\\": "src/" }
15-
},
1613
"require": {
1714
"php": ">=5.3",
1815
"react/event-loop": "^1.0",
@@ -21,6 +18,16 @@
2118
},
2219
"require-dev": {
2320
"clue/redis-react": "^2.4",
24-
"phpunit/phpunit": "^5.0 || ^4.8"
21+
"phpunit/phpunit": "^9.6 || ^7.5 || ^4.8.36"
22+
},
23+
"autoload": {
24+
"psr-4": {
25+
"Clue\\React\\Sse\\": "src/"
26+
}
27+
},
28+
"autoload-dev": {
29+
"psr-4": {
30+
"Clue\\React\\Tests\\Sse\\": "tests/"
31+
}
2532
}
2633
}

phpunit.xml.dist

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

3-
<phpunit bootstrap="tests/bootstrap.php"
3+
<!-- PHPUnit configuration file with new format for PHPUnit 9.6+ -->
4+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5+
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.6/phpunit.xsd"
6+
bootstrap="vendor/autoload.php"
7+
cacheResult="false"
48
colors="true"
5-
convertErrorsToExceptions="true"
6-
convertNoticesToExceptions="true"
7-
convertWarningsToExceptions="true"
8-
>
9+
convertDeprecationsToExceptions="true">
910
<testsuites>
1011
<testsuite name="SSE Test Suite">
1112
<directory>./tests/</directory>
1213
</testsuite>
1314
</testsuites>
14-
<filter>
15-
<whitelist>
15+
<coverage>
16+
<include>
1617
<directory>./src/</directory>
17-
</whitelist>
18-
</filter>
19-
</phpunit>
18+
</include>
19+
</coverage>
20+
<php>
21+
<ini name="error_reporting" value="-1" />
22+
</php>
23+
</phpunit>

phpunit.xml.legacy

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
<!-- PHPUnit configuration file with old format for legacy PHPUnit -->
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="SSE Test Suite">
10+
<directory>./tests/</directory>
11+
</testsuite>
12+
</testsuites>
13+
<filter>
14+
<whitelist>
15+
<directory>./src/</directory>
16+
</whitelist>
17+
</filter>
18+
<php>
19+
<ini name="error_reporting" value="-1" />
20+
</php>
21+
</phpunit>

tests/BufferedChannelTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
namespace Clue\React\Tests\Sse;
4+
35
use Clue\React\Sse\BufferedChannel;
46

57
class BufferedChannelTest extends TestCase

tests/EncoderTest.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
11
<?php
22

3+
namespace Clue\React\Tests\Sse;
4+
35
use Clue\React\Sse\Encoder;
46

57
class EncoderTest extends TestCase
68
{
79
private $encoder;
810

9-
public function setUp()
11+
/**
12+
* @before
13+
*/
14+
public function setUpEncoder()
1015
{
1116
$this->encoder = new Encoder();
1217
}

tests/TestCase.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
namespace Clue\React\Tests\Sse;
4+
5+
use PHPUnit\Framework\TestCase as BaseTestCase;
6+
7+
require __DIR__ . '/../vendor/autoload.php';
8+
9+
class TestCase extends BaseTestCase
10+
{
11+
protected function expectCallableOnce()
12+
{
13+
$mock = $this->createCallableMock();
14+
15+
$mock
16+
->expects($this->once())
17+
->method('__invoke');
18+
19+
return $mock;
20+
}
21+
22+
protected function createCallableMock()
23+
{
24+
if (method_exists('PHPUnit\Framework\MockObject\MockBuilder', 'addMethods')) {
25+
// PHPUnit 9+
26+
return $this->getMockBuilder('stdClass')->addMethods(array('__invoke'))->getMock();
27+
} else {
28+
// legacy PHPUnit 4 - PHPUnit 8
29+
return $this->getMockBuilder('stdClass')->setMethods(array('__invoke'))->getMock();
30+
}
31+
}
32+
}

tests/bootstrap.php

Lines changed: 0 additions & 34 deletions
This file was deleted.

0 commit comments

Comments
 (0)