Skip to content

Commit

Permalink
add enabled() function and allow toggling verbose output with -v,…
Browse files Browse the repository at this point in the history
… `--verbose`
  • Loading branch information
mindplay-dk committed Oct 22, 2018
1 parent 421e757 commit 65fa9c4
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
19 changes: 17 additions & 2 deletions header.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand All @@ -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;
}

/**
Expand Down
6 changes: 5 additions & 1 deletion src/TestConfiguration.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -23,6 +23,10 @@ class TestConfiguration
public function __construct(TestDriver $driver = null)
{
$this->driver = $driver ?: $this->createDefaultDriver();

if (\enabled("verbose", "v")) {
$this->enableVerboseOutput();
}
}

/**
Expand Down
1 change: 0 additions & 1 deletion test/test.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 65fa9c4

Please sign in to comment.