public function match(Request $request) { if (!$request instanceof ConsoleRequest) { return null; } $params = $request->getParams()->toArray(); if (!isset($params[0]) || !$this->application->has($params[0])) { return null; } return new RouteMatch($this->defaults); }
public function testArrayCallbackSyntax() { $console = new Application(); $console->add(new LlamaCommand('test:llama-command', null, array($this, 'simpleCallback'))); $this->assertTrue($console->has('test:llama-command')); $command = $console->get('test:llama-command'); $this->assertInstanceOf('Beryllium\\Llama\\LlamaCommand', $command); $input = new ArrayInput(array('test:llama-command')); $output = new BufferedOutput(); $command->run($input, $output); $this->assertSame("simple callback works\n", $output->fetch()); }
public function registerCommands(Application $application) { /** @var Container $container */ $container = $this->container; foreach ($container->getServiceIds() as $serviceId) { $name = null; if (strncmp($serviceId, "command.", 8) === 0) { $name = str_replace(".", ":", substr($serviceId, 8)); } elseif (strncmp($serviceId, "task.", 5) === 0) { $name = str_replace(".", ":", $serviceId); } if ($name !== null && !$application->has($name)) { /** @var Command $command */ $command = $this->container->get($serviceId); if ($command instanceof AbstractCommand) { /** @var AbstractCommand $command */ $command->initializeCommand($name); } $application->add($command); } } }
public function testHasGet() { $application = new Application(); $this->assertTrue($application->has('list'), '->has() returns true if a named command is registered'); $this->assertFalse($application->has('afoobar'), '->has() returns false if a named command is not registered'); $application->add($foo = new \FooCommand()); $this->assertTrue($application->has('afoobar'), '->has() returns true if an alias is registered'); $this->assertEquals($foo, $application->get('foo:bar'), '->get() returns a command by name'); $this->assertEquals($foo, $application->get('afoobar'), '->get() returns a command by alias'); $application = new Application(); $application->add($foo = new \FooCommand()); // simulate --help $r = new \ReflectionObject($application); $p = $r->getProperty('wantHelps'); $p->setAccessible(true); $p->setValue($application, true); $command = $application->get('foo:bar'); $this->assertInstanceOf('Symfony\\Component\\Console\\Command\\HelpCommand', $command, '->get() returns the help command if --help is provided as the input'); }
public function testHasGet() { $application = new Application(); $this->assertTrue($application->has('list'), '->has() returns true if a named command is registered'); $this->assertFalse($application->has('afoobar'), '->has() returns false if a named command is not registered'); $application->add($foo = new \FooCommand()); $this->assertTrue($application->has('afoobar'), '->has() returns true if an alias is registered'); $this->assertEquals($foo, $application->get('foo:bar'), '->get() returns a command by name'); $this->assertEquals($foo, $application->get('afoobar'), '->get() returns a command by alias'); try { $application->get('foofoo'); $this->fail('->get() throws an \\InvalidArgumentException if the command does not exist'); } catch (\Exception $e) { $this->assertInstanceOf('\\InvalidArgumentException', $e, '->get() throws an \\InvalidArgumentException if the command does not exist'); $this->assertEquals('The command "foofoo" does not exist.', $e->getMessage(), '->get() throws an \\InvalidArgumentException if the command does not exist'); } $application = new TestApplication(); $application->add($foo = new \FooCommand()); $application->setWantHelps(); $command = $application->get('foo:bar'); $this->assertEquals('Symfony\\Component\\Console\\Command\\HelpCommand', get_class($command), '->get() returns the help command if --help is provided as the input'); }
/** * @covers ::boot */ public function testDefaultsWithOrm() { $app = new Silex(); $app['db'] = $this->getMockBuilder('Doctrine\\DBAL\\Connection')->disableOriginalConstructor()->getMock(); $app['orm.em'] = $this->getMockBuilder('Doctrine\\ORM\\EntityManager')->disableOriginalConstructor()->getMock(); $console = new Console(); $app->register(new DoctrineMigrationsProvider($console)); $this->assertFalse($console->has('migrations:execute')); $this->assertFalse($console->has('migrations:generate')); $this->assertFalse($console->has('migrations:migrate')); $this->assertFalse($console->has('migrations:status')); $this->assertFalse($console->has('migrations:version')); $this->assertFalse($console->has('migrations:diff')); $app->boot(); $this->assertTrue($console->has('migrations:execute')); $this->assertTrue($console->has('migrations:generate')); $this->assertTrue($console->has('migrations:migrate')); $this->assertTrue($console->has('migrations:status')); $this->assertTrue($console->has('migrations:version')); $this->assertTrue($console->has('migrations:diff')); }