Skip to content

Commit

Permalink
Merge pull request #13 from b1rdex/phpunit-6
Browse files Browse the repository at this point in the history
Add phpunit >=5.7 <7 compatibility
  • Loading branch information
gavinlove committed Jun 21, 2017
2 parents b8c13e9 + 003a0c6 commit b1fef62
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 44 deletions.
33 changes: 14 additions & 19 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,6 @@ language: php

sudo: false

php:
- 5.6
- 7.0
- 7.1
- nightly
- hhvm

env:
- PHPUNIT=4.7.*
- PHPUNIT=4.8.*
- PHPUNIT=5.0.*
- PHPUNIT=5.1.*
- PHPUNIT=5.2.*
- PHPUNIT=5.3.*
- PHPUNIT=5.4.*
- PHPUNIT=5.5.*
- PHPUNIT=5.6.*
- PHPUNIT=5.7.*

cache:
directories:
- $HOME/.composer
Expand All @@ -32,3 +13,17 @@ before_script:

script:
- ./bin/phpunit

matrix:
include:
- php: 5.6
env: PHPUNIT=~5.7
- php: 7.0
env: PHPUNIT=~5.7
- php: 7.1
env: PHPUNIT=~6
- php: nightly
env: PHPUNIT=~6
- php: hhvm
dist: trusty
env: PHPUNIT=~5.7
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
],
"require": {
"php": ">=5.6",
"phpunit/phpunit": ">=4.7"
"phpunit/phpunit": ">=5.7 <7"
},
"autoload": {
"psr-4": { "MyBuilder\\PhpunitAccelerator\\": "src" }
Expand Down
32 changes: 10 additions & 22 deletions src/TestListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,13 @@

namespace MyBuilder\PhpunitAccelerator;

class TestListener implements \PHPUnit_Framework_TestListener
use PHPUnit\Framework\BaseTestListener;

if (!interface_exists('\PHPUnit\Framework\Test')) {
class_alias('\PHPUnit_Framework_Test', '\PHPUnit\Framework\Test');
}

class TestListener extends BaseTestListener
{
private $ignorePolicy;

Expand All @@ -13,7 +19,7 @@ public function __construct(IgnoreTestPolicy $ignorePolicy = null)
$this->ignorePolicy = ($ignorePolicy) ?: new NeverIgnoreTestPolicy();
}

public function endTest(\PHPUnit_Framework_Test $test, $time)
public function endTest(\PHPUnit\Framework\Test $test, $time)
{
$testReflection = new \ReflectionObject($test);

Expand All @@ -24,7 +30,7 @@ public function endTest(\PHPUnit_Framework_Test $test, $time)
$this->safelyFreeProperties($test, $testReflection->getProperties());
}

private function safelyFreeProperties(\PHPUnit_Framework_Test $test, array $properties)
private function safelyFreeProperties(\PHPUnit\Framework\Test $test, array $properties)
{
foreach ($properties as $property) {
if ($this->isSafeToFreeProperty($property)) {
Expand All @@ -43,29 +49,11 @@ private function isNotPhpUnitProperty(\ReflectionProperty $property)
return 0 !== strpos($property->getDeclaringClass()->getName(), self::PHPUNIT_PROPERTY_PREFIX);
}

private function freeProperty(\PHPUnit_Framework_Test $test, \ReflectionProperty $property)
private function freeProperty(\PHPUnit\Framework\Test $test, \ReflectionProperty $property)
{
$property->setAccessible(true);
$property->setValue($test, null);
}

public function startTestSuite(\PHPUnit_Framework_TestSuite $suite) {}

public function addError(\PHPUnit_Framework_Test $test, \Exception $e, $time) {}

public function addFailure(\PHPUnit_Framework_Test $test, \PHPUnit_Framework_AssertionFailedError $e, $time) {}

public function addIncompleteTest(\PHPUnit_Framework_Test $test, \Exception $e, $time) {}

public function addSkippedTest(\PHPUnit_Framework_Test $test, \Exception $e, $time) {}

public function endTestSuite(\PHPUnit_Framework_TestSuite $suite) {}

public function startTest(\PHPUnit_Framework_Test $test) {}

public function addRiskyTest(\PHPUnit_Framework_Test $test, \Exception $e, $time) {}

public function addWarning(\PHPUnit_Framework_Test $test, \PHPUnit_Framework_Warning $e, $time) {}
}

class NeverIgnoreTestPolicy implements IgnoreTestPolicy
Expand Down
4 changes: 2 additions & 2 deletions tests/TestListenerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use MyBuilder\PhpunitAccelerator\TestListener;
use MyBuilder\PhpunitAccelerator\IgnoreTestPolicy;

class TestListenerTest extends \PHPUnit_Framework_TestCase
class TestListenerTest extends \PHPUnit\Framework\TestCase
{
private $dummyTest;

Expand Down Expand Up @@ -63,7 +63,7 @@ private function assertDoesNotFreeTestProperty()
}
}

class PHPUnit_Fake extends \PHPUnit_Framework_TestCase
class PHPUnit_Fake extends \PHPUnit\Framework\TestCase
{
public $phpUnitProperty = 1;
}
Expand Down

0 comments on commit b1fef62

Please sign in to comment.