Example #1
0
 public function testCommandFromApplication()
 {
     $application = new Application();
     $application->setAutoExit(false);
     $callable = function ($input, $output) {
         $output->writeln('foo');
     };
     $command = new Command('foo', $callable);
     $application->add($command);
     $tester = new CommandTester($application->find('foo'));
     $result = $tester->execute(array());
     $this->assertInstanceOf('Danack\\Console\\Command\\ParsedCommand', $result);
 }
Example #2
0
 public function testFindAlternativeNamespace()
 {
     $application = new Application();
     $application->add(new \FooCommand());
     $application->add(new \Foo1Command());
     $application->add(new \Foo2Command());
     $application->add(new \foo3Command());
     try {
         $application->find('Unknown-namespace:Unknown-command');
         $this->fail('->find() throws an \\InvalidArgumentException if namespace does not exist');
     } catch (\Exception $e) {
         $this->assertInstanceOf('\\InvalidArgumentException', $e, '->find() throws an \\InvalidArgumentException if namespace does not exist');
         $this->assertEquals('There are no commands defined in the "Unknown-namespace" namespace.', $e->getMessage(), '->find() throws an \\InvalidArgumentException if namespace does not exist, without alternatives');
     }
     try {
         $application->find('foo2:command');
         $this->fail('->find() throws an \\InvalidArgumentException if namespace does not exist');
     } catch (\Exception $e) {
         $this->assertInstanceOf('\\InvalidArgumentException', $e, '->find() throws an \\InvalidArgumentException if namespace does not exist');
         $this->assertRegExp('/There are no commands defined in the "foo2" namespace./', $e->getMessage(), '->find() throws an \\InvalidArgumentException if namespace does not exist, with alternative');
         $this->assertRegExp('/foo/', $e->getMessage(), '->find() throws an \\InvalidArgumentException if namespace does not exist, with alternative : "foo"');
         $this->assertRegExp('/foo1/', $e->getMessage(), '->find() throws an \\InvalidArgumentException if namespace does not exist, with alternative : "foo1"');
         $this->assertRegExp('/foo3/', $e->getMessage(), '->find() throws an \\InvalidArgumentException if namespace does not exist, with alternative : "foo3"');
     }
 }