Skip to content

Commit

Permalink
Fix nightly builds (webmozarts#111)
Browse files Browse the repository at this point in the history
* Fix nightly builds by allowing later phpunit versions
  • Loading branch information
BackEndTea authored Jun 28, 2019
1 parent 4950625 commit 255fb9e
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 8 deletions.
5 changes: 4 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@ before_install:
- if [[ $COVERAGE != yes ]]; then phpenv config-rm xdebug.ini || true; fi;

install:
- composer update --prefer-dist --no-interaction
- if [[ $TRAVIS_PHP_VERSION = hhvm-3.30 ]]; then composer require phpunit/phpunit:4.8.36 --dev; fi
- export COMPOSER_FLAGS="--prefer-dist --no-interaction"
- if [[ $TRAVIS_PHP_VERSION = nightly ]]; then export COMPOSER_FLAGS="$COMOPSER_FLAGS --ignore-platform-reqs"; fi
- composer update $COMPOSER_FLAGS

script:
- if [[ $COVERAGE = yes ]]; then vendor/bin/phpunit --coverage-clover=coverage.clover; else vendor/bin/phpunit; fi
Expand Down
3 changes: 1 addition & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@
"symfony/polyfill-ctype": "^1.8"
},
"require-dev": {
"phpunit/phpunit": "^4.6",
"sebastian/version": "^1.0.1"
"phpunit/phpunit": "^4.8.36 || ^7.5.13"
},
"extra": {
"branch-alias": {
Expand Down
10 changes: 7 additions & 3 deletions tests/AssertTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
use Exception;
use Error;
use LogicException;
use PHPUnit_Framework_TestCase;
use RuntimeException;
use stdClass;
use Webmozart\Assert\Assert;
Expand All @@ -26,7 +25,7 @@
*
* @author Bernhard Schussek <[email protected]>
*/
class AssertTest extends PHPUnit_Framework_TestCase
class AssertTest extends BaseTestCase
{
private static $resource;

Expand Down Expand Up @@ -359,7 +358,7 @@ public function getTests()
// no tests for readable()/writable() for now
array('classExists', array(__CLASS__), true),
array('classExists', array(__NAMESPACE__.'\Foobar'), false),
array('subclassOf', array(__CLASS__, 'PHPUnit_Framework_TestCase'), true),
array('subclassOf', array(__CLASS__, 'Webmozart\Assert\Tests\BaseTestCase'), true),
array('subclassOf', array(__CLASS__, 'stdClass'), false),
array('interfaceExists', array('\Countable'), true),
array('interfaceExists', array(__CLASS__), false),
Expand Down Expand Up @@ -506,6 +505,7 @@ public function testAssert($method, $args, $success, $multibyte = false, $minVer
}

call_user_func_array(array('Webmozart\Assert\Assert', $method), $args);
$this->addToAssertionCount(1);
}

/**
Expand All @@ -527,6 +527,7 @@ public function testNullOr($method, $args, $success, $multibyte = false, $minVer
}

call_user_func_array(array('Webmozart\Assert\Assert', 'nullOr'.ucfirst($method)), $args);
$this->addToAssertionCount(1);
}

/**
Expand All @@ -535,6 +536,7 @@ public function testNullOr($method, $args, $success, $multibyte = false, $minVer
public function testNullOrAcceptsNull($method)
{
call_user_func(array('Webmozart\Assert\Assert', 'nullOr'.ucfirst($method)), null);
$this->addToAssertionCount(1);
}

/**
Expand All @@ -559,6 +561,7 @@ public function testAllArray($method, $args, $success, $multibyte = false, $minV
array_unshift($args, array($arg));

call_user_func_array(array('Webmozart\Assert\Assert', 'all'.ucfirst($method)), $args);
$this->addToAssertionCount(1);
}

/**
Expand All @@ -583,6 +586,7 @@ public function testAllTraversable($method, $args, $success, $multibyte = false,
array_unshift($args, new ArrayIterator(array($arg)));

call_user_func_array(array('Webmozart\Assert\Assert', 'all'.ucfirst($method)), $args);
$this->addToAssertionCount(1);
}

public function getStringConversions()
Expand Down
36 changes: 36 additions & 0 deletions tests/BaseTestCase.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

namespace Webmozart\Assert\Tests;

use PHPUnit\Framework\TestCase;

/**
* This class allows us to be compatible with multiple PHPUnit versions.
*/
class BaseTestCase extends TestCase
{
/**
* The setExpectedException got removed in later phpunit versions,
* and instead it got split up into three functions.
*
* So if the newer functions exist we call those where needed, and otherwise
* we just use the original function.
*
* @param string $exceptionName
* @param string $exceptionMessage
* @param int $exceptionCode
*/
public function setExpectedException($exceptionName, $exceptionMessage = '', $exceptionCode = null) {
if (method_exists($this, 'expectException')) {
$this->expectException($exceptionName);
if($exceptionMessage) {
$this->expectExceptionMessage($exceptionMessage);
}
if( $exceptionCode) {
$this->expectExceptionCode($exceptionCode);
}
return;
}
parent::setExpectedException($exceptionName, $exceptionMessage, $exceptionCode);
}
}
3 changes: 1 addition & 2 deletions tests/ProjectCodeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@

namespace Webmozart\Assert\Tests;

use PHPUnit_Framework_TestCase;
use ReflectionClass;
use ReflectionMethod;

/**
* @coversNothing
*/
class ProjectCodeTest extends PHPUnit_Framework_TestCase
class ProjectCodeTest extends BaseTestCase
{
private static $readmeContent;
private static $assertDocComment;
Expand Down

0 comments on commit 255fb9e

Please sign in to comment.