/** * @covers \Ilios\CliBundle\Command\AddRootUserCommand::execute */ public function testUserNotFound() { $userId = 0; $this->userManager->shouldReceive('findOneBy')->with(['id' => $userId])->andReturn(null); $this->setExpectedException('Exception', "No user with id #{$userId} was found."); $this->commandTester->execute(['command' => AddRootUserCommand::COMMAND_NAME, 'userId' => $userId]); }
/** * @dataProvider inputInteractiveCommandToOutputFilesProvider */ public function testInteractiveOutputs($inputCommandFilepath, $outputFilepath) { $code = (require $inputCommandFilepath); $this->command->setCode($code); $this->tester->execute(array(), array('interactive' => true, 'decorated' => false)); $this->assertStringEqualsFile($outputFilepath, $this->tester->getDisplay(true)); }
public function testExecute() { $cmd = $this->getCommandInstance(); $cmdTester = new CommandTester($cmd); try { $cmdTester->execute(array('command' => $cmd->getName())); $this->fail('The command without arguments should throw a \\RuntimeException'); } catch (\Exception $e) { $this->assertInstanceOf('\\RuntimeException', $e); } try { $cmdTester->execute(array('command' => $cmd->getName(), 'product' => 'Test')); $this->fail('The command without "service_id" argument should throw a \\RuntimeException'); } catch (\Exception $e) { $this->assertInstanceOf('\\RuntimeException', $e); } /* try { $cmdTester->execute(array( 'command' => $cmd->getName(), 'product' => 'Test', 'service_id' => 2 )); } catch (\Exception $e) { $this->fail('No exception should be thrown when all arguments are provided'); } */ }
public function testWillShowQuery() { $this->_em->persist(new DateTimeModel()); $this->_em->flush(); $this->assertSame(0, $this->tester->execute(array('command' => $this->command->getName(), 'dql' => 'SELECT e FROM ' . DateTimeModel::CLASSNAME . ' e', '--show-sql' => 'true'))); $this->assertStringMatchesFormat('string%sSELECT %a', $this->tester->getDisplay()); }
/** * Call API and process job immediately, return job info * @param string $url URL of API call * @param array $params parameters of POST call * @param string $method HTTP method of API call * @return Job */ protected function processJob($url, $params = [], $method = 'POST') { $responseJson = $this->callApi($url, $method, $params); $this->assertArrayHasKey('id', $responseJson, sprintf("Response of API call '%s' should contain 'id' key.", $url)); $this->commandTester->execute(['command' => 'syrup:run-job', 'jobId' => $responseJson['id']]); return $this->jobMapper->get($responseJson['id']); }
public function testCommand() { $this->converter->expects($this->once())->method('convert')->with('Document\\MyClass', array('en'), array(), 'none')->will($this->returnValue(false)); $this->mockSession->expects($this->once())->method('save'); $this->commandTester->execute(array('classname' => 'Document\\MyClass', '--locales' => array('en'), '--force' => true)); $this->assertEquals('.' . PHP_EOL . 'done' . PHP_EOL, $this->commandTester->getDisplay()); }
public function testExecute() { // Lets create a workflow manager $workflowManager = new WorkflowManager(); // Lets create a mock DI container $mockContainer = $this->getMockBuilder('Symfony\\Component\\DependencyInjection\\Container')->disableOriginalConstructor()->setMethods(array('get'))->getMock(); $mockContainer->expects($this->any())->method('get')->with($this->equalTo('tyhand_workflow.manager'))->will($this->returnValue($workflowManager)); // Lets start the application $application = new Application(); $commandObject = new WorkflowManagerDebugCommand(); $commandObject->setContainer($mockContainer); $application->add($commandObject); $command = $application->find('tyhand_workflow:manager:debug'); $commandTester = new CommandTester($command); $commandTester->execute(array('command' => $command->getName())); $this->assertRegExp('/.../', $commandTester->getDisplay()); // Lets add some mock definitions to the workflow manager $mockDefinition = $this->getMockBuilder('TyHand\\WorkflowBundle\\Workflow\\AbstractWorkflowDefinition')->setMethods(array('getName', 'getContextClass', 'build'))->getMock(); $mockDefinition->expects($this->any())->method('getName')->will($this->returnValue('fake')); $mockDefinition->expects($this->any())->method('getContextClass')->will($this->returnValue('TyHand\\WorkflowBundle\\Tests\\DummyContext')); $mockDefinition->expects($this->any())->method('build')->will($this->returnValue(false)); $workflowManager->addWorkflowDefinition($mockDefinition); $mockDefinition2 = $this->getMockBuilder('TyHand\\WorkflowBundle\\Workflow\\AbstractWorkflowDefinition')->setMethods(array('getName', 'getContextClass', 'build'))->getMock(); $mockDefinition2->expects($this->any())->method('getName')->will($this->returnValue('abstract')); $mockDefinition2->expects($this->any())->method('getContextClass')->will($this->returnValue('TyHand\\WorkflowBundle\\Tests\\DummyContext')); $mockDefinition2->expects($this->any())->method('build')->will($this->returnValue(false)); $workflowManager->addWorkflowDefinition($mockDefinition2); // Test the command again $commandTester->execute(array('command' => $command->getName())); $this->assertRegExp('/fake/', $commandTester->getDisplay()); $this->assertRegExp('/abstract/', $commandTester->getDisplay()); $this->assertRegExp('/TyHand\\\\WorkflowBundle\\\\Tests\\\\DummyContext/', $commandTester->getDisplay()); $this->assertRegExp('/Mock_AbstractWorkflowDefinition/', $commandTester->getDisplay()); }
/** * @test * @group integration */ public function testDiffWithEnv() { $exit_status = $this->_commandTester->execute(array('command' => $this->_commandName, '--magento-root' => $this->_magentoRoot, '--env' => "prod", 'config-yaml-file' => __DIR__ . "/data/base_prodenv_GBP.yaml")); $this->assertNotEmpty($this->_commandTester->getDisplay()); $this->assertCount(3, explode("\n", trim($this->_commandTester->getDisplay()))); $this->assertEquals(3, $exit_status); }
public function testExecuteNoOptions() { $this->deploymentConfig->expects($this->once())->method('isAvailable')->will($this->returnValue(false)); $this->tester->execute([]); $expected = 'Enabling maintenance mode' . PHP_EOL . 'Not enough information provided to take backup.' . PHP_EOL . 'Disabling maintenance mode' . PHP_EOL; $this->assertSame($expected, $this->tester->getDisplay()); }
/** * @covers \Ilios\CliBundle\Command\ListRootUsersCommand::execute */ public function testListUsersNoResults() { $this->userManager->shouldReceive('findDTOsBy')->with(['root' => true])->andReturn([]); $this->commandTester->execute(['command' => ListRootUsersCommand::COMMAND_NAME]); $output = $this->commandTester->getDisplay(); $this->assertEquals('No users with root-level privileges found.', trim($output)); }
/** * @test * @group functional */ public function execute() { $application = new Application(static::$kernel); $application->add(new SyncSchemaCommand()); $command = $application->find('eav:schema:sync'); $commandTester = new CommandTester($command); // FIRST PASS $commandTester->execute(array('command' => $command->getName())); $output = <<<OUTPUT +-----------+------------------------------------------------+ | Created: | Padam87\\AttributeBundle\\Tests\\Model\\Subscriber | +-----------+------------------------------------------------+ | Existing: | | +-----------+------------------------------------------------+ OUTPUT; $this->assertSame(str_replace(PHP_EOL, "\n", $output), $commandTester->getDisplay(true)); // SECOND PASS $commandTester->execute(array('command' => $command->getName())); $output = <<<OUTPUT +-----------+------------------------------------------------+ | Created: | | +-----------+------------------------------------------------+ | Existing: | Padam87\\AttributeBundle\\Tests\\Model\\Subscriber | +-----------+------------------------------------------------+ OUTPUT; $this->assertSame(str_replace(PHP_EOL, "\n", $output), $commandTester->getDisplay(true)); }
/** * @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()); }
/** * Runs the command and returns it's output. * * @param array $input Command input. * @param array $options Command tester options. * * @return string */ protected function runCommand(array $input = array(), array $options = array()) { $input['command'] = $this->command->getName(); $options['interactive'] = true; $this->commandTester->execute($input, $options); return $this->commandTester->getDisplay(); }
/** * @Then /^I should get the following products after apply the following updater to it:$/ * * @param TableNode $updates * * @throws \Exception */ public function iShouldGetTheFollowingProductsAfterApplyTheFollowingUpdaterToIt(TableNode $updates) { $application = $this->getApplicationsForUpdaterProduct(); $updateCommand = $application->find('pim:product:update'); $updateCommand->setContainer($this->getMainContext()->getContainer()); $updateCommandTester = new CommandTester($updateCommand); $getCommand = $application->find('pim:product:get'); $getCommand->setContainer($this->getMainContext()->getContainer()); $getCommandTester = new CommandTester($getCommand); foreach ($updates->getHash() as $update) { $username = isset($update['username']) ? $update['username'] : null; $updateCommandTester->execute(['command' => $updateCommand->getName(), 'identifier' => $update['product'], 'json_updates' => $update['actions'], 'username' => $username]); $expected = json_decode($update['result'], true); if (isset($expected['product'])) { $getCommandTester->execute(['command' => $getCommand->getName(), 'identifier' => $expected['product']]); unset($expected['product']); } else { $getCommandTester->execute(['command' => $getCommand->getName(), 'identifier' => $update['product']]); } $actual = json_decode($getCommandTester->getDisplay(), true); if (null === $actual) { throw new \Exception(sprintf('An error occured during the execution of the update command : %s', $getCommandTester->getDisplay())); } if (null === $expected) { throw new \Exception(sprintf('Looks like the expected result is not valid json : %s', $update['result'])); } $diff = $this->arrayIntersect($actual, $expected); assertEquals($expected, $diff); } }
public function testContainerAccess() { $invalidator = \Mockery::mock('\FOS\HttpCacheBundle\CacheManager') ->shouldReceive('invalidatePath')->once()->with('/my/path') ->shouldReceive('invalidatePath')->once()->with('/other/path') ->shouldReceive('invalidatePath')->once()->with('/another') ->getMock() ; $container = \Mockery::mock('\Symfony\Component\DependencyInjection\ContainerInterface') ->shouldReceive('get')->once()->with('fos_http_cache.cache_manager')->andReturn($invalidator) ->getMock() ; $application = new Application(); $command = new InvalidatePathCommand(); $command->setContainer($container); $application->add($command); $command = $application->find('fos:httpcache:invalidate:path'); $commandTester = new CommandTester($command); $commandTester->execute(array( 'command' => $command->getName(), 'paths' => array('/my/path', '/other/path'), )); // the only output should be generated by the listener in verbose mode $this->assertEquals('', $commandTester->getDisplay()); // the cache manager is only fetched once $commandTester->execute(array( 'command' => $command->getName(), 'paths' => array('/another'), )); }
/** * @param string $command * @param array $args */ public function runTheCommand($command, array $args = []) { $command = $this->application->find($command); $testArguments = array_merge($args, ['command' => $command->getName()]); $this->commandTester = new CommandTester($command); $this->commandTester->execute($testArguments); }
/** * @test */ public function exceptionWhileParsingLongUrlOutputsError() { $this->urlShortener->urlToShortCode(Argument::cetera())->willThrow(new InvalidUrlException())->shouldBeCalledTimes(1); $this->commandTester->execute(['command' => 'shortcode:generate', 'longUrl' => 'http://domain.com/invalid']); $output = $this->commandTester->getDisplay(); $this->assertTrue(strpos($output, 'Provided URL "http://domain.com/invalid" is invalid. Try with a different one.') === 0); }
/** * @test */ public function wrongShortCodeFormatOutputsErrorMessage() { $shortCode = 'abc123'; $this->urlShortener->shortCodeToUrl($shortCode)->willThrow(new InvalidShortCodeException())->shouldBeCalledTimes(1); $this->commandTester->execute(['command' => 'shortcode:parse', 'shortCode' => $shortCode]); $output = $this->commandTester->getDisplay(); $this->assertEquals('Provided short code "' . $shortCode . '" has an invalid format.' . PHP_EOL, $output); }
/** * @test */ public function errorIsReturnedIfServiceThrowsException() { $apiKey = 'abcd1234'; $this->apiKeyService->disable($apiKey)->willThrow(InvalidArgumentException::class)->shouldBeCalledTimes(1); $this->commandTester->execute(['command' => 'api-key:disable', 'apiKey' => $apiKey]); $output = $this->commandTester->getDisplay(); $this->assertEquals('API key "abcd1234" does not exist.' . PHP_EOL, $output); }
/** * @test */ public function it_displays_an_error_for_unresolved_characters() { $this->container['repository.test'] = new InMemoryRepository(); $this->commandTester->execute(['command' => SearchCommand::COMMAND_NAME, '--from' => 'test', 'codepoint' => '1']); $output = $this->commandTester->getDisplay(); $statusCode = $this->commandTester->getStatusCode(); ha::assertThat('output', $output, hm::containsString('Character Not Found')); ha::assertThat('status code', $statusCode, hm::is(hm::identicalTo(1))); }
public function testReleaseWithName() { $outputPath = __DIR__ . '/../../_output/changelog.json'; @unlink($outputPath); $this->commandTester->execute(['release' => '1.0.0', '--link' => 'http://foobar.com/release/1.0.0', '--linkName' => 'hello', '--config' => __DIR__ . '/../../resources/changelog.config.php']); $this->assertFileExists($outputPath); $jsonContent = json_decode(file_get_contents($outputPath), true); $this->assertArraySubset(['releases' => ['1.0.0' => ['name' => '1.0.0', 'link' => 'http://foobar.com/release/1.0.0', 'linkName' => 'hello']]], $jsonContent); }
public function testCommand() { if (0 == strpos(phpversion(), '5.3')) { $this->markTestSkipped('Dump reference command not compatible with PHP 5.3'); } $this->commandTester->execute(array()); $res = $this->commandTester->getDisplay(); $this->assertContains('Query Builder Reference', $res); }
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 testExecute() { $this->commandTester->execute(['--output' => __DIR__ . '/_files/output/framework.csv']); $this->assertEquals('Report successfully processed.' . PHP_EOL, $this->commandTester->getDisplay()); $fileContents = file_get_contents(__DIR__ . '/_files/output/framework.csv'); $this->assertContains('"Dependencies of framework:","Total number"' . PHP_EOL . ',2' . PHP_EOL, $fileContents); $this->assertContains('"Dependencies for each module:",' . PHP_EOL, $fileContents); $this->assertContains('"Magento\\A",1' . PHP_EOL . '" -- Magento\\Framework",3' . PHP_EOL, $fileContents); $this->assertContains('"Magento\\B",1' . PHP_EOL . '" -- Magento\\Framework",3' . PHP_EOL, $fileContents); }
public function testExecute() { $this->commandTester->execute(['--output' => __DIR__ . '/_files/output/circular.csv']); $this->assertEquals('Report successfully processed.' . PHP_EOL, $this->commandTester->getDisplay()); $fileContents = file_get_contents(__DIR__ . '/_files/output/circular.csv'); $this->assertContains('"Circular dependencies:","Total number of chains"' . PHP_EOL . ',2' . PHP_EOL, $fileContents); $this->assertContains('"Circular dependencies for each module:",' . PHP_EOL, $fileContents); $this->assertContains('magento/module-a,1' . PHP_EOL . 'magento/module-a->magento/module-b->magento/module-a' . PHP_EOL, $fileContents); $this->assertContains('magento/module-b,1' . PHP_EOL . 'magento/module-b->magento/module-a->magento/module-b' . PHP_EOL, $fileContents); }
/** * @expectedException \InvalidArgumentException * @expectedExceptionMessage Parameter `new` is not ready yet - cache invalidation required */ public function testExecuteThrowsExceptionWhenUsingNewOptions() { $container = $this->prophesize('Symfony\\Component\\DependencyInjection\\ContainerInterface'); $userRepository = $this->prophesize('AppBundle\\Entity\\UserRepository'); $user = $this->prophesize('AppBundle\\Entity\\User'); $container->get('app.entity.user_repository')->willReturn($userRepository); $userRepository->find(1)->willReturn($user); $this->command->setContainer($container->reveal()); $this->commandTester->execute(['command' => $this->command->getName(), 'user_id' => 1, '--new' => true]); }
public function testAddToNewRelease() { $outputPath = __DIR__ . '/../../_output/changelog.json'; @unlink($outputPath); $this->commandTester->execute(['release' => '1.0.0', 'type' => 'flip-flopped', 'change' => 'something', '--config' => __DIR__ . '/../../resources/changelog.config.php']); $this->assertFileExists($outputPath); $jsonContent = json_decode(file_get_contents($outputPath), true); $this->assertFalse(empty($jsonContent['releases']['1.0.0']['changes']['flip-flopped'])); $this->assertTrue(in_array('something', $jsonContent['releases']['1.0.0']['changes']['flip-flopped'])); }
public function testExecute() { $this->commandTester->execute(['--output' => __DIR__ . '/_files/output/modules.csv']); $this->assertEquals('Report successfully processed.' . PHP_EOL, $this->commandTester->getDisplay()); $fileContents = file_get_contents(__DIR__ . '/_files/output/modules.csv'); $this->assertContains(',All,Hard,Soft' . PHP_EOL . '"Total number of dependencies",2,2,0' . PHP_EOL, $fileContents); $this->assertContains('"Dependencies for each module:",All,Hard,Soft' . PHP_EOL, $fileContents); $this->assertContains('magento/module-a,1,1,0' . PHP_EOL . '" -- magento/module-b",,1,0' . PHP_EOL, $fileContents); $this->assertContains('magento/module-b,1,1,0' . PHP_EOL . '" -- magento/module-a",,1,0' . PHP_EOL, $fileContents); }
/** @test */ public function it_opens_a_dialog_to_select_the_entity_and_count_if_no_entity_given() { /** @var SymfonyQuestionHelper $question */ $question = $this->command->getHelper('question'); $question->setInputStream($this->getInputStream("1\n5\n")); $this->commandTester->execute(['command' => $this->command->getName()]); $count = $this->getDatabaseCount(App::class, []); $this->assertEquals(5, $count); $this->assertContains(sprintf('%s seeded.', App::class), $this->commandTester->getDisplay()); }
public function testRecursiveSearch() { $app = new Application(); $app->add($this->command); $tester = new CommandTester($app->find('testable-command')); $tester->execute(['command' => 'testable-command', '--config-dir' => realpath(__DIR__ . '/../../../../Fixtures/recursive'), '--recursive' => true]); $this->assertEquals('3', $tester->getDisplay()); $tester->execute(['command' => 'testable-command', '--config-dir' => realpath(__DIR__ . '/../../../../Fixtures/recursive'), '--recursive' => false]); $this->assertEquals('1', $tester->getDisplay()); }