From 65fa9c47c2fc44457b2acecc6632b8dbf1f3b0ab Mon Sep 17 00:00:00 2001 From: Rasmus Schultz Date: Mon, 22 Oct 2018 11:30:33 +0200 Subject: [PATCH] add `enabled()` function and allow toggling verbose output with `-v`, `--verbose` --- header.php | 19 +++++++++++++++++-- src/TestConfiguration.php | 6 +++++- test/test.php | 1 - 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/header.php b/header.php index 5fd38a4..2d33967 100644 --- a/header.php +++ b/header.php @@ -20,6 +20,21 @@ function configure($config = null) return $active; } +/** + * Tests if a given option is enabled on the command-line. + * + * For example, `if (enabled('skip-slow'))` checks for a `--skip-slow` option. + * + * @param string $option option name + * @param string $shorthand single-letter shorthand (optional) + * + * @return bool TRUE, if the specified option was enabled on the command-line + */ +function enabled($option, $shorthand = "") +{ + return in_array(getopt($shorthand, [$option]), [[$option => false], [$shorthand => false]], true); +} + /** * Run all queued tests. * @@ -31,9 +46,9 @@ function configure($config = null) */ function run() { - $status = configure()->driver->run(); + $success = configure()->driver->run(); - return $status ? 0 : 1; + return $success ? 0 : 1; } /** diff --git a/src/TestConfiguration.php b/src/TestConfiguration.php index aa18f8e..0ed9b4b 100644 --- a/src/TestConfiguration.php +++ b/src/TestConfiguration.php @@ -2,8 +2,8 @@ namespace mindplay\testies; -use PHP_CodeCoverage_Exception; use PHP_CodeCoverage; +use PHP_CodeCoverage_Exception; /** * This class creates and configures the test-driver. @@ -23,6 +23,10 @@ class TestConfiguration public function __construct(TestDriver $driver = null) { $this->driver = $driver ?: $this->createDefaultDriver(); + + if (\enabled("verbose", "v")) { + $this->enableVerboseOutput(); + } } /** diff --git a/test/test.php b/test/test.php index 58578bc..1b64a72 100644 --- a/test/test.php +++ b/test/test.php @@ -5,7 +5,6 @@ require dirname(__DIR__) . '/vendor/autoload.php'; -configure()->enableVerboseOutput(); #configure()->enableCodeCoverage(__DIR__ . '/build/clover.xml', dirname(__DIR__) . '/src'); $server = new TestServer(__DIR__, 8088);