/** * @test */ public function shouldExecuteConsumeCommand() { $application = new Application('prod'); // Add command $command = new TestableConsumerCommand('fake:consumer', $this->getMockForAbstractClass('Boot\\RabbitMQ\\Consumer\\AbstractConsumer', [$this->queueTemplate], 'MockConsumer'), $this->createLogger()); $application->add($command); // Create command tester $commandTester = new CommandTester($command); // Execute consumer $commandTester->execute(['command' => $command->getName()]); // Should have declared the queue once $this->assertEquals(1, $this->basicQueueDeclareInvocations->getInvocationCount()); $args = $this->basicQueueDeclareInvocations->getInvocations()[0]->parameters; // Make sure that the queue name is correct $this->assertEquals('some_test_queue', $args[0]); // Make sure that the queue is durable $this->assertTrue($args[2], 'The queue is not durable!'); // Make sure that the queue is not automatically deleted $this->assertFalse($args[4], 'The queue is automatically deleted!'); // Should have declared the quality of service once $this->assertEquals(1, $this->basicQosInvocations->getInvocationCount()); // Should have declared the quality of service once $this->assertEquals(1, $this->basicConsumeInvocations->getInvocationCount()); // The wait method should have been invoked once $this->assertEquals(1, $this->waitInvocations->getInvocationCount()); // Should have status code 0 $this->assertEquals(0, $commandTester->getStatusCode()); }
/** * @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))); }
/** * @test */ public function it_displays_characters_residing_in_a_supplied_script() { $repository = new InMemoryRepository(); $codepoint = Codepoint::fromInt(97); $script = Script::fromValue(Script::LATIN); $character = $this->buildCharacterWithCodepoint($codepoint, null, null, $script); $characters = Collection::fromArray([$character]); $repository->addMany($characters); $this->container['repository.test'] = $repository; $this->commandTester->execute(['command' => PropertiesCommand::COMMAND_NAME, '--from' => 'test', 'property-type' => PropertiesCommand::PROPERTY_SCRIPT, 'value' => $script->getValue()]); $output = $this->commandTester->getDisplay(); $statusCode = $this->commandTester->getStatusCode(); ha::assertThat('output', $output, hm::containsString('U+61:')); ha::assertThat('status code', $statusCode, hm::is(hm::identicalTo(0))); }
public function testExecute() { $application = new Application($this->httpClient->getKernel()); $application->add(new InitKillQueueCommand()); /** @var InitKillQueueCommand $command */ $command = $application->find('syrup:queue:kill-init'); $commandTester = new CommandTester($command); $commandTester->execute(['command' => $command->getName()]); $this->assertEquals(0, $commandTester->getStatusCode()); /** @var QueueFactory $queueFactory */ $queueFactory = $this->httpClient->getContainer()->get('syrup.queue_factory'); $queueId = 'syrup_kill_' . str_replace('.keboola.com', '', gethostname()); $queueService = $queueFactory->get($queueId); $this->assertInstanceOf('Keboola\\Syrup\\Service\\Queue\\QueueService', $queueService); $snsConfig = $this->httpClient->getContainer()->getParameter('sns'); $snsClient = new SnsClient(['credentials' => ['key' => $snsConfig['key'], 'secret' => $snsConfig['secret']], 'region' => isset($snsConfig['region']) ? $snsConfig['region'] : 'us-east-1', 'version' => '2010-03-31']); $subscriptions = $snsClient->listSubscriptionsByTopic(['TopicArn' => $snsConfig['topic_arn']]); $ssArr = $subscriptions->get('Subscriptions'); $ourSS = null; foreach ($ssArr as $ss) { if (false !== strstr($ss['Endpoint'], $queueId)) { $ourSS = $ss; break; } } $this->assertNotNull($ourSS); $this->assertEquals('sqs', $ourSS['Protocol']); $this->assertEquals($snsConfig['topic_arn'], $ourSS['TopicArn']); }
/** * Test audit table is created correctly. */ public function test01() { $application = new Application(); $application->add(new AuditCommand()); /** @var AuditCommand $command */ $command = $application->find('audit'); $command->setRewriteConfigFile(false); $commandTester = new CommandTester($command); $commandTester->execute(['command' => $command->getName(), 'config file' => __DIR__ . '/config/audit.json']); $this->assertSame(0, $commandTester->getStatusCode()); // Reconnect to DB. StaticDataLayer::connect('localhost', 'test', 'test', self::$dataSchema); $sql = sprintf(' select COLUMN_NAME as column_name , COLUMN_TYPE as column_type , IS_NULLABLE as is_nullable , CHARACTER_SET_NAME as character_set_name , COLLATION_NAME as collation_name from information_schema.COLUMNS where TABLE_SCHEMA = %s and TABLE_NAME = %s order by ORDINAL_POSITION', StaticDataLayer::quoteString(self::$auditSchema), StaticDataLayer::quoteString('AUT_COMPANY')); $rows = StaticDataLayer::executeRows($sql); $expected = [['column_name' => 'audit_timestamp', 'column_type' => 'timestamp', 'is_nullable' => 'NO', 'character_set_name' => null, 'collation_name' => null], ['column_name' => 'audit_statement', 'column_type' => "enum('INSERT','DELETE','UPDATE')", 'is_nullable' => 'NO', 'character_set_name' => 'ascii', 'collation_name' => 'ascii_general_ci'], ['column_name' => 'audit_type', 'column_type' => "enum('OLD','NEW')", 'is_nullable' => 'NO', 'character_set_name' => 'ascii', 'collation_name' => 'ascii_general_ci'], ['column_name' => 'audit_uuid', 'column_type' => 'bigint(20) unsigned', 'is_nullable' => 'NO', 'character_set_name' => null, 'collation_name' => null], ['column_name' => 'audit_rownum', 'column_type' => 'int(10) unsigned', 'is_nullable' => 'NO', 'character_set_name' => null, 'collation_name' => null], ['column_name' => 'audit_ses_id', 'column_type' => 'int(10) unsigned', 'is_nullable' => 'YES', 'character_set_name' => null, 'collation_name' => null], ['column_name' => 'audit_usr_id', 'column_type' => 'int(10) unsigned', 'is_nullable' => 'YES', 'character_set_name' => null, 'collation_name' => null], ['column_name' => 'cmp_id', 'column_type' => 'smallint(5) unsigned', 'is_nullable' => 'YES', 'character_set_name' => null, 'collation_name' => null], ['column_name' => 'cmp_abbr', 'column_type' => 'varchar(15)', 'is_nullable' => 'YES', 'character_set_name' => 'utf8', 'collation_name' => 'utf8_general_ci'], ['column_name' => 'cmp_label', 'column_type' => 'varchar(20)', 'is_nullable' => 'YES', 'character_set_name' => 'ascii', 'collation_name' => 'ascii_general_ci']]; $this->assertEquals($expected, $rows); }
public function testCreateIndex() { $command = $this->application->find('syrup:create-index'); $commandTester = new CommandTester($command); $commandTester->execute(['-d' => null]); $this->assertEquals(0, $commandTester->getStatusCode()); }
public function testRunJobWithMaintenance() { self::$kernel->getContainer()->set('syrup.job_executor', new MaintenanceExecutor()); $jobId = $this->jobMapper->create($this->createJob()); $this->commandTester->execute(['jobId' => $jobId]); $this->assertEquals(JobCommand::STATUS_LOCK, $this->commandTester->getStatusCode()); }
/** * @expectedException InvalidArgumentException * @expectedExceptionMessage Method should be one of: load, unload */ public function testSeedCommand() { $command = $this->application->find('testseeds:country'); $commandTester = new CommandTester($command); $commandTester->execute(['command' => $command->getName(), 'method' => 'nonexistant']); $this->assertEquals($commandTester->getStatusCode(), 1); }
public function test01() { $application = new AuditApplication(); $command = $application->find('about'); $commandTester = new CommandTester($command); $commandTester->execute(['command' => $command->getName()]); $this->assertSame(0, $commandTester->getStatusCode()); }
public function testBasic() { $this->client->expects($this->once())->method('query')->with('PUT', '/api/vhosts/%2F', []); $tester = new CommandTester($this->command); $tester->execute(['configFile' => 'Parser/fixture/config.yml']); $this->assertEquals("<>[info] Create vhost: /\n", $tester->getDisplay(true)); $this->assertEquals(0, $tester->getStatusCode()); }
public function testShouldNotDownloadTheFileAgainIfAlreadyExistsOutputOnlyFilePathInNonInteractiveMode() { $this->command->setDownloader(new Downloader(__DIR__ . '/Fixtures/vendor/bin')); $this->mockUserInput("\n"); $this->tester->execute(['command' => $this->command->getName(), 'version' => '5.67.8'], ['interactive' => false]); $this->assertEquals(realpath(__DIR__ . '/Fixtures/vendor/bin/selenium-server-standalone-5.67.8.jar') . "\n", $this->tester->getDisplay()); $this->assertSame(0, $this->tester->getStatusCode()); }
/** * @dataProvider dataForTestExecute */ public function testExecute($name, $yell, $expected) { $command = new GreetCommand(); $tester = new CommandTester($command); $tester->execute(['name' => $name, '--yell' => $yell]); $this->assertSame(0, $tester->getStatusCode()); $this->assertSame($expected, $tester->getDisplay()); }
/** * @test */ public function execute_creates_a_server_with_project_and_scripts() { $mersey = $this->getLocalMerseyMock([['name' => 'testing', 'displayName' => 'Test Display', 'username' => 'testuser', 'hostname' => 'example.com', 'sshKey' => 'special_key', 'port' => 3000, 'projects' => [['name' => 'testproject', 'root' => '/project/root', 'scripts' => [['name' => 'testscript', 'description' => 'A Script', 'command' => 'my script']]]]]]); $command = $this->getApplication($mersey)->find('add'); $this->mockAnswersUsingArray($command, [['server name/alias', 'testing'], ['server display name', 'Test Display'], ['SSH username', 'testuser'], ['hostname', 'example.com'], ['optional settings', 'y'], ['ssh key', 'special_key'], ['port', 3000], ['define a project', 'y'], ['project name', 'testproject'], ['project root', '/project/root'], ['scripts to the project', 'y'], ['script name', 'testscript'], ['script description', 'A Script'], ['script command', 'my script'], ['another script', 'n'], ['another project', 'n']]); $tester = new CommandTester($command); $tester->execute(['command' => $command->getName()]); $this->assertSame(0, $tester->getStatusCode(), 'Exit code is showing an error'); }
/** * Consume a queue for a specific amount of messages. * * @param string $vhost * @param string[] $queues * @param int $amount */ public function consume($vhost, array $queues, $amount = 1) { $command = $this->getApplication()->find('amqp:consume'); $tester = new CommandTester($command); $tester->execute(['--amount' => $amount, 'vhost' => $vhost, 'queues' => $queues]); if ($tester->getStatusCode() !== 0) { throw new \RuntimeException('amqp:consume failed to execute correctly'); } }
/** * @test */ public function execute_opens_server_config() { $mersey = $this->getMerseyMock(); $mersey->shouldReceive('getServersConfig')->andReturn('server-config.json'); $command = $this->getApplication($mersey)->find('edit'); $tester = new CommandTester($command); $tester->execute(['command' => $command->getName()], ['verbosity' => Output::VERBOSITY_DEBUG]); $this->assertContains('open server-config.json', $tester->getDisplay()); $this->assertSame(0, $tester->getStatusCode(), 'Exit code is showing an error'); }
public function testCreateJob() { $command = $this->application->find('syrup:job:create'); $commandTester = new CommandTester($command); $commandTester->execute(['token' => $this->storageApiToken, 'cmd' => 'run']); $this->assertEquals(0, $commandTester->getStatusCode()); $jobId = intval(str_replace('Created job id ', '', $commandTester->getDisplay())); $job = $this->jobMapper->get($jobId); $this->assertEquals($job->getStatus(), Job::STATUS_WAITING); }
public function testFullFunctionalCommandCheckOnly() { $application = new LicenserApplication(); $command = $application->find('licenser'); $commandTester = new CommandTester($command); $commandTester->execute(['source' => realpath($this->tempDir), '--check-only' => true]); self::assertContains('[WARN] 4 file(s) should be updated.', $commandTester->getDisplay()); self::assertContains('4 file(s) has been processed', $commandTester->getDisplay()); self::assertEquals(1, $commandTester->getStatusCode()); }
/** * Tests if command is being executed. */ public function testExecute() { $app = new Application(); $app->add($this->getCommand()); $command = $app->find('ongr:es:cache:clear'); $tester = new CommandTester($command); $tester->execute(['command' => $command->getName()]); $this->assertContains('Elasticsearch index cache has been cleared for manager named `default`', $tester->getDisplay()); $this->assertEquals(0, $tester->getStatusCode(), 'Status code should be zero.'); }
public function testAccountCommandAdmin() { $kernel = $this->createKernel(); $kernel->boot(); $application = new Application($kernel); $application->add(new Command\AccountCommand()); $command = $application->find('aimeos:account'); $commandTester = new CommandTester($command); $commandTester->execute(array('command' => $command->getName(), 'site' => 'unittest', 'email' => '*****@*****.**', '--password' => 'test', '--admin' => true)); $this->assertEquals(0, $commandTester->getStatusCode()); }
public function testSetupCommand() { $kernel = $this->createKernel(); $kernel->boot(); $application = new Application($kernel); $application->add(new Command\SetupCommand()); $command = $application->find('aimeos:setup'); $commandTester = new CommandTester($command); $commandTester->execute(array('command' => $command->getName(), 'site' => 'unittest', '--option' => 'setup/default/demo:0')); $this->assertEquals(0, $commandTester->getStatusCode()); }
/** * @test */ public function execute_connects_to_a_server_and_runs_project_script() { $mersey = $this->getMerseyMock(); $mersey->shouldReceive('getGlobalScripts')->andReturn([]); $commandInstance = $this->createCommand($mersey, $this->getTestServer('with-script')); $command = $this->getApplication($commandInstance)->find('testserver'); $tester = new CommandTester($command); $tester->execute(['command' => $command->getName(), 'project' => 'testproject', 'script' => 'testscript'], ['verbosity' => Output::VERBOSITY_DEBUG]); $this->assertContains("cd /home/testserver/testproject; running script on server;", $tester->getDisplay()); $this->assertSame(0, $tester->getStatusCode(), 'Exit code is showing an error'); }
/** * @test */ public function it_transfers_characters_from_one_repository_to_another() { $codepoint = Codepoint::fromInt(1); $character = $this->buildCharacterWithCodepoint($codepoint); $characters = Collection::fromArray([$character]); $source = new InMemoryRepository(); $source->addMany($characters); $destination = new InMemoryRepository(); $this->container['repository.test-source'] = $source; $this->container['repository.test-destination'] = $destination; ha::assertThat(count($source), hm::is(hm::identicalTo(1))); ha::assertThat(count($destination), hm::is(hm::identicalTo(0))); $this->commandTester->execute(['command' => RepositoryTransferCommand::COMMAND_NAME, 'from' => 'test-source', 'to' => 'test-destination']); ha::assertThat(count($source), hm::is(hm::identicalTo(1))); ha::assertThat(count($destination), hm::is(hm::identicalTo(1))); $output = $this->commandTester->getDisplay(); $statusCode = $this->commandTester->getStatusCode(); ha::assertThat('output', $output, hm::containsString('Database Generated')); ha::assertThat('status code', $statusCode, hm::is(hm::identicalTo(0))); }
public function testJobsCommand() { $kernel = $this->createKernel(); $kernel->boot(); $application = new Application($kernel); $application->add(new Command\JobsCommand()); $command = $application->find('aimeos:jobs'); $commandTester = new CommandTester($command); $commandTester->execute(array('command' => $command->getName(), 'site' => 'unittest', 'jobs' => 'catalog/index/rebuild')); $this->assertEquals(0, $commandTester->getStatusCode()); }
public function testCacheCommand() { $kernel = $this->createKernel(); $kernel->boot(); $application = new Application($kernel); $application->add(new Command\CacheCommand()); $command = $application->find('aimeos:cache'); $commandTester = new CommandTester($command); $commandTester->execute(array('command' => $command->getName(), 'site' => 'unittest')); $this->assertEquals(0, $commandTester->getStatusCode()); }
public function test01() { $application = new Application(); $application->add(new AuditCommand()); /** @var AuditCommand $command */ $command = $application->find('audit'); $command->setRewriteConfigFile(false); $commandTester = new CommandTester($command); $commandTester->execute(['command' => $command->getName(), 'config file' => __DIR__ . '/config/audit.json']); $this->assertSame(0, $commandTester->getStatusCode()); }
public function test_paralle_command_exit_code_fail() { $filter = $this->getFilterMock(); $runner = $this->getRunnerMock(25); $application = new Application(); $commandInstance = new ParallelCommand($filter->reveal(), $runner->reveal(), $this->getFakeConfig()); $application->add($commandInstance); $command = $application->find('run'); $commandTester = new CommandTester($command); $commandTester->execute(array('command' => $command->getName())); $this->assertEquals(25, $commandTester->getStatusCode()); }
/** * @return string */ public function testExecute() { $kernel = static::createKernel(); $kernel->boot(); $application = new Application($kernel); $application->add(new ClientCreateCommand()); $command = $application->find(ClientCreateCommand::$commandName); $commandTester = new CommandTester($command); $commandTester->execute(['name' => $this->clientName, '--redirect-uri' => ['/'], '--grant-type' => [OAuth2::GRANT_TYPE_CLIENT_CREDENTIALS]]); $this->assertEquals(0, $commandTester->getStatusCode()); return $commandTester->getDisplay(); }
/** * @todo Separate to tests for ExecutionLoop */ public function testShouldExitSuccessfullyIfNoProcessArePreparedOrQueued() { $seleniumAdapterMock = $this->getSeleniumAdapterMock(); $processSetMock = $this->getMockBuilder(ProcessSet::class)->disableOriginalConstructor()->getMock(); $processSetMock->expects($this->any())->method('count')->willReturn(333); $creatorMock = $this->getMockBuilder(ProcessSetCreator::class)->disableOriginalConstructor()->getMock(); $creatorMock->expects($this->once())->method('createFromFiles')->willReturn($processSetMock); $this->command->setSeleniumAdapter($seleniumAdapterMock); $this->command->setProcessSetCreator($creatorMock); $this->tester->execute(['command' => $this->command->getName(), 'environment' => 'staging', 'browser' => 'firefox', '--tests-dir' => __DIR__ . '/Fixtures/DummyTests']); $this->assertContains('No tasks left, exiting the execution loop...', $this->tester->getDisplay()); $this->assertSame(0, $this->tester->getStatusCode()); }
/** * @dataProvider providerExecute */ public function testExecute($configFile, $expectedOutput, $expectedStatusCode, $exception = null, $exceptionMessage = null) { if ($exception) { $this->setExpectedException($exception, $exceptionMessage); } $application = new ConsoleApplication($this->silex, 'Fakery Generator Test Application', 'N/A'); $application->add(new ValidateCommand()); $command = $application->find('fakery:validate'); $commandTester = new CommandTester($command); $commandTester->execute(['command' => $command->getName(), 'config' => static::$fixtures . $configFile]); $this->assertEquals($expectedStatusCode, $commandTester->getStatusCode()); $this->assertRegExp('/' . $expectedOutput . '/', $commandTester->getDisplay()); }
public function testCleanup() { // job execution test $jobId = $this->jobMapper->create($this->createJob()); $command = $this->application->find('syrup:job:cleanup'); $commandTester = new CommandTester($command); $commandTester->execute(['jobId' => $jobId]); $this->assertEquals(0, $commandTester->getStatusCode()); $job = $this->jobMapper->get($jobId); $this->assertEquals($job->getStatus(), Job::STATUS_TERMINATED); $this->assertEquals('Job has been terminated&cleared', $job->getResult()['message']); $this->assertNotNull($job->getEndTime()); $this->assertNotNull($job->getDurationSeconds()); }