Since: 1.0
Author: Bernhard Schussek (bschussek@gmail.com)
Inheritance: extends RuntimeExceptio\RuntimeException
Esempio n. 1
0
 /**
  * Returns the command configuration for a given name.
  *
  * @param string $name The name of the command.
  *
  * @return CommandConfig The command configuration.
  *
  * @throws NoSuchCommandException If the command configuration is not found.
  *
  * @see beginCommand()
  */
 public function getCommandConfig($name)
 {
     foreach ($this->commandConfigs as $commandConfig) {
         if ($name === $commandConfig->getName()) {
             return $commandConfig;
         }
     }
     throw NoSuchCommandException::forCommandName($name);
 }
Esempio n. 2
0
    public function testRenderWithCauseIfVeryVerbose()
    {
        $this->io->setVerbosity(IO::VERY_VERBOSE);
        $cause = new RuntimeException('The message of the cause.');
        $exception = NoSuchCommandException::forCommandName('foobar', 0, $cause);
        $trace = new ExceptionTrace($exception);
        $trace->render($this->io);
        // Prevent trimming of trailing spaces in the box
        $box1 = '                                                          ' . "\n" . '  [Webmozart\\Console\\Api\\Command\\NoSuchCommandException]  ' . "\n" . '  The command "foobar" does not exist.                    ' . "\n" . '                                                          ';
        $expected1 = <<<EOF


{$box1}


Exception trace:
  ()
    src/Api/Command/NoSuchCommandException.php:??
  Webmozart\\Console\\Api\\Command\\NoSuchCommandException::forCommandName()
    tests/UI/Component/ExceptionTraceTest.php
EOF;
        $box2 = '                             ' . "\n" . '  [RuntimeException]         ' . "\n" . '  The message of the cause.  ' . "\n" . '                             ';
        $expected2 = <<<EOF


Caused by:


{$box2}


Exception trace:
  ()
    tests/UI/Component/ExceptionTraceTest.php
EOF;
        $actual = $this->io->fetchErrors();
        // Normalize line numbers across PHP and HHVM
        $actual = preg_replace('~(NoSuchCommandException.php:)\\d+~', '$1??', $actual);
        // Normalize slashes across OS
        $expected1 = str_replace(array("\n", '/'), array(PHP_EOL, DIRECTORY_SEPARATOR), $expected1);
        $expected2 = str_replace(array("\n", '/'), array(PHP_EOL, DIRECTORY_SEPARATOR), $expected2);
        $this->assertStringStartsWith($expected1, $actual);
        $this->assertContains($expected2, $actual);
        $this->assertStringEndsWith(PHP_EOL . PHP_EOL, $actual);
    }
Esempio n. 3
0
 /**
  * Returns a command by its name.
  *
  * @param string $name The name of the command.
  *
  * @return Command The command.
  *
  * @throws NoSuchCommandException If no command with that name exists in the
  *                                collection.
  */
 public function get($name)
 {
     if (isset($this->commands[$name])) {
         return $this->commands[$name];
     }
     if (isset($this->shortNameIndex[$name])) {
         return $this->commands[$this->shortNameIndex[$name]];
     }
     if (isset($this->aliasIndex[$name])) {
         return $this->commands[$this->aliasIndex[$name]];
     }
     throw NoSuchCommandException::forCommandName($name);
 }
 /**
  * @expectedException \Webmozart\Console\Api\Command\NoSuchCommandException
  */
 public function testThrowExceptionIfCatchingNotActive()
 {
     $this->config->setCatchExceptions(false)->beginCommand('list')->setHandler(new CallbackHandler(function () {
         throw NoSuchCommandException::forCommandName('foobar', 123);
     }))->end();
     $args = new StringArgs('list');
     $input = new StringInputStream();
     $output = new BufferedOutputStream();
     $errorOutput = new BufferedOutputStream();
     $application = new ConsoleApplication($this->config);
     $application->run($args, $input, $output, $errorOutput);
 }