Skip to content

Commit 9095c71

Browse files
authored
Merge pull request #11 from SimonFrings/tests
Run tests on PHP 8, PHP 7.4 and PHPUnit 9 and update PHPUnit configuration schema for PHPUnit 9.3
2 parents b7a2a92 + 21a1302 commit 9095c71

File tree

8 files changed

+77
-23
lines changed

8 files changed

+77
-23
lines changed

.gitattributes

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/.gitattributes export-ignore
2+
/.github/workflows/ export-ignore
3+
/.gitignore export-ignore
4+
/phpunit.xml.dist export-ignore
5+
/phpunit.xml.legacy export-ignore
6+
/tests/ export-ignore

.github/workflows/ci.yml

+11
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,15 @@ jobs:
1010
strategy:
1111
matrix:
1212
php:
13+
- 8.0
14+
- 7.4
15+
- 7.3
16+
- 7.2
17+
- 7.1
18+
- 7.0
1319
- 5.6
20+
- 5.5
21+
- 5.4
1422
- 5.3
1523
steps:
1624
- uses: actions/checkout@v2
@@ -21,6 +29,9 @@ jobs:
2129
coverage: xdebug
2230
- run: composer install
2331
- run: vendor/bin/phpunit --coverage-text
32+
if: ${{ matrix.php >= 7.3 }}
33+
- run: vendor/bin/phpunit --coverage-text -c phpunit.xml.legacy
34+
if: ${{ matrix.php < 7.3 }}
2435

2536
PHPUnit-hhvm:
2637
name: PHPUnit (HHVM)

README.md

+7
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,13 @@ The recommended way to install this library is [through Composer](https://getcom
8080
}
8181
```
8282

83+
See also the [CHANGELOG](CHANGELOG.md) for details about version upgrades.
84+
85+
This project aims to run on any platform and thus does not require any PHP
86+
extensions and supports running on legacy PHP 5.3 through current PHP 8+ and
87+
HHVM.
88+
It's *highly recommended to use PHP 7+* for this project.
89+
8390
## Tests
8491

8592
To run the test suite, you first need to clone this repo and then install all

composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,6 @@
1717
"php": ">=5.3"
1818
},
1919
"require-dev": {
20-
"phpunit/phpunit": "^4.8.35"
20+
"phpunit/phpunit": "^9.3 || ^5.7 || ^4.8.35"
2121
}
2222
}

phpunit.xml.dist

+11-11
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
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.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"
47
colors="true"
5-
convertErrorsToExceptions="true"
6-
convertNoticesToExceptions="true"
7-
convertWarningsToExceptions="true"
8-
>
8+
cacheResult="false">
99
<testsuites>
10-
<testsuite name="JSON stream Test Suite">
10+
<testsuite name="JSON Stream Test Suite">
1111
<directory>./tests/</directory>
1212
</testsuite>
1313
</testsuites>
14-
<filter>
15-
<whitelist>
14+
<coverage>
15+
<include>
1616
<directory>./src/</directory>
17-
</whitelist>
18-
</filter>
19-
</phpunit>
17+
</include>
18+
</coverage>
19+
</phpunit>

phpunit.xml.legacy

+18
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="JSON Stream 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/StreamingJsonParserTest.php

+23-5
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,14 @@
22

33
use Clue\JsonStream\StreamingJsonParser;
44

5-
class StreamingJsonParserTest extends TestCase
5+
class StreamingJsonParserTest extends PHPUnit\Framework\TestCase
66
{
77
private $parser;
88

9-
public function setUp()
9+
/**
10+
* @before
11+
*/
12+
public function setUpParser()
1013
{
1114
$this->parser = new StreamingJsonParser();
1215
}
@@ -57,11 +60,26 @@ public function testMultipleObjectAndArray()
5760
$this->assertTrue($this->parser->isEmpty());
5861
}
5962

60-
/**
61-
* @expectedException UnexpectedValueException
62-
*/
6363
public function testInvalid()
6464
{
65+
$this->setExpectedException('UnexpectedValueException');
6566
$this->parser->push('invalid');
6667
}
68+
69+
public function setExpectedException($exception, $exceptionMessage = '', $exceptionCode = null)
70+
{
71+
if (method_exists($this, 'expectException')) {
72+
// PHPUnit 5.2+
73+
$this->expectException($exception);
74+
if ($exceptionMessage !== '') {
75+
$this->expectExceptionMessage($exceptionMessage);
76+
}
77+
if ($exceptionCode !== null) {
78+
$this->expectExceptionCode($exceptionCode);
79+
}
80+
} else {
81+
// legacy PHPUnit 4 - PHPUnit 5.1
82+
parent::setExpectedException($exception, $exceptionMessage, $exceptionCode);
83+
}
84+
}
6785
}

tests/bootstrap.php

-6
This file was deleted.

0 commit comments

Comments
 (0)