public function createStringInput($testCommandline)
 {
     $input = new StringInput($testCommandline);
     $optionDefinitions = [new InputArgument('unused', InputArgument::REQUIRED), new InputOption(FormatterOptions::FORMAT, null, InputOption::VALUE_REQUIRED), new InputOption(FormatterOptions::TABLE_STYLE, null, InputOption::VALUE_REQUIRED), new InputOption(FormatterOptions::FIELD, null, InputOption::VALUE_REQUIRED), new InputOption(FormatterOptions::FIELDS, null, InputOption::VALUE_REQUIRED), new InputOption(FormatterOptions::INCLUDE_FIELD_LABELS, null, InputOption::VALUE_NONE), new InputOption(FormatterOptions::ROW_LABELS, null, InputOption::VALUE_REQUIRED), new InputOption(FormatterOptions::FIELD_LABELS, null, InputOption::VALUE_REQUIRED), new InputOption(FormatterOptions::DEFAULT_FORMAT, null, InputOption::VALUE_REQUIRED), new InputOption(FormatterOptions::DEFAULT_FIELDS, null, InputOption::VALUE_REQUIRED), new InputOption(FormatterOptions::LIST_ORIENTATION, null, InputOption::VALUE_NONE)];
     $definition = new InputDefinition($optionDefinitions);
     $input->bind($definition);
     return $input;
 }
 public function testInputOptionWithGivenString()
 {
     $definition = new InputDefinition(array(new InputOption('foo', null, InputOption::VALUE_REQUIRED)));
     // call to bind
     $input = new StringInput('--foo=bar');
     $input->bind($definition);
     $this->assertEquals('bar', $input->getOption('foo'));
 }
 public function testGetCustomFacts()
 {
     $mock = $this->getMockForAbstractClass('SugarCli\\Console\\Command\\Inventory\\AbstractInventoryCommand', array('test'));
     $input = new StringInput('--custom-fact="foo:bar" --custom-fact "baz.foo:bar" --custom-fact "baz.test:a"');
     $input->bind($mock->getDefinition());
     $expected = 'bar';
     $this->assertEquals($expected, $mock->getCustomFacts($input, 'foo'));
     $expected = array('foo' => 'bar', 'test' => 'a');
     $this->assertEquals($expected, $mock->getCustomFacts($input, 'baz'));
     $this->assertEquals(array(), $mock->getCustomFacts($input, 'test'));
 }
예제 #4
0
 private function configure(InputInterface $input)
 {
     preg_match_all('/(\\-\\-skip\\-[a-zA-Z0-9\\.\\-\\/=\\"\']+)/', (string) $input, $matches);
     $stringInput = new StringInput(implode(' ', $matches[0]));
     $stringInput->bind($this->getDefinition());
     extract(Environment::getVars($stringInput));
     $app = new Generic($app_path, $lib_path, $env, $user, 'console', $this->cacheConfig);
     $config = $app->getConfig();
     // add helper sets
     if (isset($config['console']['helpers']) && is_array($config['console']['helpers'])) {
         $set_array = array();
         foreach ($config['console']['helpers'] as $name => $helper) {
             $helper = new $helper();
             $set_array[$name] = $helper->getHelper($app, $this);
         }
         $helperSet = new \Symfony\Component\Console\Helper\HelperSet($set_array);
         $this->setHelperSet($helperSet);
     }
     // add commands
     if (isset($config['console']['commands']) && is_array($config['console']['commands'])) {
         foreach ($config['console']['commands'] as $command) {
             $sets = array();
             if (!is_string($command)) {
                 if (!isset($command['class'])) {
                     throw new \Exception('Commands with extra configuration needs a `class` parameter. No class parameter found.');
                 }
                 $sets = isset($command['set']) ? $command['set'] : $sets;
                 if (!is_array($sets)) {
                     throw new \Exception('Commands with a `sets` parameter must be a hash array of paramerter => service, where parameter is the un-camelised key paramerter and service is the key identifier of the dependant service.');
                 }
                 $command = $command['class'];
             }
             $command = new $command();
             Utils::setParametersOn($command, $sets, $app);
             if ($command instanceof \Skip\ServiceContainerInterface) {
                 $command->setContainer($app);
             }
             $this->add($command);
         }
     }
     $this->app = $app;
 }
예제 #5
0
 /**
  * @dataProvider inputProvider
  * @param string $stringInput
  * @param string $expectedIdeKey
  */
 public function testShouldGetIdeKeyFromCommandOptionOnCommandInitialization($stringInput, $expectedIdeKey)
 {
     $this->mockXdebugExtension($isExtensionLoaded = true, $isRemoteEnabled = true);
     $command = new RunCommand(new EventDispatcher());
     $input = new StringInput($stringInput);
     $output = new BufferedOutput();
     $output->setVerbosity(OutputInterface::VERBOSITY_DEBUG);
     // Trigger event to add the xdebug option to the command and bind the definition to the input
     $this->listener->onCommandConfigure(new BasicConsoleEvent($command));
     $input->bind($command->getDefinition());
     // Trigger command initialization event
     $event = new ExtendedConsoleEvent($command, $input, $output);
     $this->listener->onCommandRunTestsInit($event);
     if ($expectedIdeKey !== null) {
         $this->assertContains('Xdebug remote debugging initialized with IDE key: ' . $expectedIdeKey, $output->fetch());
     } else {
         // no output expected (xdebug not triggered)
         $this->assertEmpty($output->fetch());
     }
 }
 protected function bindSignature()
 {
     $signatureParts = new SignatureParts($this->signature);
     $signature = $signatureParts->getSignatureWithoutCommandName();
     list($name, $arguments, $options) = Parser::parse($signature);
     $this->name = $name;
     $inputDefinition = new InputDefinition();
     foreach ($arguments as $argument) {
         $inputDefinition->addArgument($argument);
     }
     foreach ($options as $option) {
         $inputDefinition->addOption($option);
     }
     $inputWithoutHandlerName = explode(' ', $this->request->text, 2)[1] ?? '';
     $this->input = new StringInput($inputWithoutHandlerName);
     $this->inputDefinition = $inputDefinition;
     try {
         $this->input->bind($inputDefinition);
     } catch (RuntimeException $exception) {
         return false;
     }
     return true;
 }
 function testInteractAndValidate()
 {
     $this->commandFileInstance = new \Consolidation\TestUtils\ExampleCommandFile();
     $this->commandFactory = new AnnotatedCommandFactory();
     $hookInfo = $this->commandFactory->createCommandInfo($this->commandFileInstance, 'interactTestHello');
     $this->assertTrue($hookInfo->hasAnnotation('hook'));
     $this->assertEquals($hookInfo->getAnnotation('hook'), 'interact test:hello');
     $this->commandFactory->registerCommandHook($hookInfo, $this->commandFileInstance);
     $hookInfo = $this->commandFactory->createCommandInfo($this->commandFileInstance, 'validateTestHello');
     $this->assertTrue($hookInfo->hasAnnotation('hook'));
     $this->assertEquals($hookInfo->getAnnotation('hook'), 'validate test:hello');
     $this->commandFactory->registerCommandHook($hookInfo, $this->commandFileInstance);
     $hookCallback = $this->commandFactory->hookManager()->get('test:hello', [HookManager::ARGUMENT_VALIDATOR]);
     $this->assertTrue($hookCallback != null);
     $this->assertEquals(1, count($hookCallback));
     $this->assertEquals(2, count($hookCallback[0]));
     $this->assertTrue(is_callable($hookCallback[0]));
     $this->assertEquals('validateTestHello', $hookCallback[0][1]);
     $hookCallback = $this->commandFactory->hookManager()->get('test:hello', [HookManager::INTERACT]);
     $this->assertTrue($hookCallback != null);
     $this->assertEquals(1, count($hookCallback));
     $this->assertEquals(2, count($hookCallback[0]));
     $this->assertTrue(is_callable($hookCallback[0]));
     $this->assertEquals('interactTestHello', $hookCallback[0][1]);
     $commandInfo = $this->commandFactory->createCommandInfo($this->commandFileInstance, 'testHello');
     $command = $this->commandFactory->createCommand($commandInfo, $this->commandFileInstance);
     $this->assertInstanceOf('\\Symfony\\Component\\Console\\Command\\Command', $command);
     $this->assertEquals('test:hello', $command->getName());
     $commandGetNames = $this->callProtected($command, 'getNames');
     $this->assertEquals('test:hello,Consolidation\\TestUtils\\ExampleCommandFile', implode(',', $commandGetNames));
     $testInteractInput = new StringInput('test:hello');
     $definition = new \Symfony\Component\Console\Input\InputDefinition([new \Symfony\Component\Console\Input\InputArgument('application', \Symfony\Component\Console\Input\InputArgument::REQUIRED), new \Symfony\Component\Console\Input\InputArgument('who', \Symfony\Component\Console\Input\InputArgument::REQUIRED)]);
     $testInteractInput->bind($definition);
     $testInteractOutput = new BufferedOutput();
     $command->commandProcessor()->interact($testInteractInput, $testInteractOutput, $commandGetNames, $command->getAnnotationData());
     $this->assertEquals('Goofey', $testInteractInput->getArgument('who'));
     $hookCallback = $command->commandProcessor()->hookManager()->get('test:hello', 'interact');
     $this->assertTrue($hookCallback != null);
     $this->assertEquals('interactTestHello', $hookCallback[0][1]);
     $input = new StringInput('test:hello "Mickey Mouse"');
     $this->assertRunCommandViaApplicationEquals($command, $input, 'Hello, Mickey Mouse.');
     $input = new StringInput('test:hello');
     $this->assertRunCommandViaApplicationEquals($command, $input, 'Hello, Goofey.');
     $input = new StringInput('test:hello "Donald Duck"');
     $this->assertRunCommandViaApplicationEquals($command, $input, "I won't say hello to Donald Duck.", 1);
     $input = new StringInput('test:hello "Drumph"');
     $this->assertRunCommandViaApplicationEquals($command, $input, "Irrational value error.", 1);
     // Try the last test again with a display error function installed.
     $this->commandFactory->commandProcessor()->setDisplayErrorFunction(function ($output, $message) {
         $output->writeln("*** {$message} ****");
     });
     $input = new StringInput('test:hello "Drumph"');
     $this->assertRunCommandViaApplicationEquals($command, $input, "*** Irrational value error. ****", 1);
 }
             $runner = $this->command->getRunner();
             expect($loader)->to->be->an->instanceof('Peridot\\Concurrency\\SuiteLoader');
             expect($runner)->to->be->an->instanceof('Peridot\\Concurrency\\Runner\\StreamSelect\\StreamSelectRunner');
         });
         it('should set the reporter to the concurrency reporter', function () {
             $reporter = $this->configuration->getReporter();
             expect($reporter)->to->equal('concurrent');
         });
         it('should set configured processes on the concurrency config', function () {
             $configuration = $this->plugin->getConfiguration();
             expect($configuration->getProcesses())->to->equal(4);
         });
     });
     it('should not set the suite loader and runner if concurrent options is not set', function () {
         $input = new StringInput('');
         $input->bind($this->definition);
         $this->emitter->emit('peridot.execute', [$input]);
         $this->emitter->emit('peridot.load', [$this->command, $this->configuration]);
         $loader = $this->command->getLoader();
         $runner = $this->command->getRunner();
         expect($loader)->to->be->an->instanceof('Peridot\\Runner\\SuiteLoader');
         expect($runner)->to->be->an->instanceof('Peridot\\Runner\\Runner');
     });
 });
 context('when peridot.configure event is fired', function () use($configure) {
     beforeEach($configure);
     it('should store references to the configuration and application objects', function () {
         expect($this->plugin->getConfiguration())->to->be->an->instanceof('Peridot\\Concurrency\\Configuration');
         expect($this->plugin->getApplication())->to->equal($this->app->reveal());
     });
 });
 /**
  * test getAppPath Method
  * @expectedException Skip\Util\Exception\AppPathNotFoundException
  */
 public function testGetAppPath()
 {
     @rmdir("./app");
     @mkdir("./app");
     $path = Environment::getAppPath();
     $this->assertEquals($this->rootPath . "/app", $path);
     @rmdir("./app");
     @rmdir("./app");
     @mkdir("./app");
     $cliInput = new StringInput('--skip-app-path=./app');
     $cliInput->bind($this->cliInputDefinition);
     $path = Environment::getAppPath($cliInput);
     $this->assertEquals($this->rootPath . "/app", $path);
     @rmdir("./app");
     @rmdir("./appPathTest");
     @mkdir("./appPathTest");
     putenv("SKIP_APP_PATH=appPathTest");
     $path = Environment::getAppPath();
     $this->assertEquals($this->rootPath . "/appPathTest", $path);
     @rmdir("./appPathTest");
     $config = Environment::getAppPath();
 }
    function testSimpleList()
    {
        $expected = <<<EOT
 ------- --------
  One     apple
  Two     banana
  Three   carrot
 ------- --------
EOT;
        $data = $this->simpleListExampleDataUsingAssociativeList();
        $this->assertFormattedOutputMatches($expected, 'table', $data);
        $data = $this->simpleListExampleData();
        $this->assertFormattedOutputMatches($expected, 'table', $data);
        $expected = <<<EOT
 ----- --------
  I     apple
  II    banana
  III   carrot
 ----- --------
EOT;
        // If we provide field labels, then the output will change to reflect that.
        $formatterOptionsWithFieldLables = new FormatterOptions();
        $formatterOptionsWithFieldLables->setFieldLabels(['one' => 'I', 'two' => 'II', 'three' => 'III']);
        $this->assertFormattedOutputMatches($expected, 'table', $data, $formatterOptionsWithFieldLables);
        $expectedDrushStyleTable = <<<EOT
 One   : apple
 Two   : banana
 Three : carrot
EOT;
        // If we provide field labels, then the output will change to reflect that.
        $formatterOptionsWithFieldLables = new FormatterOptions();
        $formatterOptionsWithFieldLables->setTableStyle('compact')->setListDelimiter(':');
        $this->assertFormattedOutputMatches($expectedDrushStyleTable, 'table', $data, $formatterOptionsWithFieldLables);
        // Adding an extra field that does not exist in the data set should not change the output
        $formatterOptionsWithExtraFieldLables = new FormatterOptions();
        $formatterOptionsWithExtraFieldLables->setFieldLabels(['one' => 'I', 'two' => 'II', 'three' => 'III', 'four' => 'IV']);
        $this->assertFormattedOutputMatches($expected, 'table', $data, $formatterOptionsWithExtraFieldLables);
        $expectedRotated = <<<EOT
 ------- -------- --------
  One     Two      Three
 ------- -------- --------
  apple   banana   carrot
 ------- -------- --------
EOT;
        $this->assertFormattedOutputMatches($expectedRotated, 'table', $data, new FormatterOptions(['list-orientation' => false]));
        $expectedList = <<<EOT
apple
banana
carrot
EOT;
        $this->assertFormattedOutputMatches($expectedList, 'list', $data);
        $expectedReorderedList = <<<EOT
carrot
apple
EOT;
        $options = new FormatterOptions([FormatterOptions::FIELDS => 'three,one']);
        $this->assertFormattedOutputMatches($expectedReorderedList, 'list', $data, $options);
        $expectedCsv = <<<EOT
One,Two,Three
apple,banana,carrot
EOT;
        $this->assertFormattedOutputMatches($expectedCsv, 'csv', $data);
        $expectedCsvNoHeaders = 'apple,banana,carrot';
        $this->assertFormattedOutputMatches($expectedCsvNoHeaders, 'csv', $data, new FormatterOptions(), ['include-field-labels' => false]);
        // Next, configure the formatter options with 'include-field-labels',
        // but set --include-field-labels to turn the option back on again.
        $options = new FormatterOptions(['include-field-labels' => false]);
        $input = new StringInput('test --include-field-labels');
        $optionDefinitions = [new InputArgument('unused', InputArgument::REQUIRED), new InputOption('include-field-labels', null, InputOption::VALUE_NONE)];
        $definition = new InputDefinition($optionDefinitions);
        $input->bind($definition);
        $testValue = $input->getOption('include-field-labels');
        $this->assertTrue($testValue);
        $hasFieldLabels = $input->hasOption('include-field-labels');
        $this->assertTrue($hasFieldLabels);
        $this->assertFormattedOutputMatches($expectedCsvNoHeaders, 'csv', $data, $options);
        $options->setInput($input);
        $this->assertFormattedOutputMatches($expectedCsv, 'csv', $data, $options);
    }