Permalink
Browse files

Merge branch 'master' into fcgi

  • Loading branch information...
2 parents 7f647ae + b79d450 commit d26d66c889368dd01ea952d2ca6474c806f168f5 @mageekguy mageekguy committed Aug 16, 2012
View
@@ -26,11 +26,19 @@ public function __call($method, $arguments)
{
if (isset($this->methods[$method]) === false)
{
- throw new exceptions\runtime\unexpectedValue('Method \'' . $method . '\' is unavailable');
+ if (method_exists($this->script, $method) === false)
+ {
+ throw new exceptions\runtime\unexpectedValue('Method \'' . $method . '\' is unavailable');
+ }
+
+ call_user_func_array(array($this->script, $method), $arguments);
+
+ return $this;
}
else
{
$this->script->getArgumentsParser()->invokeHandlers($this->script, $this->methods[$method], $arguments);
+
return $this;
}
}
View
@@ -20,6 +20,7 @@ class runner extends atoum\script
protected $scoreFile = null;
protected $arguments = array();
protected $namespaces = array();
+ protected $testAllDirectories = array();
protected $tags = array();
protected $methods = array();
protected $loop = false;
@@ -91,6 +92,23 @@ public function setArguments(array $arguments)
return $this;
}
+ public function addTestAllDirectory($directory)
+ {
+ $directory = rtrim((string) $directory, DIRECTORY_SEPARATOR);
+
+ if (in_array($directory, $this->testAllDirectories) === false)
+ {
+ $this->testAllDirectories[] = $directory;
+ }
+
+ return $this;
+ }
+
+ public function getTestAllDirectories()
+ {
+ return $this->testAllDirectories;
+ }
+
public function run(array $arguments = array())
{
try
@@ -254,16 +272,21 @@ public function testMethod($class, $method)
return $this;
}
+ public static function autorunIsEnabled()
+ {
+ return (static::$autorunner !== null);
+ }
+
public static function enableAutorun($name)
{
- if (self::$autorunner !== null)
+ if (static::$autorunner !== null)
{
- throw new exceptions\runtime('Unable to autorun \'' . $name . '\' because \'' . self::$autorunner->getName() . '\' is already set as autorunner');
+ throw new exceptions\runtime('Unable to autorun \'' . $name . '\' because \'' . static::$autorunner->getName() . '\' is already set as autorunner');
}
- self::$autorunner = new static($name);
+ static::$autorunner = new static($name);
- $autorunner = & self::$autorunner;
+ $autorunner = & static::$autorunner;
register_shutdown_function(function() use (& $autorunner) {
if ($autorunner !== null)
@@ -280,7 +303,7 @@ public static function enableAutorun($name)
public static function disableAutorun()
{
- self::$autorunner = null;
+ static::$autorunner = null;
}
public static function getSubDirectoryPath($directory, $directorySeparator = null)
@@ -637,6 +660,24 @@ function($script, $argument, $values) {
)
->addArgumentHandler(
function($script, $argument, $values) {
+ if (sizeof($values) !== 0)
+ {
+ throw new exceptions\logic\invalidArgument(sprintf($script->getLocale()->_('Bad usage of %s, do php %s --help for more informations'), $argument, $script->getName()));
+ }
+
+ $runner = $script->getRunner();
+
+ foreach ($script->getTestAllDirectories() as $directory)
+ {
+ $runner->addTestsFromDirectory($directory);
+ }
+ },
+ array('--test-all'),
+ null,
+ $this->locale->_('Execute unit tests in directories defined via $script->addTestAllDirectory(\'path/to/directory\') in a configuration file')
+ )
+ ->addArgumentHandler(
+ function($script, $argument, $values) {
if ($values)
{
throw new exceptions\logic\invalidArgument(sprintf($script->getLocale()->_('Bad usage of %s, do php %s --help for more informations'), $argument, $script->getName()));
View
@@ -244,6 +244,13 @@ public function setAssertionManager(test\assertion\manager $assertionManager)
$this->assertionManager->setHandler('when', function($mixed) use ($assertionManager) { if (is_callable($mixed) === true) { call_user_func($mixed); } return $assertionManager; });
+ $mockControllerExtractor = function(mock\aggregator $mock) { return $mock->getMockController(); };
+
+ $this->assertionManager
+ ->setHandler('callOf', $mockControllerExtractor)
+ ->setHandler('ƒ', $mockControllerExtractor)
+ ;
+
$returnAssertionManager = function() use ($assertionManager) { return $assertionManager; };
$this->assertionManager
->setHandler('if', $returnAssertionManager)
@@ -252,6 +259,7 @@ public function setAssertionManager(test\assertion\manager $assertionManager)
->setHandler('given', $returnAssertionManager)
;
+
$test = $this;
$this->assertionManager
->setHandler('assert', function($case = null) use ($test) { $test->stopCase(); if ($case !== null) { $test->startCase($case); } return $test->getAssertionManager(); })
View
@@ -13,4 +13,7 @@
define(__NAMESPACE__ . '\scripts\runner', __FILE__);
}
-scripts\runner::enableAutorun(constant(__NAMESPACE__ . '\scripts\runner'));
+if (scripts\runner::autorunIsEnabled() === false)
+{
+ scripts\runner::enableAutorun(constant(__NAMESPACE__ . '\scripts\runner'));
+}
@@ -37,6 +37,8 @@ public function test__call()
->mock($runner)->call('setBootstrapFile')->withArguments($bootstrapFile)->once()
->object($configurator->bootstrapFile($bootstrapFile = uniqid()))->isIdenticalTo($configurator)
->mock($runner)->call('setBootstrapFile')->withArguments($bootstrapFile)->once()
+ ->object($configurator->setScoreFile($scoreFile = uniqid()))->isIdenticalTo($configurator)
+ ->mock($script)->call('setScoreFile')->withArguments($scoreFile)->once()
->exception(function() use ($configurator, & $method) { $configurator->{$method = uniqid()}(); })
->isInstanceOf('mageekguy\atoum\exceptions\runtime\unexpectedValue')
->hasMessage('Method \'' . $method . '\' is unavailable')
@@ -143,6 +143,11 @@ public function test__construct()
'Execute atoum unit tests'
),
array(
+ array('--test-all'),
+ null,
+ 'Execute unit tests in directories defined via $script->addTestAllDirectory(\'path/to/directory\') in a configuration file'
+ ),
+ array(
array('-ft', '--force-terminal'),
null,
'Force output as in terminal'
@@ -276,6 +281,11 @@ public function test__construct()
'Execute atoum unit tests'
),
array(
+ array('--test-all'),
+ null,
+ 'Execute unit tests in directories defined via $script->addTestAllDirectory(\'path/to/directory\') in a configuration file'
+ ),
+ array(
array('-ft', '--force-terminal'),
null,
'Force output as in terminal'
@@ -312,7 +322,7 @@ public function testUseConfigFile()
$this
->if($factory = new atoum\factory())
->and($factory['mageekguy\atoum\locale'] = $locale = new \mock\mageekguy\atoum\locale())
- ->and($runner = new scripts\runner($name = uniqid(), $factory))
+ ->and($runner = new scripts\runner(uniqid(), $factory))
->then
->exception(function() use ($runner, & $file) {
$runner->useConfigFile($file = uniqid());
@@ -333,7 +343,7 @@ public function testUseConfigFile()
public function testUseDefaultConfigFiles()
{
$this
- ->if($runner = new \mock\mageekguy\atoum\scripts\runner($name = uniqid()))
+ ->if($runner = new \mock\mageekguy\atoum\scripts\runner(uniqid()))
->and($runner->getMockController()->useConfigFile = function() {})
->then
->object($runner->useDefaultConfigFiles())->isIdenticalTo($runner)
@@ -345,6 +355,29 @@ public function testUseDefaultConfigFiles()
;
}
+ public function getTestAllDirectories()
+ {
+ $this
+ ->if($runner = new \mock\mageekguy\atoum\scripts\runner(uniqid()))
+ ->then
+ ->array($runner->getTestAllDirectories())->isEmpty()
+ ;
+ }
+
+ public function testAddTestAllDirectory()
+ {
+ $this
+ ->if($runner = new \mock\mageekguy\atoum\scripts\runner(uniqid()))
+ ->then
+ ->object($runner->addTestAllDirectory($directory = uniqid()))->isIdenticalTo($runner)
+ ->array($runner->getTestAllDirectories())->isEqualTo(array($directory))
+ ->object($runner->addtestalldirectory($directory))->isidenticalto($runner)
+ ->array($runner->gettestalldirectories())->isequalto(array($directory))
+ ->object($runner->addtestalldirectory(($otherDirectory = uniqid()) . DIRECTORY_SEPARATOR))->isidenticalto($runner)
+ ->array($runner->gettestalldirectories())->isequalto(array($directory, $otherDirectory))
+ ;
+ }
+
public function testGetSubDirectoryPath()
{
$this

0 comments on commit d26d66c

Please sign in to comment.