Skip to content

Commit

Permalink
PHPUnit tweaks (YOURLS#2706)
Browse files Browse the repository at this point in the history
* Overwrite tests/composer.json with specific phpunit version depending on PHP version
* Send code coverage to scrutinize
  • Loading branch information
ozh authored Jun 3, 2020
1 parent 2eb2df0 commit 033b815
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 16 deletions.
35 changes: 33 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,64 @@ language: php
env:
global:
- DB=mysql
- PHPUNIT_FLAGS='--no-coverage'
- TEST_COVERAGE=0

services:
- mysql

# https://phpunit.de/supported-versions.html
matrix:
include:
- php: 5.6
env: PHPUNIT_VERSION=5.7.*
- php: 7.0
env: PHPUNIT_VERSION=6.5.*
- php: 7.1
env: PHPUNIT_VERSION=7.5.*
- php: 7.2
env: PHPUNIT_VERSION=7.5.*
- php: 7.3
env: PHPUNIT_VERSION=7.5.*
- php: 7.4
env: PHPUNIT_VERSION=7.5.* TEST_COVERAGE=1 PHPUNIT_FLAGS='--coverage-clover clover.xml'
- php: nightly
env: PHPUNIT_VERSION=7.5.*
fast_finish: true
allow_failures:
- php: nightly

cache:
apt: true
directories:
# Cache directory for older Composer versions.
- $HOME/.composer/cache/files
# Cache directory for more recent Composer versions.
- $HOME/.cache/composer/files

install:
# Speed up build time by disabling Xdebug unless actually needed.
- if [ "$TEST_COVERAGE" != '1' ]; then phpenv config-rm xdebug.ini || echo 'No xdebug config.'; fi
- composer global require hirak/prestissimo --no-suggest --no-interaction
# Update tests/composer.json to overwrite phpunit with specific version
- composer require "phpunit/phpunit:${PHPUNIT_VERSION}" -d ./tests --dev --no-update --no-interaction --no-suggest
- composer install -d ./tests --no-suggest --no-interaction

before_script:
- mysql --version
- git clone git://github.com/ozh/YOURLS-fr_FR.git user/languages/fr
- cp user/languages/fr/fr_FR.* user/languages
- mysql -e 'create database IF NOT EXISTS yourls_tests;'
- cp tests/data/config/yourls-tests-config-travis.php user/config.php

install: composer install -d ./tests
script: tests/vendor/bin/phpunit --configuration ./phpunit-travis.xml.dist $PHPUNIT_FLAGS

script: tests/vendor/bin/phpunit --configuration ./phpunit-travis.xml.dist
after_script:
- |
if [ "$TEST_COVERAGE" == '1' ]; then
travis_retry wget https://scrutinizer-ci.com/ocular.phar;
travis_retry php ocular.phar code-coverage:upload --format=php-clover clover.xml;
fi
notifications:
email: false
11 changes: 8 additions & 3 deletions phpunit-travis.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@
<group>ajax</group>
</exclude>
</groups>
<filter>
<whitelist>
<directory suffix=".php">./includes</directory>
<exclude>
<directory suffix=".php">./includes/vendors</directory>
</exclude>
</whitelist>
</filter>
<php>
<!-- Constants -->
<const name="PHPUNIT_TESTSUITE" value="true" />
Expand All @@ -33,7 +41,4 @@
<!-- API -->
<request name="format" value="simple"/>
</php>
<logging>
<log type="junit" target="build/logs/junit.xml" logIncompleteSkipped="false" />
</logging>
</phpunit>
5 changes: 1 addition & 4 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
</exclude>
</groups>
<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<whitelist>
<directory suffix=".php">./includes</directory>
<exclude>
<directory suffix=".php">./includes/vendors</directory>
Expand All @@ -43,7 +43,4 @@
<!-- API -->
<request name="format" value="simple"/>
</php>
<logging>
<log type="junit" target="build/logs/junit.xml" />
</logging>
</phpunit>
12 changes: 5 additions & 7 deletions tests/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,11 @@
yourls_get_all_options();
yourls_load_plugins();

// PHPUnit 6 compatibility for previous versions
if ( class_exists( 'PHPUnit\Runner\Version' ) && version_compare( PHPUnit\Runner\Version::id(), '6.0', '>=' ) ) {
class_alias( 'PHPUnit\Framework\Assert', 'PHPUnit_Framework_Assert' );
class_alias( 'PHPUnit\Framework\TestCase', 'PHPUnit_Framework_TestCase' );
class_alias( 'PHPUnit\Framework\Error\Error', 'PHPUnit_Framework_Error' );
class_alias( 'PHPUnit\Framework\Error\Notice', 'PHPUnit_Framework_Error_Notice' );
class_alias( 'PHPUnit\Framework\Error\Warning', 'PHPUnit_Framework_Error_Warning' );
/**
* Compatibility with PHPUnit 6+
*/
if ( class_exists( 'PHPUnit\Runner\Version' ) ) {
require_once dirname( __FILE__ ) . '/includes/phpunit6-compat.php';
}

// At this point, tests will start
Expand Down
19 changes: 19 additions & 0 deletions tests/includes/phpunit6-compat.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

// PHPUnit 6 compatibility for previous versions
if ( class_exists( 'PHPUnit\Runner\Version' ) && version_compare( PHPUnit\Runner\Version::id(), '6.0', '>=' ) ) {
class_alias( 'PHPUnit\Framework\Assert' , 'PHPUnit_Framework_Assert' );
class_alias( 'PHPUnit\Framework\TestCase' , 'PHPUnit_Framework_TestCase' );
class_alias( 'PHPUnit\Framework\Error\Error' , 'PHPUnit_Framework_Error' );
class_alias( 'PHPUnit\Framework\Error\Notice' , 'PHPUnit_Framework_Error_Notice' );
class_alias( 'PHPUnit\Framework\Error\Warning' , 'PHPUnit_Framework_Error_Warning' );
class_alias( 'PHPUnit\Framework\Exception' , 'PHPUnit_Framework_Exception' );
class_alias( 'PHPUnit\Framework\ExpectationFailedException' , 'PHPUnit_Framework_ExpectationFailedException' );
class_alias( 'PHPUnit\Framework\Test' , 'PHPUnit_Framework_Test' );
class_alias( 'PHPUnit\Framework\Warning' , 'PHPUnit_Framework_Warning' );
class_alias( 'PHPUnit\Framework\AssertionFailedError' , 'PHPUnit_Framework_AssertionFailedError' );
class_alias( 'PHPUnit\Framework\TestSuite' , 'PHPUnit_Framework_TestSuite' );
class_alias( 'PHPUnit\Framework\TestListener' , 'PHPUnit_Framework_TestListener' );
class_alias( 'PHPUnit\Util\GlobalState' , 'PHPUnit_Util_GlobalState' );
class_alias( 'PHPUnit\Util\Getopt' , 'PHPUnit_Util_Getopt' );
}

0 comments on commit 033b815

Please sign in to comment.