Example #1
0
 public function testOutputFormatting()
 {
     $console = new ConsoleApplication();
     $console->add($command = new FooCommand());
     $command->run(new ArrayInput(array('')), $output = new BufferedOutput());
     $output->setFormatter(new RawOutputFormatter());
     $command->line('foo');
     $this->assertEquals('foo', rtrim($output->fetch()));
     $command->info('foo');
     $this->assertEquals('<info>foo</info>', rtrim($output->fetch()));
     $command->comment('foo');
     $this->assertEquals('<comment>foo</comment>', rtrim($output->fetch()));
     $command->question('foo');
     $this->assertEquals('<question>foo</question>', rtrim($output->fetch()));
     $command->error('foo');
     $this->assertEquals('<error>foo</error>', rtrim($output->fetch()));
 }
Example #2
0
 public function ajaxAction()
 {
     $application = $this->container['application'];
     $input = new StringInput($this->command);
     $input->setInteractive(false);
     $output = new BufferedOutput();
     $formatter = $output->getFormatter();
     $formatter->setDecorated(true);
     $output->setFormatter(new HtmlOutputFormatter($formatter));
     $application->setAutoExit(false);
     // Some commands  dump things out instead of returning a value
     ob_start();
     $errorCode = $application->run($input, $output);
     if (!($result = $output->fetch())) {
         $result = ob_get_contents();
         // If empty, replace it by the catched output
     }
     ob_end_clean();
     $result = nl2br($result);
     $result = preg_replace('|<br />\\r.*<br />(\\r.*?)<br />|', '$1<br />', $result);
     return ['input' => $this->command, 'output' => $result, 'environment' => '', 'error_code' => $errorCode];
 }
 public function ajaxAction()
 {
     $application = $this->container['application'];
     $input = new StringInput($this->command);
     $input->setInteractive(false);
     $output = new BufferedOutput();
     $formatter = $output->getFormatter();
     $formatter->setDecorated(true);
     $output->setFormatter(new HtmlOutputFormatter($formatter));
     $application->setAutoExit(false);
     $endpoint = preg_replace('/(updater\\/|updater\\/index.php)$/', '', $this->request->getRequestUri());
     $fullEndpoint = sprintf('%s://%s%sindex.php/occ/', $this->request->getServerProtocol(), $this->request->getHost(), $endpoint !== '' ? $endpoint : '/');
     $application->setEndpoint($fullEndpoint);
     $application->setAuthToken($this->request->header('X_Updater_Auth'));
     // Some commands dump things out instead of returning a value
     ob_start();
     $errorCode = $application->run($input, $output);
     if (!($result = $output->fetch())) {
         $result = ob_get_contents();
         // If empty, replace it by the catched output
     }
     ob_end_clean();
     $result = nl2br($result);
     $result = preg_replace('|<br />\\r.*<br />(\\r.*?)<br />|', '$1<br />', $result);
     return ['input' => $this->command, 'output' => $result, 'environment' => '', 'error_code' => $errorCode];
 }