Beispiel #1
0
 private function updateCommandDefinition(Command $command, OutputInterface $output)
 {
     $eventDispatcher = $this->getApplication()->getDispatcher();
     $input = new ArrayInput(['command' => $command->getName()]);
     $event = new ConsoleCommandEvent($command, $input, $output);
     $eventDispatcher->dispatch(GushEvents::DECORATE_DEFINITION, $event);
     $command->getSynopsis(true);
     $command->getSynopsis(false);
     $command->mergeApplicationDefinition();
     try {
         $input->bind($command->getDefinition());
     } catch (\Exception $e) {
         $output->writeln('<error>Something went wrong: </error>' . $e->getMessage());
         return;
     }
     $eventDispatcher->dispatch(GushEvents::INITIALIZE, $event);
     // The options were set on the input but now we need to set them on the Command definition
     if ($options = $input->getOptions()) {
         foreach ($options as $name => $value) {
             $option = $command->getDefinition()->getOption($name);
             if ($option->acceptValue()) {
                 $option->setDefault($value);
             }
         }
     }
 }
 /**
  * @expectedException InvalidArgumentException
  * @expectedExceptionMessage Invalid format for --custom-fact 'foobar'
  */
 public function testGetCustomFactsInvalid()
 {
     $mock = $this->getMockForAbstractClass('SugarCli\\Console\\Command\\Inventory\\AbstractInventoryCommand', array('test'));
     $input = new ArrayInput(array('--custom-fact' => array('foobar')));
     $input->bind($mock->getDefinition());
     $mock->getCustomFacts($input, '');
 }
 public function testGetConfig()
 {
     file_put_contents('box.json', '{}');
     $command = $this->app->get('test');
     $input = new ArrayInput(array());
     $input->bind($command->getDefinition());
     $this->assertInstanceOf('KevinGH\\Box\\Configuration', $this->callMethod($command, 'getConfig', array($input)));
 }
Beispiel #4
0
 protected function getInput(Command $command, array $arguments = [], array $options = [])
 {
     $input = new ArrayInput([]);
     $input->bind($command->getDefinition());
     foreach ($arguments as $key => $value) {
         $input->setArgument($key, $value);
     }
     foreach ($options as $key => $value) {
         $input->setOption($key, $value);
     }
     return $input;
 }
Beispiel #5
0
 protected function addCommandArray(array $args, OutputInterface $output)
 {
     $command = $this->getApplication()->find($args['command']);
     if ($command instanceof CompositeCommand) {
         unset($args['command']);
         $input = new ArrayInput($args);
         $input->bind($command->getDefinition());
         $command->initialize($input, $output);
     } else {
         $input = new ArrayInput($args);
         self::$commands[] = array('command' => $command, 'input' => $input);
     }
 }
Beispiel #6
0
 public function testValidate()
 {
     $input = new ArrayInput(array());
     $input->bind(new InputDefinition(array(new InputArgument('name', InputArgument::REQUIRED))));
     try {
         $input->validate();
         $this->fail('->validate() throws a \\RuntimeException if not enough arguments are given');
     } catch (\Exception $e) {
         $this->assertInstanceOf('\\RuntimeException', $e, '->validate() throws a \\RuntimeException if not enough arguments are given');
         $this->assertEquals('Not enough arguments.', $e->getMessage());
     }
     $input = new ArrayInput(array('name' => 'foo'));
     $input->bind(new InputDefinition(array(new InputArgument('name', InputArgument::REQUIRED))));
     try {
         $input->validate();
     } catch (\RuntimeException $e) {
         $this->fail('->validate() does not throw a \\RuntimeException if enough arguments are given');
     }
 }
 public function testValidate()
 {
     $input = new ArrayInput(array('name' => 'foo'));
     $input->bind(new InputDefinition(array(new InputArgument('name', InputArgument::REQUIRED))));
     $this->assertNull($input->validate());
 }
Beispiel #8
0
 /**
  * buildInput.
  *
  * @param $array
  *
  * @return InputInterface
  */
 protected function buildInput($array)
 {
     $input = new ArrayInput($array);
     $input->bind((new LicenserCommand())->getDefinition());
     return $input;
 }
Beispiel #9
0
 /**
  * @covers                   ::getConfiguration
  * @expectedException        InvalidArgumentException
  * @expectedExceptionMessage The configuration file "foo.bar" could not be found.
  */
 public function testGetConfigurationFileDoesNotExist()
 {
     $mock = $this->getMockBuilder('MaartenStaa\\PHPTA\\CLI\\Command')->setMethods(array('getFilesystem'))->getMock();
     $fs = $this->getMockBuilder('Illuminate\\Filesystem\\Filesystem')->setMethods(array('isFile'))->getMock();
     $mock->expects($this->once())->method('getFilesystem')->will($this->returnValue($fs));
     $fs->expects($this->once())->method('isFile')->with('foo.bar')->will($this->returnValue(false));
     $input = new ArrayInput(array());
     $input->bind($mock->getDefinition());
     $input->setOption('config', 'foo.bar');
     $output = new StreamOutput(fopen('php://memory', 'w', false));
     $mock->getConfiguration($input, $output);
 }