Skip to content
Browse files

Improve configurator.

Now use factory to construct configurator.
Configurator just handle script argument.
Rules of argument to method translation are now for all arguments :
1) remove trailing '-' ;
2) replace /-(.)/ by /\u\1/ ;
It's now possible to handle script argument in a config file with
$script.
The variable $runner in a config file is now the runner, and not the
configurator.
  • Loading branch information...
1 parent b2736b5 commit 328a139a43435e31142a88a6df8f64806a4ae0be @mageekguy committed Feb 29, 2012
Showing with 18 additions and 31 deletions.
  1. +8 −25 classes/configurator.php
  2. +3 −2 classes/scripts/runner.php
  3. +7 −4 tests/units/classes/configurator.php
View
33 classes/configurator.php
@@ -17,38 +17,21 @@ public function __construct(scripts\runner $script)
foreach ($arguments as $argument)
{
- $methodName = preg_replace('/-(.)/e', 'ucfirst(\'\1\')', ltrim($argument, '-'));
-
- if ($values === null)
- {
- $this->methods[$methodName] = $argument;
- }
- else
- {
- $this->methods['set' . ucfirst($methodName)] = $argument;
- }
+ $this->methods[preg_replace('/-(.)/e', 'ucfirst(\'\1\')', ltrim($argument, '-'))] = $argument;
}
}
}
public function __call($method, $arguments)
{
- switch (true)
+ if (isset($this->methods[$method]) === false)
{
- case isset($this->methods[$method]):
- $this->script->getArgumentsParser()->invokeHandlers($this->script, $this->methods[$method], $arguments);
- return $this;
-
- case method_exists($this->script->getRunner(), $method):
- call_user_func_array(array($this->script->getRunner(), $method), $arguments);
- return $this;
-
- case method_exists($this->script, $method):
- call_user_func_array(array($this->script, $method), $arguments);
- return $this;
-
- default:
- throw new exceptions\runtime\unexpectedValue('Method \'' . $method . '\' is unavailable');
+ throw new exceptions\runtime\unexpectedValue('Method \'' . $method . '\' is unavailable');
+ }
+ else
+ {
+ $this->script->getArgumentsParser()->invokeHandlers($this->script, $this->methods[$method], $arguments);
+ return $this;
}
}
View
5 classes/scripts/runner.php
@@ -167,11 +167,12 @@ public function help()
public function useConfigFile($path)
{
- $runner = new atoum\configurator($this);
+ $script = $this->factory->build('atoum\configurator', array($this));
+ $runner = $this->runner;
try
{
- $this->includer->includePath($path, function($path) use ($runner) { include_once($path); });
+ $this->includer->includePath($path, function($path) use ($script, $runner) { include_once($path); });
}
catch (atoum\includer\exception $exception)
{
View
11 tests/units/classes/configurator.php
@@ -35,15 +35,18 @@ public function test__call()
->and($script->setRunner($runner))
->and($configurator = new atoum\configurator($script))
->then
- ->object($configurator->setScoreFile($scoreFile = uniqid()))->isIdenticalTo($configurator)
+ ->object($configurator->scoreFile($scoreFile = uniqid()))->isIdenticalTo($configurator)
->mock($script)->call('setScoreFile')->withArguments($scoreFile)->once()
- ->object($configurator->setPhpPath($phpPath = uniqid()))->isIdenticalTo($configurator)
- ->mock($runner)->call('setPhpPath')->withArguments($phpPath)->once()
- ->object($configurator->setBf($bootstrapFile = uniqid()))->isIdenticalTo($configurator)
+ ->object($configurator->bf($bootstrapFile = uniqid()))->isIdenticalTo($configurator)
+ ->mock($runner)->call('setBootstrapFile')->withArguments($bootstrapFile)->once()
+ ->object($configurator->bootstrapFile($bootstrapFile = uniqid()))->isIdenticalTo($configurator)
->mock($runner)->call('setBootstrapFile')->withArguments($bootstrapFile)->once()
->exception(function() use ($configurator, & $method) { $configurator->{$method = uniqid()}(); })
->isInstanceOf('mageekguy\atoum\exceptions\runtime\unexpectedValue')
->hasMessage('Method \'' . $method . '\' is unavailable')
+ ->exception(function() use ($configurator) { $configurator->setPhpPath(uniqid()); })
+ ->isInstanceOf('mageekguy\atoum\exceptions\runtime\unexpectedValue')
+ ->hasMessage('Method \'setPhpPath\' is unavailable')
;
}
}

0 comments on commit 328a139

Please sign in to comment.
Something went wrong with that request. Please try again.