Skip to content

Commit

Permalink
Improve test suite by adding "composer run multicover"
Browse files Browse the repository at this point in the history
This will aid on running the tests with coverage on both PHP7 and PHP8,
merge coverage reports and render them as HTML to be inspected by
humans.

It's not completely maintenance free because some paths will probably
have to be adjusted for others, but it's way better than nothing.
  • Loading branch information
amotl committed Feb 25, 2021
1 parent 8ebeb75 commit cefb5e3
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 4 deletions.
18 changes: 14 additions & 4 deletions DEVELOP.rst
Original file line number Diff line number Diff line change
Expand Up @@ -81,15 +81,15 @@ Installation

Install prerequisites::

# Install different PHP releases.
brew install [email protected] [email protected] [email protected] composer
# Install different PHP releases and Composer.
brew install [email protected] [email protected] [email protected] brew-php-switcher composer

# Select PHP version.
brew-php-switcher 7.3
brew-php-switcher 7.4
brew-php-switcher 8.0

# Install xdebug extension for tracking code coverage.
# Install `xdebug` extension into each environment for tracking code coverage.
pecl install xdebug

Get the sources::
Expand All @@ -113,9 +113,19 @@ Running the Tests
--mount type=bind,source=$PWD/test/provisioning/truststore,target=/vagrant/test/provisioning/truststore \
--publish 4200:4200 --publish 5432:5432 crate/crate:nightly

# Run test suite
# Run test suite on current/default version of PHP
composer run test

# Run tests on both PHP7 and PHP8 to get the full picture of coverage
composer run multicover
open build/multicover/html/index.html


Invoke code style checks
========================

::

# Run code style checks
composer run check-style

Expand Down
2 changes: 2 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
},
"scripts": {
"test": "XDEBUG_MODE=coverage phpunit --coverage-clover build/logs/clover.xml",
"coverage-html": "XDEBUG_MODE=coverage phpunit --coverage-html build/logs/html",
"multicover": "./devtools/php-multicover.sh",
"check-style": "phpcs",
"fix-style": "phpcbf"
}
Expand Down
63 changes: 63 additions & 0 deletions devtools/php-multicover.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#!/bin/sh
#
# About
# =====
#
# Run tests with coverage on both PHP7 and PHP8,
# merge coverage reports and render them as HTML.
#
# Please adjust the paths to the PHP interpreters
# to fit your needs. Make sure to `pecl install xdebug`
# in both PHP7 and PHP8 environments beforehand.
#
# Setup
# =====
#
# Install different PHP releases and Composer::
#
# brew install [email protected] [email protected] [email protected] brew-php-switcher composer
#
# Select PHP version::
#
# brew-php-switcher 7.3
# brew-php-switcher 7.4
# brew-php-switcher 8.0
#
# Install `xdebug` extension into each environment for tracking code coverage::
#
# pecl install xdebug
#
# Install `phpunit-merger`::
#
# composer require --dev nimut/phpunit-merger
#
# Please make sure to remove it before committing as it is currently not available for PHP8::
#
# composer remove --dev nimut/phpunit-merger
#

# Define shortcuts to executables.
php7=/usr/local/Cellar/[email protected]/7.4.15/bin/php
php8=/usr/local/Cellar/php/8.0.2/bin/php
phpunit="$(pwd)/vendor/bin/phpunit"
phpunit_merger="$(pwd)/vendor/bin/phpunit-merger"

# Prepare output directories.
mkdir -p build/multicover/reports build/multicover/html
rm -rf build/multicover/reports/* build/multicover/html/*

# Enable coverage tracing.
export XDEBUG_MODE=coverage

# Run tests with PHP coverage output on both PHP7 and PHP8.
echo Running tests with coverage on PHP7
$php7 $phpunit --coverage-php build/multicover/reports/clover-php7.php
echo; echo

echo Running tests with coverage on PHP8
$php8 $phpunit --coverage-php build/multicover/reports/clover-php8.php
echo; echo

# Merge coverage reports and generate HTML output.
echo Merging test reports
$php7 $phpunit_merger coverage build/multicover/reports --html=build/multicover/html /dev/null

0 comments on commit cefb5e3

Please sign in to comment.