|
|
|
<?php
|
|
|
|
|
|
|
|
use Robo\Result;
|
|
|
|
|
|
|
|
const BASE = __DIR__.\DIRECTORY_SEPARATOR;
|
|
|
|
const BASE_TEST = BASE."tests".\DIRECTORY_SEPARATOR;
|
|
|
|
define("IS_WIN", defined("PHP_WINDOWS_VERSION_MAJOR"));
|
|
|
|
define("IS_MAC", php_uname("s") === "Darwin");
|
|
|
|
|
|
|
|
function norm(string $path): string {
|
|
|
|
$out = realpath($path);
|
|
|
|
if (!$out) {
|
|
|
|
$out = str_replace(["/", "\\"], \DIRECTORY_SEPARATOR, $path);
|
|
|
|
}
|
|
|
|
return $out;
|
|
|
|
}
|
|
|
|
|
|
|
|
class RoboFile extends \Robo\Tasks {
|
|
|
|
/** Runs the typical test suite
|
|
|
|
*
|
|
|
|
* Arguments passed to the task are passed on to PHPUnit. Thus one may, for
|
|
|
|
* example, run the following command and get the expected results:
|
|
|
|
*
|
|
|
|
* ./robo test --testsuite Tokenizer --exclude-group slow --testdox
|
|
|
|
*
|
|
|
|
* Please see the PHPUnit documentation for available options.
|
|
|
|
*/
|
|
|
|
public function test(array $args): Result {
|
|
|
|
return $this->runTests(escapeshellarg(\PHP_BINARY), "typical", $args);
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Runs the full test suite
|
|
|
|
*
|
|
|
|
* This includes pedantic tests which may help to identify problems.
|
|
|
|
* See help for the "test" task for more details.
|
|
|
|
*/
|
|
|
|
public function testFull(array $args): Result {
|
|
|
|
return $this->runTests(escapeshellarg(\PHP_BINARY), "full", $args);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Runs a quick subset of the test suite
|
|
|
|
*
|
|
|
|
* See help for the "test" task for more details.
|
|
|
|
*/
|
|
|
|
public function testQuick(array $args): Result {
|
|
|
|
return $this->runTests(escapeshellarg(\PHP_BINARY), "quick", $args);
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Manually updates the imported html5lib test suite */
|
|
|
|
public function testUpdate(): Result {
|
|
|
|
$dir = BASE_TEST."html5lib-tests";
|
|
|
|
if (is_dir($dir)) {
|
|
|
|
return $this->taskGitStack()->dir($dir)->pull()->run();
|
|
|
|
} else {
|
|
|
|
return $this->taskGitStack()->cloneRepo("https://github.com/html5lib/html5lib-tests", $dir)->run();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Produces a code coverage report
|
|
|
|
*
|
|
|
|
* By default this task produces an HTML-format coverage report in
|
|
|
|
* tests/coverage/. Additional reports may be produced by passing
|
|
|
|
* arguments to this task as one would to PHPUnit.
|
|
|
|
*/
|
|
|
|
public function coverage(array $args): Result {
|
|
|
|
// run tests with code coverage reporting enabled
|
|
|
|
$exec = $this->findCoverageEngine();
|
|
|
|
return $this->runTests($exec, "coverage", array_merge(["--coverage-html", BASE_TEST."coverage"], $args));
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Produces a code coverage report, with redundant tests
|
|
|
|
*
|
|
|
|
* Depending on the environment, some tests that normally provide
|
|
|
|
* coverage may be skipped, while working alternatives are normally
|
|
|
|
* suppressed for reasons of time. This coverage report will try to
|
|
|
|
* run all tests which may cover code.
|
|
|
|
*
|
|
|
|
* See also help for the "coverage" task for more details.
|
|
|
|
*/
|
|
|
|
public function coverageFull(array $args): Result {
|
|
|
|
// run tests with code coverage reporting enabled
|
|
|
|
$exec = $this->findCoverageEngine();
|
|
|
|
return $this->runTests($exec, "typical", array_merge(["--coverage-html", BASE_TEST."coverage"], $args));
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Runs the coding standards fixer */
|
|
|
|
public function clean($opts = ['demo|d' => false]): Result {
|
|
|
|
$t = $this->taskExec(norm(BASE."vendor/bin/php-cs-fixer"));
|
|
|
|
$t->arg("fix");
|
|
|
|
if ($opts['demo']) {
|
|
|
|
$t->args("--dry-run", "--diff")->option("--diff-format", "udiff");
|
|
|
|
}
|
|
|
|
return $t->run();
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function findCoverageEngine(): string {
|
|
|
|
if (IS_WIN) {
|
|
|
|
$dbg = dirname(\PHP_BINARY)."\\phpdbg.exe";
|
|
|
|
$dbg = file_exists($dbg) ? $dbg : "";
|
|
|
|
} else {
|
|
|
|
$dbg = trim(`which phpdbg 2>/dev/null`);
|
|
|
|
}
|
|
|
|
if ($dbg) {
|
|
|
|
return escapeshellarg($dbg)." -qrr";
|
|
|
|
} else {
|
|
|
|
$ext = IS_WIN ? "dll" : (IS_MAC ? "dylib" : "so");
|
|
|
|
return escapeshellarg(\PHP_BINARY)." -d zend_extension=xdebug.$ext";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function blackhole(bool $all = false): string {
|
|
|
|
$hole = IS_WIN ? "nul" : "/dev/null";
|
|
|
|
return $all ? ">$hole 2>&1" : "2>$hole";
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function runTests(string $executor, string $set, array $args) : Result {
|
|
|
|
switch ($set) {
|
|
|
|
case "typical":
|
|
|
|
$set = ["--exclude-group", "optional"];
|
|
|
|
break;
|
|
|
|
case "quick":
|
|
|
|
$set = ["--exclude-group", "optional,slow"];
|
|
|
|
break;
|
|
|
|
case "coverage":
|
|
|
|
$set = ["--exclude-group", "optional,coverageOptional"];
|
|
|
|
break;
|
|
|
|
case "full":
|
|
|
|
$set = [];
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
throw new \Exception;
|
|
|
|
}
|
|
|
|
$execpath = norm(BASE."vendor-bin/phpunit/vendor/phpunit/phpunit/phpunit");
|
|
|
|
$confpath = realpath(BASE_TEST."phpunit.dist.xml") ?: norm(BASE_TEST."phpunit.xml");
|
|
|
|
// clone the html5lib test suite if it's not already present
|
|
|
|
if (!is_dir(BASE_TEST."html5lib-tests")) {
|
|
|
|
$this->testUpdate();
|
|
|
|
}
|
|
|
|
return $this->taskExec($executor)->option("-d", "zend.assertions=1")->arg($execpath)->option("-c", $confpath)->args(array_merge($set, $args))->run();
|
|
|
|
}
|
|
|
|
}
|