Skip to content
This repository has been archived by the owner on Oct 6, 2023. It is now read-only.

Commit

Permalink
Extend PHPUnit support (#4)
Browse files Browse the repository at this point in the history
* Extend PHPUnit support

* empty

* try to support 7.2 even on 4.0

* Revert "try to support 7.2 even on 4.0"

This reverts commit 46e733b.

* debug

* Revert "debug"

This reverts commit 27d3369.

* respect php vs phpunit incompatibilities

* series method is not available on 4.0
  • Loading branch information
keradus authored Jul 8, 2017
1 parent 7c96a2d commit a502c24
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 12 deletions.
17 changes: 16 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,26 @@ before_install:
install: skip

script:
- ./run-tests.sh 4.8.35 || travis_terminate 1
- ./run-tests.sh ~4.0.0 || travis_terminate 1
- ./run-tests.sh ~4.1.0 || travis_terminate 1
- ./run-tests.sh ~4.2.0 || travis_terminate 1
- ./run-tests.sh ~4.3.0 || travis_terminate 1
- ./run-tests.sh ~4.4.0 || travis_terminate 1
- ./run-tests.sh ~4.5.0 || travis_terminate 1
- ./run-tests.sh ~4.6.0 || travis_terminate 1
- ./run-tests.sh ~4.7.0 || travis_terminate 1
- ./run-tests.sh ~4.8.0 || travis_terminate 1
- ./run-tests.sh ~5.0.0 || travis_terminate 1
- ./run-tests.sh ~5.1.0 || travis_terminate 1
- ./run-tests.sh ~5.2.0 || travis_terminate 1
- ./run-tests.sh ~5.3.0 || travis_terminate 1
- ./run-tests.sh ~5.4.0 || travis_terminate 1
- ./run-tests.sh ~5.5.0 || travis_terminate 1
- ./run-tests.sh ~5.6.0 || travis_terminate 1
- ./run-tests.sh ~5.7.0 || travis_terminate 1
- ./run-tests.sh ~6.0.0 || travis_terminate 1
- ./run-tests.sh ~6.1.0 || travis_terminate 1
- ./run-tests.sh ~6.2.0 || travis_terminate 1

jobs:
include:
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"php": "^5.3.6 || ^7.0"
},
"require-dev": {
"phpunit/phpunit": "^4.8.35 || ^5.4.3"
"phpunit/phpunit": "^4 || ^5 || ^6"
},
"conflict": {
"hhvm": "*"
Expand Down
2 changes: 1 addition & 1 deletion phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/4.8/phpunit.xsd"
backupGlobals="false"
backupStaticAttributes="false"
bootstrap="./vendor/autoload.php"
bootstrap="./tests/bootstrap.php"
colors="true"
columns="max"
convertErrorsToExceptions="true"
Expand Down
2 changes: 1 addition & 1 deletion run-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ fi

echo -e "\e[46m§ Trying to execute tests under PHPUnit ${PHPUNIT}.\e[0m"

rm -rf composer.lock vendor/
rm -f composer.lock

echo -e "\n\e[46m§ Installing deps...\e[0m"
composer require -q --dev --no-update phpunit/phpunit:${PHPUNIT}
Expand Down
13 changes: 7 additions & 6 deletions tests/ReporterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

namespace PHPUnitGoodPractices\Tests;

use PHPUnit\Framework\Error\Warning;
use PHPUnit\Framework\TestCase;
use PHPUnitGoodPractices\Reporter;

Expand All @@ -31,10 +32,10 @@ public function testReportWithDefaults()
$expectedMessage = "PHPUnit good practice has been abused.\nFoo.";

if (is_callable(array($this, 'expectException'))) {
$this->expectException(\PHPUnit_Framework_Error_Warning::class);
$this->expectException(Warning::class);
$this->expectExceptionMessage($expectedMessage);
} else {
$this->setExpectedException(\PHPUnit_Framework_Error_Warning::class, $expectedMessage);
$this->setExpectedException(Warning::class, $expectedMessage);
}

Reporter::report('Foo.');
Expand All @@ -47,10 +48,10 @@ public function testReportWithoutHeaders()
$expectedMessage = 'Foo.';

if (is_callable(array($this, 'expectException'))) {
$this->expectException(\PHPUnit_Framework_Error_Warning::class);
$this->expectException(Warning::class);
$this->expectExceptionMessage($expectedMessage);
} else {
$this->setExpectedException(\PHPUnit_Framework_Error_Warning::class, $expectedMessage);
$this->setExpectedException(Warning::class, $expectedMessage);
}

Reporter::report('Foo.');
Expand All @@ -75,9 +76,9 @@ public function testReportAfterClearingCustomReporter()

Reporter::clearCustomReporter();
if (is_callable(array($this, 'expectException'))) {
$this->expectException(\PHPUnit_Framework_Error_Warning::class);
$this->expectException(Warning::class);
} else {
$this->setExpectedException(\PHPUnit_Framework_Error_Warning::class);
$this->setExpectedException(Warning::class);
}
Reporter::report('Foo.');
}
Expand Down
5 changes: 3 additions & 2 deletions tests/StrictAssertionTraitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

namespace PHPUnitGoodPractices\Tests;

use PHPUnit\Framework\Error\Warning;
use PHPUnit\Framework\TestCase;
use PHPUnitGoodPractices\StrictAssertionTrait;

Expand Down Expand Up @@ -41,9 +42,9 @@ public function testAssertEqualsFails()
$data = 5;

if (is_callable(array($this, 'expectException'))) {
$this->expectException(\PHPUnit_Framework_Error_Warning::class);
$this->expectException(Warning::class);
} else {
$this->setExpectedException(\PHPUnit_Framework_Error_Warning::class);
$this->setExpectedException(Warning::class);
}

$this->assertEquals($data, $data);
Expand Down
34 changes: 34 additions & 0 deletions tests/bootstrap.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

/*
* This file is part of PHPUnit Good Practices.
*
* (c) Dariusz Rumiński <[email protected]>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/

if (!class_exists('PHPUnit\Framework\Error\Warning')) {
class_alias('PHPUnit_Framework_Error_Warning', 'PHPUnit\Framework\Error\Warning');
}

if (!class_exists('PHPUnit\Framework\TestCase')) {
class_alias('PHPUnit_Framework_TestCase', 'PHPUnit\Framework\TestCase');
}

if (!class_exists('PHPUnit\Runner\Version')) {
class_alias('PHPUnit_Runner_Version', 'PHPUnit\Runner\Version');
}

if (
PHP_VERSION_ID >= 70200 && version_compare(PHPUnit\Runner\Version::id(), '4.1') < 0
) {
die(sprintf(
"\e[45mPHPUnit %s: Is not compatible with PHP %s.\e[0m",
PHPUnit\Runner\Version::id(),
PHP_VERSION
));
}

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

0 comments on commit a502c24

Please sign in to comment.