예제 #1
0
 public function testFindCommand()
 {
     $application = new TestApplication();
     $application->addCommand(new \FooCommand());
     $this->assertEquals('FooCommand', get_class($application->findCommand('foo:bar')), '->findCommand() returns a command if its name exists');
     $this->assertEquals('Symfony\\Components\\Console\\Command\\HelpCommand', get_class($application->findCommand('h')), '->findCommand() returns a command if its name exists');
     $this->assertEquals('FooCommand', get_class($application->findCommand('f:bar')), '->findCommand() returns a command if the abbreviation for the namespace exists');
     $this->assertEquals('FooCommand', get_class($application->findCommand('f:b')), '->findCommand() returns a command if the abbreviation for the namespace and the command name exist');
     $this->assertEquals('FooCommand', get_class($application->findCommand('a')), '->findCommand() returns a command if the abbreviation exists for an alias');
     $application->addCommand(new \Foo1Command());
     $application->addCommand(new \Foo2Command());
     try {
         $application->findCommand('f');
         $this->fail('->findCommand() throws an \\InvalidArgumentException if the abbreviation is ambiguous for a namespace');
     } catch (\Exception $e) {
         $this->assertInstanceOf('\\InvalidArgumentException', $e, '->findCommand() throws an \\InvalidArgumentException if the abbreviation is ambiguous for a namespace');
         $this->assertEquals('Command "f" is not defined.', $e->getMessage(), '->findCommand() throws an \\InvalidArgumentException if the abbreviation is ambiguous for a namespace');
     }
     try {
         $application->findCommand('a');
         $this->fail('->findCommand() throws an \\InvalidArgumentException if the abbreviation is ambiguous for an alias');
     } catch (\Exception $e) {
         $this->assertInstanceOf('\\InvalidArgumentException', $e, '->findCommand() throws an \\InvalidArgumentException if the abbreviation is ambiguous for an alias');
         $this->assertEquals('Command "a" is ambiguous (afoobar, afoobar1 and 1 more).', $e->getMessage(), '->findCommand() throws an \\InvalidArgumentException if the abbreviation is ambiguous for an alias');
     }
     try {
         $application->findCommand('foo:b');
         $this->fail('->findCommand() throws an \\InvalidArgumentException if the abbreviation is ambiguous for a command');
     } catch (\Exception $e) {
         $this->assertInstanceOf('\\InvalidArgumentException', $e, '->findCommand() throws an \\InvalidArgumentException if the abbreviation is ambiguous for a command');
         $this->assertEquals('Command "foo:b" is ambiguous (foo:bar, foo:bar1).', $e->getMessage(), '->findCommand() throws an \\InvalidArgumentException if the abbreviation is ambiguous for a command');
     }
 }
예제 #2
0
 public function testFindCommand()
 {
     $application = new TestApplication();
     $application->addCommand(new \FooCommand());
     $this->assertEquals(get_class($application->findCommand('foo:bar')), 'FooCommand', '->findCommand() returns a command if its name exists');
     $this->assertEquals(get_class($application->findCommand('h')), 'Symfony\\Components\\Console\\Command\\HelpCommand', '->findCommand() returns a command if its name exists');
     $this->assertEquals(get_class($application->findCommand('f:bar')), 'FooCommand', '->findCommand() returns a command if the abbreviation for the namespace exists');
     $this->assertEquals(get_class($application->findCommand('f:b')), 'FooCommand', '->findCommand() returns a command if the abbreviation for the namespace and the command name exist');
     $this->assertEquals(get_class($application->findCommand('a')), 'FooCommand', '->findCommand() returns a command if the abbreviation exists for an alias');
     $application->addCommand(new \Foo1Command());
     $application->addCommand(new \Foo2Command());
     try {
         $application->findCommand('f');
         $this->fail('->findCommand() throws an \\InvalidArgumentException if the abbreviation is ambiguous for a namespace');
     } catch (\InvalidArgumentException $e) {
     }
     try {
         $application->findCommand('a');
         $this->fail('->findCommand() throws an \\InvalidArgumentException if the abbreviation is ambiguous for an alias');
     } catch (\InvalidArgumentException $e) {
     }
     try {
         $application->findCommand('foo:b');
         $this->fail('->findCommand() throws an \\InvalidArgumentException if the abbreviation is ambiguous for a command');
     } catch (\InvalidArgumentException $e) {
     }
 }