Skip to content

Commit

Permalink
Merge branch 'feature/more-code-coverage'
Browse files Browse the repository at this point in the history
  • Loading branch information
ben-xo committed Jan 3, 2022
2 parents fd1a187 + 290b4e9 commit 6ea6d65
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 3 deletions.
4 changes: 3 additions & 1 deletion test/combine_coverage.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php declare(strict_types=1);

ini_set('memory_limit', (string)(1024 * 1024 * 1024) );

require_once('vendor/autoload.php');

use SebastianBergmann\CodeCoverage\Report\Text as PHP_CodeCoverage_Report_Text;
Expand All @@ -12,6 +14,6 @@
}

// Based on PHPUnit_TextUI_TestRunner::doRun
$writer = new PHP_CodeCoverage_Report_Text();
$writer = new PHP_CodeCoverage_Report_Text(50, 90, true, false);

echo $writer->process($codeCoverage);
8 changes: 7 additions & 1 deletion test/dir2castWithCoverage.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,14 @@
$filter = new Filter;
$filter->includeDirectory('../../dir2cast.php');

if(isset($_SERVER['PATH_COVERAGE']) && $_SERVER['PATH_COVERAGE'] != '') {
$selector = (new Selector)->forLineAndPathCoverage($filter);
} else {
$selector = (new Selector)->forLineCoverage($filter);
}

$coverage = new CodeCoverage(
(new Selector)->forLineCoverage($filter),
$selector,
$filter
);

Expand Down
24 changes: 23 additions & 1 deletion test/run.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
#!/bin/bash
set -e

# Test runner.
#
# Usage:
#
# ./test/run.sh # runs all tests
# ./test/run.sh FilenameTest.php # runs only that test
# PATH_COVERAGE=yes ./test/run.sh # adds more (but slower) coverage reporting

SCRIPT_DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )

cd "$SCRIPT_DIR"
Expand All @@ -21,6 +29,20 @@ fi

export XDEBUG_MODE=coverage
rm -f /tmp/cov-*
vendor/bin/phpunit --bootstrap "$SCRIPT_DIR/bootstrap.php" --coverage-php /tmp/cov-main --coverage-filter ../dir2cast.php ${tests[@]}

export PATH_COVERAGE=${PATH_COVERAGE:-}
PATH_COVERAGE_OPTION=""

if [[ "$PATH_COVERAGE" != '' ]]; then
PATH_COVERAGE_OPTION="--path-coverage"
fi

vendor/bin/phpunit \
--bootstrap "$SCRIPT_DIR/bootstrap.php" \
--coverage-php /tmp/cov-main \
--coverage-filter ../dir2cast.php \
$PATH_COVERAGE_OPTION \
${tests[@]}

php combine_coverage.php
rm -rf testdir /tmp/cov-*

0 comments on commit 6ea6d65

Please sign in to comment.