Skip to content
This repository has been archived by the owner on Sep 20, 2019. It is now read-only.

Commit

Permalink
allow leading slashes when selecting projectors (closes #53)
Browse files Browse the repository at this point in the history
  • Loading branch information
freekmurze committed Jul 12, 2018
1 parent f5e2a6a commit d1329d8
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 2 deletions.
5 changes: 4 additions & 1 deletion src/Console/Concerns/SelectsProjectors.php
Expand Up @@ -11,14 +11,17 @@ trait SelectsProjectors
public function selectsProjectors(array $projectorClassNames, string $allProjectorsWarning): ?Collection
{
if (count($projectorClassNames ?? []) === 0) {
if (! $confirmed = $this->confirm($allProjectorsWarning)) {
if (!$confirmed = $this->confirm($allProjectorsWarning)) {
return null;
}

return Projectionist::getProjectors();
}

return collect($projectorClassNames)
->map(function (string $projectorName) {
return ltrim($projectorName, '\\');
})
->map(function (string $projectorName) {
if (! $projector = $this->projectionist->getProjector($projectorName)) {
throw new Exception("Projector {$projectorName} not found. Did you register it?");
Expand Down
2 changes: 1 addition & 1 deletion src/Console/ListCommand.php
Expand Up @@ -77,7 +77,7 @@ protected function list(Collection $projectors): void
return [
$projector->getName(),
$this->getLastProcessedEventId($projector),
optional($this->getLastEventProcessedAt($projector))->format('Y-m-d H:i:s') ?? '',
optional($this->getLastEventProcessedAt($projector))->format('Y-m-d H:i:s') ?? '/',
];
})
->toArray();
Expand Down
1 change: 1 addition & 0 deletions src/EventSerializers/JsonEventSerializer.php
Expand Up @@ -5,6 +5,7 @@
use Spatie\EventProjector\ShouldBeStored;
use Symfony\Component\Serializer\Encoder\JsonEncoder;
use Symfony\Component\Serializer\Normalizer\ObjectNormalizer;
use Symfony\Component\Serializer\Normalizer\PropertyNormalizer;
use Symfony\Component\Serializer\Serializer as SymfonySerializer;

class JsonEventSerializer implements EventSerializer
Expand Down
13 changes: 13 additions & 0 deletions tests/Console/RebuildCommandTest.php
Expand Up @@ -37,6 +37,19 @@ public function it_can_rebuild_a_projector()
$this->assertCount(1, ProjectorStatus::get());
}

/** @test */
public function it_allows_leading_slashes()
{
Projectionist::addProjector(ResettableProjector::class);

$this->artisan('event-projector:rebuild', [
'projector' => ['\\' . ResettableProjector::class],
]);

$this->assertSeeInConsoleOutput('Projector(s) rebuild!');

}

/** @test */
public function a_projector_status_will_not_be_created_after_a_projector_is_rebuild_without_any_events()
{
Expand Down

0 comments on commit d1329d8

Please sign in to comment.