dox Executable Documentation

Run command

Non existing command

When try to I run the command 'nonExisting'
Then there should be an error containing 'Command [nonExisting] not found. Use \'help\' to list available commands.'

Without args

Given the command 'CommandWithoutArgs' with the body ' function doExecute() { $this->executed = true; } '
When I run the command 'CommandWithoutArgs'
Then 'executed' should be true

With arguments

Given the command 'CommandWithArguments' with the body ' /** * @param int $one * @param bool $two * @param \\DateTime $three */ function doExecute($one, $two, $three) { $this->one = $one; $this->two = $two; $this->three = $three; } '
When I run the command 'CommandWithArguments' with the arguments array('12', 'false', '2001-02-13 11:12')
Then 'one' should be exactly 12
Then 'two' should be exactly false
Then 'three' should be new \DateTime('2001-02-13 11:12')

Optional arguments

Given the command 'OptionalArguments' with the body ' function doExecute($one, $two = false, $three = "tres") { $this->one = $one; $this->two = $two; $this->three = $three; } '
When I run the command 'OptionalArguments' with the arguments array('uno', 'dos')
Then 'one' should be exactly 'uno'
Then 'two' should be exactly 'dos'
Then 'three' should be exactly 'tres'

Regular options

Given the command 'RegularOptions' with the body ' function doExecute($one, $two) { $this->one = $one; $this->two = $two; } '
When I run the command 'RegularOptions' with the arguments array('--one=uno', '--two=dos')
Then 'one' should be exactly 'uno'
Then 'two' should be exactly 'dos'

Options mixed with arguments

Given the command 'OptionsMixedWithArguments' with the body ' function doExecute($one, $two) { $this->one = $one; $this->two = $two; } '
When I run the command 'OptionsMixedWithArguments' with the arguments array('--two=dos', 'eins', 'zwei')
Then 'one' should be exactly 'eins'
Then 'two' should be exactly 'dos'

Long argument

Given the command 'CollectingOption' with the body ' function doExecute($one, $two) { $this->one = $one; $this->two = $two; } '
When I run the command 'CollectingOption' with the arguments array('uno', '--', 'a', 'long', 'argument')
Then 'one' should be exactly 'uno'
Then 'two' should be exactly 'a long argument'

Array option

Given the command 'ArrayOption' with the body ' function doExecute($one) { $this->one = $one; } '
When I run the command 'ArrayOption' with the arguments array('--one=uno', '--one=eins')
Then 'one' should be array('uno', 'eins')

Short options

Given the command 'ShortOptions' with the body ' /** * @param $one [o] * @param string $two [w] * @param boolean $three [t] */ function doExecute($one, $two, $three) { $this->one = $one; $this->two = $two; $this->three = $three; } '
When I run the command 'ShortOptions' with the arguments array('-o=uno', '-tw=dos')
Then 'one' should be 'uno'
Then 'two' should be 'dos'
Then 'three' should be true

Options without equal sign

Given the command 'OptionsWithoutEqualSign' with the body ' /** * @param $one [o] * @param $two [w] * @param $three [t] */ function doExecute($one, $two, $three) { $this->one = $one; $this->two = $two; $this->three = $three; } '
When I run the command 'OptionsWithoutEqualSign' with the arguments array('-t', 'tres', '--two', 'dos', 'uno')
Then 'one' should be 'uno'
Then 'two' should be 'dos'
Then 'three' should be 'tres'

Inject console

Given the command 'InjectConsole' with the body ' function doExecute($one, \\watoki\\cli\\Console $console) { $this->executed = $one; $console->out->writeLine("Hello World"); } '
When I run the command 'InjectConsole' with the arguments array('yes')
Then 'executed' should be 'yes'
Then the output should be 'Hello World'

Invalid option

Given the command 'InvalidOption' with the body ' function doExecute($one) {} '
When try to I run the command 'InvalidOption' with the arguments array('--one', 'uno', '--two', 'dos')
Then there should be an error containing 'Invalid option: two'

Invalid argument

Given the command 'InvalidArgument' with the body ' function doExecute($one) {} '
When try to I run the command 'InvalidArgument' with the arguments array('--one', 'uno', 'arg1', 'arg2')
Then there should be an error containing 'Too many arguments: maximum 1, given 2'