Skip to content

Update tests suite to PHPUnit 9.6 and improve documentation #17

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
/.gitignore export-ignore
/examples/ export-ignore
/phpunit.xml.dist export-ignore
/phpunit.xml.legacy export-ignore
/tests/ export-ignore
7 changes: 5 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ on:
jobs:
PHPUnit:
name: PHPUnit (PHP ${{ matrix.php }})
runs-on: ubuntu-20.04
runs-on: ubuntu-22.04
strategy:
matrix:
php:
Expand All @@ -20,10 +20,13 @@ jobs:
- 5.4
- 5.3
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
coverage: xdebug
- run: composer install
- run: vendor/bin/phpunit --coverage-text
if: ${{ matrix.php >= 7.3 }}
- run: vendor/bin/phpunit --coverage-text -c phpunit.xml.legacy
if: ${{ matrix.php < 7.3 }}
20 changes: 14 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# clue/sse-react

[![CI status](https://github.com/clue/php-sse-react/workflows/CI/badge.svg)](https://github.com/clue/php-sse-react/actions)
[![CI status](https://github.com/clue/php-sse-react/actions/workflows/ci.yml/badge.svg)](https://github.com/clue/php-sse-react/actions)
[![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)

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

## Install

The recommended way to install this library is [through composer](http://getcomposer.org). [New to composer?](http://getcomposer.org/doc/00-intro.md)
The recommended way to install this library is [through Composer](https://getcomposer.org/).
[New to Composer?](https://getcomposer.org/doc/00-intro.md)

Once released, this project will follow [SemVer](https://semver.org/).
At the moment, this will install the latest development version:

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

This project aims to run on any platform and thus does not require any PHP
extensions and supports running on legacy PHP 5.3 through PHP 7.3.
It's *highly recommended to use the latest supported PHP version* for this project.

## Tests

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

```bash
$ composer install
composer install
```

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

```bash
$ php vendor/bin/phpunit
php vendor/bin/phpunit
```

## License

MIT
MIT, see [LICENSE file](LICENSE).
15 changes: 11 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@
"email": "christian@lueck.tv"
}
],
"autoload": {
"psr-4": { "Clue\\React\\Sse\\": "src/" }
},
"require": {
"php": ">=5.3",
"react/event-loop": "^1.0",
Expand All @@ -21,6 +18,16 @@
},
"require-dev": {
"clue/redis-react": "^2.4",
"phpunit/phpunit": "^5.0 || ^4.8"
"phpunit/phpunit": "^9.6 || ^7.5 || ^4.8.36"
},
"autoload": {
"psr-4": {
"Clue\\React\\Sse\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"Clue\\React\\Tests\\Sse\\": "tests/"
}
}
}
24 changes: 14 additions & 10 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>

<phpunit bootstrap="tests/bootstrap.php"
<!-- PHPUnit configuration file with new format for PHPUnit 9.6+ -->
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.6/phpunit.xsd"
bootstrap="vendor/autoload.php"
cacheResult="false"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
>
convertDeprecationsToExceptions="true">
<testsuites>
<testsuite name="SSE Test Suite">
<directory>./tests/</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>
<coverage>
<include>
<directory>./src/</directory>
</whitelist>
</filter>
</phpunit>
</include>
</coverage>
<php>
<ini name="error_reporting" value="-1" />
</php>
</phpunit>
21 changes: 21 additions & 0 deletions phpunit.xml.legacy
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>

<!-- PHPUnit configuration file with old format for legacy PHPUnit -->
<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="SSE Test Suite">
<directory>./tests/</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>
<directory>./src/</directory>
</whitelist>
</filter>
<php>
<ini name="error_reporting" value="-1" />
</php>
</phpunit>
2 changes: 2 additions & 0 deletions tests/BufferedChannelTest.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

namespace Clue\React\Tests\Sse;

use Clue\React\Sse\BufferedChannel;

class BufferedChannelTest extends TestCase
Expand Down
7 changes: 6 additions & 1 deletion tests/EncoderTest.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
<?php

namespace Clue\React\Tests\Sse;

use Clue\React\Sse\Encoder;

class EncoderTest extends TestCase
{
private $encoder;

public function setUp()
/**
* @before
*/
public function setUpEncoder()
{
$this->encoder = new Encoder();
}
Expand Down
32 changes: 32 additions & 0 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

namespace Clue\React\Tests\Sse;

use PHPUnit\Framework\TestCase as BaseTestCase;

require __DIR__ . '/../vendor/autoload.php';

class TestCase extends BaseTestCase
{
protected function expectCallableOnce()
{
$mock = $this->createCallableMock();

$mock
->expects($this->once())
->method('__invoke');

return $mock;
}

protected function createCallableMock()
{
if (method_exists('PHPUnit\Framework\MockObject\MockBuilder', 'addMethods')) {
// PHPUnit 9+
return $this->getMockBuilder('stdClass')->addMethods(array('__invoke'))->getMock();
} else {
// legacy PHPUnit 4 - PHPUnit 8
return $this->getMockBuilder('stdClass')->setMethods(array('__invoke'))->getMock();
}
}
}
34 changes: 0 additions & 34 deletions tests/bootstrap.php

This file was deleted.