Exemplo n.º 1
0
 public function testHelp()
 {
     $this->if($argumentsParser = new mock\script\arguments\parser())->and($this->calling($argumentsParser)->addHandler = function () {
     })->and($locale = new mock\locale())->and($this->calling($locale)->_ = function ($string) {
         return $string;
     })->and($helpWriter = new mock\writers\std\out())->and($this->calling($helpWriter)->write = function () {
     })->and($script = new mock\script($name = uniqid()))->and($script->setArgumentsParser($argumentsParser))->and($script->setLocale($locale))->and($script->setHelpWriter($helpWriter))->then->object($script->help())->isIdenticalTo($script)->mock($helpWriter)->call('write')->never()->if($script->addArgumentHandler(function () {
     }, array('-c', '--c'), $valuesC = '<argumentC>', $helpC = 'help of C argument'))->then->object($script->help())->isIdenticalTo($script)->mock($locale)->call('_')->withArguments('Usage: %s [options]')->once()->mock($helpWriter)->call('write')->withArguments('Usage: ' . $script->getName() . ' [options]')->once()->withArguments('Available options are:')->once()->withArguments('   -c <argumentC>, --c <argumentC>: help of C argument')->once();
 }
Exemplo n.º 2
0
 public function testWriteError()
 {
     $this->if($locale = new mock\locale())->and($stderr = new mock\writers\std\err())->and($stderr->getMockCOntroller()->write = function () {
     })->and($script = new mock\script(uniqid()))->and($script->setErrorWriter($stderr))->and($script->setLocale($locale))->then->object($script->writeError($message = uniqid()))->isIdenticalTo($script)->mock($stderr)->call('write')->withIdenticalArguments('Error: ' . $message . PHP_EOL)->once()->mock($locale)->call('_')->withArguments('Error: %s')->once()->object($script->writeError(($message = uniqid()) . PHP_EOL))->isIdenticalTo($script)->mock($stderr)->call('write')->withIdenticalArguments('Error: ' . $message . PHP_EOL)->once()->mock($locale)->call('_')->withArguments('Error: %s')->exactly(2)->object($script->writeError(($message = uniqid()) . ' ' . PHP_EOL))->isIdenticalTo($script)->mock($stderr)->call('write')->withIdenticalArguments('Error: ' . $message . PHP_EOL)->once()->mock($locale)->call('_')->withArguments('Error: %s')->exactly(3)->object($script->writeError(' ' . ($message = uniqid()) . ' ' . PHP_EOL))->isIdenticalTo($script)->mock($stderr)->call('write')->withIdenticalArguments('Error: ' . $message . PHP_EOL)->once()->mock($locale)->call('_')->withArguments('Error: %s')->exactly(4);
 }