Browse Source

Update tooling

master
J. King 1 year ago
parent
commit
738509c3da
  1. 94
      RoboFile.php
  2. 10
      composer.json
  3. 2
      composer.lock
  4. 6
      robo
  5. 4
      robo.bat
  6. 10
      tests/phpunit.dist.xml
  7. 13
      vendor-bin/phpunit/composer.lock

94
RoboFile.php

@ -1,8 +1,4 @@
<?php
/** @license MIT
* Copyright 2017 , Dustin Wilson, J. King et al.
* See LICENSE and AUTHORS files for details */
use Robo\Result;
@ -10,6 +6,7 @@ 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");
define("IS_LINUX", !IS_WIN && !IS_MAC);
error_reporting(0);
function norm(string $path): string {
@ -26,10 +23,10 @@ class RoboFile extends \Robo\Tasks {
* 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
* ./robo test --testsuite TTRSS --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);
}
@ -38,7 +35,7 @@ class RoboFile extends \Robo\Tasks {
*
* 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);
}
@ -47,35 +44,21 @@ class RoboFile extends \Robo\Tasks {
* 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 {
$repos = [
'platform-tests' => "https://github.com/web-platform-tests/wpt",
];
$c = $this->collectionBuilder();
foreach ($repos as $dir => $url) {
$dir = BASE_TEST.$dir;
if (is_dir($dir)) {
$c->addTask($this->taskGitStack()->dir($dir)->pull());
} else {
$c->addTask($this->taskGitStack()->cloneRepo($url, $dir));
}
}
$c->addTask($this->taskExec(BASE_TEST."parsetests")->arg(BASE_TEST."platform-tests")->rawArg(">")->arg(BASE_TEST."cases".DIRECTORY_SEPARATOR."std-sanitize.json"));
return $c->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.
*/
*
* Robo first tries to use pcov and will fall back to xdebug.
* Neither pcov nor xdebug need to be enabled to be used; they
* only need to be present in the extension load path to be used.
*/
public function coverage(array $args): Result {
// run tests with code coverage reporting enabled
$exec = $this->findCoverageEngine();
@ -90,47 +73,48 @@ class RoboFile extends \Robo\Tasks {
* 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));
}
/** Finds the first suitable means of computing code coverage, either pcov or xdebug. */
protected function findCoverageEngine(): string {
$dir = rtrim(ini_get("extension_dir"), "/").\DIRECTORY_SEPARATOR;
$ext = IS_WIN ? "dll" : "so";
$php = escapeshellarg(\PHP_BINARY);
$code = escapeshellarg(BASE."lib");
if (extension_loaded("pcov")) {
return "$php -d opcache.enable_cli=0 -d pcov.enabled=1 -d pcov.directory=$code";
return "$php -d pcov.enabled=1 -d pcov.directory=$code";
} elseif (extension_loaded("xdebug")) {
return "$php -d opcache.enable_cli=0 -d xdebug.mode=coverage";
return "$php -d xdebug.mode=coverage";
} elseif (file_exists($dir."pcov.$ext")) {
return "$php -d opcache.enable_cli=0 -d extension=pcov.$ext -d pcov.enabled=1 -d pcov.directory=$code";
return "$php -d extension=pcov.$ext -d pcov.enabled=1 -d pcov.directory=$code";
} elseif (file_exists($dir."xdebug.$ext")) {
return "$php -d opcache.enable_cli=0 -d zend_extension=xdebug.$ext -d xdebug.mode=coverage";
return "$php -d zend_extension=xdebug.$ext -d xdebug.mode=coverage";
} else {
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 {
return $php;
}
return $php;
}
}
/** Returns the necessary shell arguments to print error output or all output to the bitbucket
*
* @param bool $all Whether all output (true) or only error output (false) should be suppressed
*/
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 {
/** Executes PHPUnit, used by the test and coverage tasks.
*
* @param string $executor The path to the PHP binary to execute with any required extra arguments. Normally this is either "php" or the result of findCoverageEngine()
* @param string $set The set of tests to run, either "typical" (excludes redundant tests), "quick" (excludes redundant and slow tests), "coverage" (excludes tests not needed for coverage), or "full" (all tests)
* @param array $args Extra arguments passed by Robo from the command line
*/
protected function runTests(string $executor, string $set, array $args): Result {
switch ($set) {
case "typical":
$set = ["--exclude-group", "optional"];
@ -149,10 +133,24 @@ class RoboFile extends \Robo\Tasks {
}
$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();
}
/** Manually updates the imported web-platform-tests test suite */
public function testUpdate(): Result {
$repos = [
'platform-tests' => "https://github.com/web-platform-tests/wpt",
];
$c = $this->collectionBuilder();
foreach ($repos as $dir => $url) {
$dir = BASE_TEST.$dir;
if (is_dir($dir)) {
$c->addTask($this->taskGitStack()->dir($dir)->pull());
} else {
$c->addTask($this->taskGitStack()->cloneRepo($url, $dir));
}
}
$c->addTask($this->taskExec(BASE_TEST."parsetests")->arg(BASE_TEST."platform-tests")->rawArg(">")->arg(BASE_TEST."cases".DIRECTORY_SEPARATOR."std-sanitize.json"));
return $c->run();
}
}

10
composer.json

@ -9,10 +9,6 @@
},
"suggest": {
},
"scripts": {
"post-install-cmd": ["@composer bin all install"],
"post-update-cmd": ["@composer bin all update"]
},
"license": "MIT",
"authors": [
{
@ -41,5 +37,11 @@
"allow-plugins": {
"bamarni/composer-bin-plugin": true
}
},
"extra": {
"bamarni-bin": {
"bin-links": false,
"forward-command": true
}
}
}

2
composer.lock

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "c630a2bcd0a5436e132c6a584f0de742",
"content-hash": "ca1817f63eaf25e350da3b69bae122a0",
"packages": [],
"packages-dev": [
{

6
robo

@ -2,13 +2,13 @@
base=`dirname "$0"`
roboCommand="$1"
if [ $# -eq 0 ]; then
"$base/vendor/bin/robo"
"$base/vendor-bin/robo/vendor/bin/robo"
else
shift
ulimit -n 2048
if [ "$1" = "clean" ]; then
"$base/vendor/bin/robo" "$roboCommand" "$@"
"$base/vendor-bin/robo/vendor/bin/robo" "$roboCommand" "$@"
else
"$base/vendor/bin/robo" "$roboCommand" -- "$@"
"$base/vendor-bin/robo/vendor/bin/robo" "$roboCommand" -- "$@"
fi
fi

4
robo.bat

@ -15,7 +15,7 @@ if "%~1" neq "" (
if defined args set args=%args:~1%
if "%1"=="clean" (
call "%base%vendor\bin\robo" "%roboCommand%" %args%
call "%base%vendor-bin\robo\vendor\bin\robo" "%roboCommand%" %args%
) else (
call "%base%vendor\bin\robo" "%roboCommand%" -- %args%
call "%base%vendor-bin\robo\vendor\bin\robo" "%roboCommand%" -- %args%
)

10
tests/phpunit.dist.xml

@ -1,5 +1,7 @@
<?xml version="1.0"?>
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd"
colors="true"
bootstrap="bootstrap.php"
convertErrorsToExceptions="false"
@ -9,11 +11,11 @@
forceCoversAnnotation="true"
>
<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<coverage processUncoveredFiles="true">
<include>
<directory suffix=".php">../lib</directory>
</whitelist>
</filter>
</include>
</coverage>
<testsuites>
<testsuite name="Charset">

13
vendor-bin/phpunit/composer.lock

@ -622,16 +622,16 @@
},
{
"name": "phpunit/phpunit",
"version": "9.6.5",
"version": "9.6.6",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/phpunit.git",
"reference": "86e761949019ae83f49240b2f2123fb5ab3b2fc5"
"reference": "b65d59a059d3004a040c16a82e07bbdf6cfdd115"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/86e761949019ae83f49240b2f2123fb5ab3b2fc5",
"reference": "86e761949019ae83f49240b2f2123fb5ab3b2fc5",
"url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/b65d59a059d3004a040c16a82e07bbdf6cfdd115",
"reference": "b65d59a059d3004a040c16a82e07bbdf6cfdd115",
"shasum": ""
},
"require": {
@ -704,7 +704,8 @@
],
"support": {
"issues": "https://github.com/sebastianbergmann/phpunit/issues",
"source": "https://github.com/sebastianbergmann/phpunit/tree/9.6.5"
"security": "https://github.com/sebastianbergmann/phpunit/security/policy",
"source": "https://github.com/sebastianbergmann/phpunit/tree/9.6.6"
},
"funding": [
{
@ -720,7 +721,7 @@
"type": "tidelift"
}
],
"time": "2023-03-09T06:34:10+00:00"
"time": "2023-03-27T11:43:46+00:00"
},
{
"name": "sebastian/cli-parser",

Loading…
Cancel
Save