public function testTokenWithValueOf0DoesNotStopProcessing() { extract($this->generateArgvArgc("0 flag 25")); $o = CLImaxController::create(array(CLImaxController::OPT_RETURN_INSTEAD_OF_EXIT => true, CLImaxController::OPT_SLIENT => true))->addEnvironmentFlagWithExactlyOneArgument('foo', 'flag'); $res = $o->run($argv, $argc); $this->assertEquals(0, $res); $this->assertEquals(25, $o->getEnvironment('foo')); }
public function run($arguments, CLImaxController $cliController) { // argument checks if ($this->requiresArgument && count($arguments) === 0) { throw new CLImaxCommand_ArugumentException("Argument required."); } if (!$this->allowsMultipleArguments && count($arguments) > 1) { throw new CLImaxCommand_ArugumentException("Only one argument accepted."); } if (count($arguments) === 0 && $this->noArgumentValue) { $arguments = array($this->noArgumentValue); } if (!is_array($arguments)) { throw new Exception("Arguments should be an array but wasn't. Internal fail."); } if ($this->allowedValues) { $badArgs = array_diff($arguments, $this->allowedValues); if (count($badArgs) > 0) { throw new CLImaxCommand_ArugumentException("Invalid argument(s): " . join(', ', $badArgs)); } } // flatten argument to a single value as a convenience for working with the environment data later if (count($arguments) === 1) { $arguments = $arguments[0]; } $cliController->setEnvironment($this->environmentKey, $arguments); return 0; }