protected function setUp() { $application = new Application(); $application->add(new RepositoryTransferCommand($this->container)); $command = $application->get(RepositoryTransferCommand::COMMAND_NAME); $this->commandTester = new CommandTester($command); }
public function testValidCommands() { $this->assertInstanceOf('Doctrine\\ODM\\MongoDB\\Tools\\Console\\Command\\GenerateDocumentsCommand', $this->cli->get('odm:generate:documents')); $this->assertInstanceOf('Doctrine\\ODM\\MongoDB\\Tools\\Console\\Command\\GenerateHydratorsCommand', $this->cli->get('odm:generate:hydrators')); $this->assertInstanceOf('Doctrine\\ODM\\MongoDB\\Tools\\Console\\Command\\GenerateProxiesCommand', $this->cli->get('odm:generate:proxies')); $this->assertInstanceOf('Doctrine\\ODM\\MongoDB\\Tools\\Console\\Command\\GenerateRepositoriesCommand', $this->cli->get('odm:generate:repositories')); $this->assertInstanceOf('Doctrine\\ODM\\MongoDB\\Tools\\Console\\Command\\QueryCommand', $this->cli->get('odm:query')); $this->assertInstanceOf('Doctrine\\ODM\\MongoDB\\Tools\\Console\\Command\\Schema\\CreateCommand', $this->cli->get('odm:schema:create')); $this->assertInstanceOf('Doctrine\\ODM\\MongoDB\\Tools\\Console\\Command\\Schema\\UpdateCommand', $this->cli->get('odm:schema:update')); $this->assertInstanceOf('Doctrine\\ODM\\MongoDB\\Tools\\Console\\Command\\Schema\\DropCommand', $this->cli->get('odm:schema:drop')); }
public function setUp() { $application = new Application(); $application->add(new CreateOrganizationCommand()); $this->command = $application->get('swp:organization:create'); $this->question = $this->command->getHelper('question'); }
protected function setUp() { $application = new Application(); $application->add(new SearchCommand($this->container)); $command = $application->get(SearchCommand::COMMAND_NAME); $this->commandTester = new CommandTester($command); }
/** * @covers ::execute */ public function testExecute() { $client = new ClientMock(); $client->queueResponse('packagist/list.json')->queueResponse('packagist/list.json')->queueResponse('packagist/list.empty.json'); $command = new SearchCommand($client); $console = new Application(); $console->add($command); $tester = new CommandTester($console->get('search')); $tester->execute([]); $expected = <<<RESPONSE Available Init Templates: clippings/package-template harp-orm/harp-template openbuildings/jam-template RESPONSE; $this->assertEquals($expected, $tester->getDisplay()); $tester->execute(['filter' => 'clip']); $expected = <<<RESPONSE Available Init Templates: clippings/package-template RESPONSE; $this->assertEquals($expected, $tester->getDisplay()); $expected = <<<RESPONSE No templates found RESPONSE; $tester->execute([]); $this->assertEquals($expected, $tester->getDisplay()); }
public function setUp() { $application = new Application(); $application->add(new CreateTenantCommand()); $this->command = $application->get('swp:tenant:create'); $this->question = $this->command->getHelper('question'); }
public function testExecuteForApplicationCommandWithXmlOption() { $application = new Application(); $commandTester = new CommandTester($application->get('help')); $commandTester->execute(array('command_name' => 'list', '--xml' => true)); $this->assertRegExp('/<command/', $commandTester->getDisplay(), '->execute() returns an XML help text if --xml is passed'); }
protected function getCommandTester(Command $command, $name, $params = []) { $application = new Application(); $application->add($command); $tester = new CommandTester($application->get($name)); $tester->execute(array_merge(['command' => $command->getName()], $params)); return $tester; }
public function testExecuteForApplicationCommandWithXmlOption() { $application = new Application(); $commandTester = new CommandTester($application->get('help')); $commandTester->execute(array('command_name' => 'list', '--format' => 'xml')); $this->assertContains('list [--xml] [--raw] [--format FORMAT] [--] [<namespace>]', $commandTester->getDisplay(), '->execute() returns a text help for the given command'); $this->assertContains('<command', $commandTester->getDisplay(), '->execute() returns an XML help text if --format=xml is passed'); }
public function testExecuteForApplicationCommandWithXmlOption() { $application = new Application(); $commandTester = new CommandTester($application->get('help')); $commandTester->execute(array('command_name' => 'list', '--format' => 'xml')); $this->assertRegExp('/list \\[--xml\\] \\[--raw\\] \\[--format="\\.\\.\\."\\] \\[namespace\\]/', $commandTester->getDisplay(), '->execute() returns a text help for the given command'); $this->assertRegExp('/<command/', $commandTester->getDisplay(), '->execute() returns an XML help text if --format=xml is passed'); }
/** * @inheritdoc */ public function get($name) { $command = parent::get($name); if ($command instanceof ContainerAwareInterface) { $command->setContainer($this->kernel->getContainer()); } return $command; }
public function testExecute() { $application = new Application(); $commandTester = new CommandTester($command = $application->get('list')); $commandTester->execute(array('command' => $command->getFullName())); $this->assertRegExp('/help Displays help for a command/', $commandTester->getDisplay(), '->execute() returns a list of available commands'); $commandTester->execute(array('command' => $command->getFullName(), '--xml' => true)); $this->assertRegExp('/<command id="list" namespace="_global" name="list">/', $commandTester->getDisplay(), '->execute() returns a list of available commands in XML if --xml is passed'); }
public function testExecuteListsCommandsWithRawOption() { $application = new Application(); $commandTester = new CommandTester($command = $application->get('list')); $commandTester->execute(array('command' => $command->getName(), '--raw' => true)); $output = <<<EOF help Displays help for a command list Lists commands EOF; $this->assertEquals($output, $commandTester->getDisplay(true)); }
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 testExecuteListsCommandsWithNamespaceArgument() { require_once realpath(__DIR__ . '/../Fixtures/FooCommand.php'); $application = new Application(); $application->add(new \FooCommand()); $commandTester = new CommandTester($command = $application->get('list')); $commandTester->execute(array('command' => $command->getName(), 'namespace' => 'foo', '--raw' => true)); $output = <<<EOF foo:bar The foo:bar command EOF; $this->assertEquals($output, $commandTester->getDisplay(true)); }
public function testExecuteCurrent() { $manifest = $this->createFile(); file_put_contents($manifest, '[]'); $command = new Command('upgrade', true); $command->setManifestUri($manifest); $app = new Application('Test', '1.0.0'); $app->getHelperSet()->set(new Helper()); $app->add($command); $tester = new CommandTester($app->get('upgrade')); $tester->execute(array('command' => 'upgrade')); $this->assertRegExp('/Already up-to-date\\./', $tester->getDisplay()); }
protected function getCommandTester(Command $command, $name, $params = [], $helpers = []) { $application = new Application(); $application->add($command); $testedCommand = $application->get($name); if (!empty($helpers)) { foreach ($helpers as $helperName => $helperMock) { $testedCommand->getHelperSet()->set($helperMock, $helperName); } } $tester = new CommandTester($testedCommand); $tester->execute(array_merge(['command' => $command->getName()], $params)); return $tester; }
public function testExecute() { $command = new HelpCommand(); $command->setCommand(new ListCommand()); $commandTester = new CommandTester($command); $commandTester->execute(array()); $this->assertRegExp('/list \\[--xml\\] \\[namespace\\]/', $commandTester->getDisplay(), '->execute() returns a text help for the given command'); $commandTester->execute(array('--xml' => true)); $this->assertRegExp('/<command/', $commandTester->getDisplay(), '->execute() returns an XML help text if --xml is passed'); $application = new Application(); $commandTester = new CommandTester($application->get('help')); $commandTester->execute(array('command_name' => 'list')); $this->assertRegExp('/list \\[--xml\\] \\[namespace\\]/', $commandTester->getDisplay(), '->execute() returns a text help for the given command'); $commandTester->execute(array('command_name' => 'list', '--xml' => true)); $this->assertRegExp('/<command/', $commandTester->getDisplay(), '->execute() returns an XML help text if --xml is passed'); }
/** * @covers ::execute */ public function testExecute() { $token = $this->getMockBuilder('CL\\ComposerInit\\Token')->disableOriginalConstructor()->setMethods(['set', 'getFilename'])->getMock(); $token->method('set')->with('NEW_TOKEN'); $token->method('getFilename')->willReturn('TOKEN_FILENAME'); $command = new TokenCommand($token); $console = new Application(); $console->add($command); $tester = new CommandTester($console->get('token')); $tester->execute(['token' => 'NEW_TOKEN']); $expected = <<<OUTPUT Token saved to TOKEN_FILENAME OUTPUT; $this->assertEquals($expected, $tester->getDisplay()); }
public function testExecute() { $application = new Application(); $commandTester = new CommandTester($command = $application->get('list')); $commandTester->execute(array('command' => $command->getName()), array('decorated' => false)); $this->assertRegExp('/help Displays help for a command/', $commandTester->getDisplay(), '->execute() returns a list of available commands'); $commandTester->execute(array('command' => $command->getName(), '--xml' => true)); $this->assertRegExp('/<command id="list" name="list">/', $commandTester->getDisplay(), '->execute() returns a list of available commands in XML if --xml is passed'); $commandTester->execute(array('command' => $command->getName(), '--raw' => true)); $output = <<<EOF help Displays help for a command list Lists commands EOF; $this->assertEquals(str_replace("\n", PHP_EOL, $output), $commandTester->getDisplay(), 'boo'); }
/** * @covers ::execute */ public function testExecute() { $template = $this->getMockBuilder('CL\\ComposerInit\\Template')->disableOriginalConstructor()->setMethods(['getPromptNames', 'putInto', 'open'])->getMock(); $prompts = $this->getMockBuilder('CL\\ComposerInit\\Prompt\\Prompts')->disableOriginalConstructor()->setMethods(['getValues'])->getMock(); $command = $this->getMockBuilder('CL\\ComposerInit\\UseCommand')->setConstructorArgs([$template, $prompts, new ClientMock()])->setMethods(['getTemplate', 'getPrompts', 'getPackageZipUrl'])->getMock(); $command->method('getPackageZipUrl')->with('TEST_PACKAGE')->willReturn('TEST_URL'); $template->method('open')->with('TEST_URL'); $template->method('getPromptNames')->willReturn(['author_name', 'title']); $template->method('putInto')->with(getcwd()); $prompts->method('getValues')->with(['author_name', 'title'], $this->isInstanceOf('Symfony\\Component\\Console\\Output\\OutputInterface'), $this->isInstanceOf('Symfony\\Component\\Console\\Helper\\DialogHelper'))->willReturn(['author_name' => 'VAL1', 'title' => 'VAL2']); $console = new Application(); $console->add($command); $tester = new CommandTester($console->get('use')); $dialog = $command->getHelper('dialog'); $dialog->setInputStream($this->getInputStream("y\n")); $tester->execute(['package' => 'TEST_PACKAGE']); $expected = <<<OUTPUT Enter Template variables (Press enter for default): Use These Variables: author_name: VAL1 title: VAL2 Confirm? (Y/n):Done OUTPUT; $this->assertEquals($expected, $tester->getDisplay()); $dialog->setInputStream($this->getInputStream("n\n")); $tester->execute(['package' => 'TEST_PACKAGE']); $expected = <<<OUTPUT Enter Template variables (Press enter for default): Use These Variables: author_name: VAL1 title: VAL2 Confirm? (Y/n):Aborted OUTPUT; $this->assertEquals($expected, $tester->getDisplay()); }
/** * @expectedException Symfony\Component\Console\Exception\CommandNotFoundException * @expectedExceptionMessage The command "foofoo" does not exist. */ public function testGetInvalidCommand() { $application = new Application(); $application->get('foofoo'); }
public function testExecuteListsCommandsOrderRaw() { require_once realpath(__DIR__ . '/../Fixtures/Foo6Command.php'); $application = new Application(); $application->add(new \Foo6Command()); $commandTester = new CommandTester($command = $application->get('list')); $commandTester->execute(array('command' => $command->getName(), '--raw' => true)); $output = <<<EOF help Displays help for a command list Lists commands 0foo:bar 0foo:bar command EOF; $this->assertEquals($output, trim($commandTester->getDisplay(true))); }
/** * {@inheritdoc} */ public function get($name) { $this->registerCommands(); return parent::get($name); }
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'); }
/** * Returns the tester for the command. * * @return CommandTester The tester. */ protected function getTester() { return new CommandTester($this->app->get($this->name)); }
/** * @param Command $command * @return Command */ protected function createCommand(Command $command) { $application = new Application(); $application->add($command); return $application->get($command->getName()); }
/** * @test * it should allow specifying the tables to skip in the dump */ public function it_should_allow_specifying_the_tables_to_skip_in_the_dump() { $root = vfsStream::setup('dumps'); $root->addChild(new vfsStreamFile('dump.sql')); $root->addChild(new vfsStreamFile('dump.dist.sql')); $expectedDump = $root->url() . '/dump.sql'; $expectedDistDump = $root->url() . '/dump.dist.sql'; $application = new Application(); /** @var \tad\WPBrowser\Services\Db\MySQLDumpFactoryInterface $factory */ $factory = $this->prophesize('\\tad\\WPBrowser\\Services\\Db\\MySQLDumpFactoryInterface'); $dump = $this->prophesize('MySQLDump'); $dump->write(Argument::any())->shouldBeCalled(); $filesystem = $this->prophesize('tad\\WPBrowser\\Filesystem\\Filesystem'); $filesystem->file_put_contents(Argument::type('string'), Argument::type('string'))->willReturn(true); $factory->makeDump(Argument::type('string'), Argument::type('string'), Argument::type('string'), Argument::type('string'))->willReturn($dump->reveal()); $application->add(new DbSnapshot(null, $factory->reveal(), $filesystem->reveal())); $command = $application->find('db:snapshot'); $commandTester = new CommandTester($command); $commandTester->execute(['command' => $command->getName(), 'name' => 'db', 'snapshot' => 'issue4455', '--dump-file' => $expectedDump, '--dist-dump-file' => $expectedDistDump, '--skip-tables' => 'foo,bar,baz']); $dumpTables = $application->get('db:snapshot')->_getDumpTables(); $this->assertArrayHasKey('foo', $dumpTables); $this->assertArrayHasKey('bar', $dumpTables); $this->assertArrayHasKey('baz', $dumpTables); $this->assertEquals(\MySQLDump::NONE, $dumpTables['foo']); $this->assertEquals(\MySQLDump::NONE, $dumpTables['bar']); $this->assertEquals(\MySQLDump::NONE, $dumpTables['baz']); }
/** * @param IMigrationTask $task * @throws Exception */ private function runTask(IMigrationTask $task, Application $application, OutputInterface $output) { try { $command = $application->get($task->getCommandName()); $arguments = array_merge(array('command' => $task->getCommandName()), $task->getParameters()); $input = new ArrayInput($arguments); $command->run($input, $output); $this->markAsRun($task); } catch (Exception $e) { throw $e; } }
function testAppShouldHaveTestCommand() { $command = $this->app->get('test'); assert($command, new \AssertionError('Test command not found')); }