Skip to content

Commit

Permalink
Merge pull request #18 from SimonFrings/tests
Browse files Browse the repository at this point in the history
Run tests on PHPUnit 9 and update PHPUnit configuration schema for PHPUnit 9.3
  • Loading branch information
clue authored Oct 17, 2020
2 parents 7a6f5f9 + f828a0c commit 5c35c4e
Show file tree
Hide file tree
Showing 9 changed files with 54 additions and 16 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
9 changes: 4 additions & 5 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 @@ -21,10 +21,9 @@ matrix:
allow_failures:
- php: hhvm-3.18

sudo: false

install:
- composer install --no-interaction
- composer install

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
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"react/stream": "^1.0 || ^0.7 || ^0.6"
},
"require-dev": {
"phpunit/phpunit": "^7.0 || ^6.0 || ^5.7 || ^4.8.35",
"phpunit/phpunit": "^9.3 || ^5.7 || ^4.8.35",
"react/child-process": "^0.6",
"react/event-loop": "^1.0 || ^0.5 || ^0.4 || ^0.3"
}
Expand Down
17 changes: 11 additions & 6 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,14 +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="CSV test suite">
<testsuite name="CSV 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="CSV Test Suite">
<directory>./tests/</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>
<directory>./src/</directory>
</whitelist>
</filter>
</phpunit>
5 changes: 4 additions & 1 deletion tests/AssocDecoderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ class AssocDecoderTest extends TestCase
private $input;
private $decoder;

public function setUp()
/**
* @before
*/
public function setUpDecoder()
{
$stream = fopen('php://temp', 'r');
$loop = $this->getMockBuilder('React\EventLoop\LoopInterface')->getMock();
Expand Down
5 changes: 4 additions & 1 deletion tests/DecoderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ class DecoderTest extends TestCase
private $input;
private $decoder;

public function setUp()
/**
* @before
*/
public function setUpDecoder()
{
$stream = fopen('php://temp', 'r');
$loop = $this->getMockBuilder('React\EventLoop\LoopInterface')->getMock();
Expand Down
5 changes: 4 additions & 1 deletion tests/EncoderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ class EncoderTest extends TestCase
private $output;
private $encoder;

public function setUp()
/**
* @before
*/
public function setUpEncoder()
{
$stream = fopen('php://temp', 'r+');
$loop = $this->getMockBuilder('React\EventLoop\LoopInterface')->getMock();
Expand Down
8 changes: 7 additions & 1 deletion tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ protected function expectCallableOnceWith($value)

protected function createCallableMock()
{
return $this->getMockBuilder('stdClass')->setMethods(array('__invoke'))->getMock();
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();
}
}
}

0 comments on commit 5c35c4e

Please sign in to comment.