Skip to content

Run tests on PHPUnit 9 and update PHPUnit configuration schema for PHPUnit 9.3 #18

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 2 commits into from
Oct 19, 2020
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 @@
/.travis.yml export-ignore
/examples/ export-ignore
/phpunit.xml.dist export-ignore
/phpunit.xml.legacy export-ignore
/tests/ export-ignore
7 changes: 3 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,9 @@ php:
# lock distro so new future defaults will not break the build
dist: trusty

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 @@ -23,6 +23,6 @@
"react/http": "^1.0"
},
"require-dev": {
"phpunit/phpunit": "^7.0 || ^6.4 || ^5.7 || ^4.8.35"
"phpunit/phpunit": "^9.3 || ^5.7 || ^4.8.35"
}
}
15 changes: 10 additions & 5 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="EventSource 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="EventSource Test Suite">
<directory>./tests/</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>
<directory>./src/</directory>
</whitelist>
</filter>
</phpunit>
29 changes: 20 additions & 9 deletions tests/EventSourceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,30 +13,24 @@

class EventSourceTest extends TestCase
{
/**
* @expectedException InvalidArgumentException
*/
public function testConstructorThrowsIfFirstArgumentIsNotAnUri()
{
$loop = $this->getMockBuilder('React\EventLoop\LoopInterface')->getMock();
$this->setExpectedException('InvalidArgumentException');
new EventSource('///', $loop);
}

/**
* @expectedException InvalidArgumentException
*/
public function testConstructorThrowsIfUriArgumentDoesNotIncludeScheme()
{
$loop = $this->getMockBuilder('React\EventLoop\LoopInterface')->getMock();
$this->setExpectedException('InvalidArgumentException');
new EventSource('example.com', $loop);
}

/**
* @expectedException InvalidArgumentException
*/
public function testConstructorThrowsIfUriArgumentIncludesInvalidScheme()
{
$loop = $this->getMockBuilder('React\EventLoop\LoopInterface')->getMock();
$this->setExpectedException('InvalidArgumentException');
new EventSource('ftp://example.com', $loop);
}

Expand Down Expand Up @@ -620,4 +614,21 @@ public function testReconnectAfterStreamClosesUsesLastEventIdFromParsedEventStre
$this->assertNotNull($timerReconnect);
$timerReconnect();
}

public function setExpectedException($exception, $exceptionMessage = '', $exceptionCode = null)
{
if (method_exists($this, 'expectException')) {
// PHPUnit 5.2+
$this->expectException($exception);
if ($exceptionMessage !== '') {
$this->expectExceptionMessage($exceptionMessage);
}
if ($exceptionCode !== null) {
$this->expectExceptionCode($exceptionCode);
}
} else {
// legacy PHPUnit 4 - PHPUnit 5.1
parent::setExpectedException($exception, $exceptionMessage, $exceptionCode);
}
}
}