Skip to content

Commit

Permalink
Merge pull request #52 from Miljar/issue/51/cli-names-use-limit
Browse files Browse the repository at this point in the history
Use --limit option in event-store:projection:names command
  • Loading branch information
UFOMelkor authored Jul 25, 2018
2 parents d4d0051 + ef7c95f commit 5f0aeca
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Command/ProjectionNamesCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
if (\count($names) > $offset) {
$projectionNames = $projectionManager->$method($filter, $limit - (\count($names) - $offset));
} else {
$projectionNames = $projectionManager->$method($filter);
$projectionNames = $projectionManager->$method($filter, $limit);
}

foreach ($projectionNames as $projectionName) {
Expand Down
91 changes: 91 additions & 0 deletions test/Command/ProjectionNamesCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,95 @@ public static function provideProjectionNames(): array
'read_model_projection' => ['black_hole_read_model_projection'],
];
}

/**
* @test
* @dataProvider provideLimitOptions
*/
public function it_lists_correct_amount_of_projections(int $amountToGenerate, int $limit = null): void
{
$kernel = static::createKernel();
$kernel->boot();

/** @var InMemoryProjectionManager $manager */
$manager = $kernel->getContainer()->get('test.prooph_event_store.projection_manager.main_projection_manager');

$projectionNames = $this->projectionNameGenerator($amountToGenerate);

foreach ($projectionNames as $projectionName) {
$manager->createProjection($projectionName);
}

$app = new Application($kernel);
$command = $app->find('event-store:projection:names');

if (null === $limit) {
$limit = $command->getDefinition()->getOption('limit')->getDefault();
}

$commandTester = new CommandTester($command);
$commandTester->execute(['--limit' => $limit]);
$this->assertContains('main_projection_manager', $commandTester->getDisplay());

$expectedProjectionNames = \array_slice($projectionNames, 0, $limit);
$unexpectedProjectionNames = \array_slice($projectionNames, $limit);
foreach ($expectedProjectionNames as $projectionName) {
$this->assertContains($projectionName, $commandTester->getDisplay());
}
foreach ($unexpectedProjectionNames as $projectionName) {
$this->assertNotContains($projectionName, $commandTester->getDisplay());
}
}

/**
* Generates an array of projection names, each suffixed with a zero-padded number
*
* Example:
* [
* 'black_hole_read_model_projection_01',
* 'black_hole_read_model_projection_02',
* 'black_hole_read_model_projection_03',
* 'black_hole_read_model_projection_04',
* 'black_hole_read_model_projection_05',
* 'black_hole_read_model_projection_06',
* 'black_hole_read_model_projection_07',
* 'black_hole_read_model_projection_08',
* 'black_hole_read_model_projection_09',
* 'black_hole_read_model_projection_10',
* 'black_hole_read_model_projection_11',
* ...
* ]
*
* @param int $amountToGenerate
* @param string $prefix
*/
private function projectionNameGenerator(
int $amountToGenerate,
string $prefix = 'black_hole_read_model_projection_'
): array {
return \array_map(
function ($value) use ($amountToGenerate, $prefix) {
return $prefix . \str_pad((string) $value, \strlen((string) $amountToGenerate), '0', \STR_PAD_LEFT);
},
\range(1, $amountToGenerate)
);
}

public function provideLimitOptions(): array
{
return [
[
25,
null,
],
[
25,
5,
],
[
25,
25,
],
];
}
}

0 comments on commit 5f0aeca

Please sign in to comment.