From dfe05127e4df1bc12a22ad18cb94d8c84ef3c4de Mon Sep 17 00:00:00 2001 From: David Badura Date: Thu, 10 Aug 2023 19:43:54 +0200 Subject: [PATCH] remove old projection commands --- src/Console/Command/ProjectionCommand.php | 71 ------- .../Command/ProjectionCreateCommand.php | 50 ----- src/Console/Command/ProjectionDropCommand.php | 50 ----- .../Command/ProjectionRebuildCommand.php | 118 ----------- .../Command/ProjectionCreateCommandTest.php | 68 ------- .../Command/ProjectionDropCommandTest.php | 68 ------- .../Command/ProjectionRebuildCommandTest.php | 187 ------------------ 7 files changed, 612 deletions(-) delete mode 100644 src/Console/Command/ProjectionCommand.php delete mode 100644 src/Console/Command/ProjectionCreateCommand.php delete mode 100644 src/Console/Command/ProjectionDropCommand.php delete mode 100644 src/Console/Command/ProjectionRebuildCommand.php delete mode 100644 tests/Unit/Console/Command/ProjectionCreateCommandTest.php delete mode 100644 tests/Unit/Console/Command/ProjectionDropCommandTest.php delete mode 100644 tests/Unit/Console/Command/ProjectionRebuildCommandTest.php diff --git a/src/Console/Command/ProjectionCommand.php b/src/Console/Command/ProjectionCommand.php deleted file mode 100644 index c8abc40f..00000000 --- a/src/Console/Command/ProjectionCommand.php +++ /dev/null @@ -1,71 +0,0 @@ - */ - protected function projectors(mixed $projectionOption): array - { - $normalizedProjectionOption = $this->normalizeProjectionOption($projectionOption); - - if (!$normalizedProjectionOption) { - return $this->projectorRepository->projectors(); - } - - return array_values( - array_filter( - [...$this->projectorRepository->projectors()], - static fn (Projector $projection): bool => in_array($projection::class, $normalizedProjectionOption) - ), - ); - } - - /** @return non-empty-array>|null */ - private function normalizeProjectionOption(mixed $option): array|null - { - if (is_string($option)) { - $option = [$option]; - } - - if (!is_array($option)) { - throw new InvalidArgumentGiven($option, 'class-string<' . Projector::class . '>[]'); - } - - $result = []; - - foreach ($option as $entry) { - if (!is_string($entry) || !is_subclass_of($entry, Projector::class)) { - throw new InvalidArgumentGiven($entry, 'class-string<' . Projector::class . '>'); - } - - $result[] = $entry; - } - - if ($result === []) { - return null; - } - - return $result; - } -} diff --git a/src/Console/Command/ProjectionCreateCommand.php b/src/Console/Command/ProjectionCreateCommand.php deleted file mode 100644 index d301f4d6..00000000 --- a/src/Console/Command/ProjectionCreateCommand.php +++ /dev/null @@ -1,50 +0,0 @@ -addOption('projection', 'p', InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, 'run only for specific projections [FQCN]'); - } - - protected function execute(InputInterface $input, OutputInterface $output): int - { - $console = new OutputStyle($input, $output); - - (new ProjectorHelper($this->projectorResolver))->createProjection( - ...$this->projectors( - $input->getOption('projection'), - ), - ); - - $console->success('projection created'); - - return 0; - } -} diff --git a/src/Console/Command/ProjectionDropCommand.php b/src/Console/Command/ProjectionDropCommand.php deleted file mode 100644 index eaefb95a..00000000 --- a/src/Console/Command/ProjectionDropCommand.php +++ /dev/null @@ -1,50 +0,0 @@ -addOption('projection', 'p', InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, 'run only for specific projections [FQCN]'); - } - - protected function execute(InputInterface $input, OutputInterface $output): int - { - $console = new OutputStyle($input, $output); - - (new ProjectorHelper($this->projectorResolver))->dropProjection( - ...$this->projectors( - $input->getOption('projection'), - ), - ); - - $console->success('projection deleted'); - - return 0; - } -} diff --git a/src/Console/Command/ProjectionRebuildCommand.php b/src/Console/Command/ProjectionRebuildCommand.php deleted file mode 100644 index af002e1d..00000000 --- a/src/Console/Command/ProjectionRebuildCommand.php +++ /dev/null @@ -1,118 +0,0 @@ -addOption('recreate', 'r', InputOption::VALUE_NONE, 'drop and create projections') - ->addOption( - 'until', - 'u', - InputOption::VALUE_REQUIRED, - 'create the projection up to a point in time [2017-02-02 12:00]', - ) - ->addOption( - 'projection', - 'p', - InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, - 'run only for specific projections [FQCN]', - ); - } - - protected function execute(InputInterface $input, OutputInterface $output): int - { - $console = new OutputStyle($input, $output); - - $projectors = $this->projectors($input->getOption('projection')); - - if (InputHelper::bool($input->getOption('recreate'))) { - (new ProjectorHelper($this->projectorResolver))->dropProjection( - ...$projectors, - ); - - $console->success('projection schema deleted'); - - (new ProjectorHelper($this->projectorResolver))->createProjection( - ...$projectors, - ); - - $console->success('projection schema created'); - } - - $until = InputHelper::nullableString($input->getOption('until')); - - $middlewares = []; - - if (is_string($until)) { - try { - $date = new DateTimeImmutable($until); - } catch (Throwable) { - $console->error(sprintf('date "%s" not supported. the format should be "2017-02-02 12:00"', $until)); - - return 1; - } - - $middlewares[] = new UntilEventMiddleware($date); - } - - $pipeline = new Pipeline( - new StoreSource($this->store), - new ProjectorRepositoryTarget( - new InMemoryProjectorRepository($projectors), - $this->projectorResolver, - ), - $middlewares, - ); - - $console->warning('rebuild projections'); - $console->progressStart($pipeline->count()); - - $pipeline->run(static function () use ($console): void { - $console->progressAdvance(); - }); - - $console->progressFinish(); - $console->success('finish'); - - return 0; - } -} diff --git a/tests/Unit/Console/Command/ProjectionCreateCommandTest.php b/tests/Unit/Console/Command/ProjectionCreateCommandTest.php deleted file mode 100644 index ae1b6e06..00000000 --- a/tests/Unit/Console/Command/ProjectionCreateCommandTest.php +++ /dev/null @@ -1,68 +0,0 @@ -run($input, $output); - - self::assertSame(0, $exitCode); - - self::assertTrue($projectionA->createCalled); - self::assertTrue($projectionB->createCalled); - - $content = $output->fetch(); - - self::assertStringContainsString('[OK] projection created', $content); - } - - public function testSpecificProjection(): void - { - $projectionA = new DummyProjection(); - $projectionB = new Dummy2Projection(); - $repository = new InMemoryProjectorRepository([$projectionA, $projectionB]); - - $command = new ProjectionCreateCommand($repository); - - $input = new ArrayInput(['--projection' => DummyProjection::class]); - $output = new BufferedOutput(); - - $exitCode = $command->run($input, $output); - - self::assertSame(0, $exitCode); - self::assertTrue($projectionA->createCalled); - self::assertFalse($projectionB->createCalled); - - $content = $output->fetch(); - - self::assertStringContainsString('[OK] projection created', $content); - } -} diff --git a/tests/Unit/Console/Command/ProjectionDropCommandTest.php b/tests/Unit/Console/Command/ProjectionDropCommandTest.php deleted file mode 100644 index e5bd10c5..00000000 --- a/tests/Unit/Console/Command/ProjectionDropCommandTest.php +++ /dev/null @@ -1,68 +0,0 @@ -run($input, $output); - - self::assertSame(0, $exitCode); - - self::assertTrue($projectionA->dropCalled); - self::assertTrue($projectionB->dropCalled); - - $content = $output->fetch(); - - self::assertStringContainsString('[OK] projection deleted', $content); - } - - public function testSpecificProjection(): void - { - $projectionA = new DummyProjection(); - $projectionB = new Dummy2Projection(); - $repository = new InMemoryProjectorRepository([$projectionA, $projectionB]); - - $command = new ProjectionDropCommand($repository); - - $input = new ArrayInput(['--projection' => DummyProjection::class]); - $output = new BufferedOutput(); - - $exitCode = $command->run($input, $output); - - self::assertSame(0, $exitCode); - self::assertTrue($projectionA->dropCalled); - self::assertFalse($projectionB->dropCalled); - - $content = $output->fetch(); - - self::assertStringContainsString('[OK] projection deleted', $content); - } -} diff --git a/tests/Unit/Console/Command/ProjectionRebuildCommandTest.php b/tests/Unit/Console/Command/ProjectionRebuildCommandTest.php deleted file mode 100644 index aed9d29e..00000000 --- a/tests/Unit/Console/Command/ProjectionRebuildCommandTest.php +++ /dev/null @@ -1,187 +0,0 @@ -stream = new ArrayStream([ - new Message( - new ProfileCreated(ProfileId::fromString('1'), Email::fromString('info@patchlevel.de')), - ), - new Message( - new ProfileCreated(ProfileId::fromString('1'), Email::fromString('info@patchlevel.de')), - ), - new Message( - new ProfileCreated(ProfileId::fromString('1'), Email::fromString('info@patchlevel.de')), - ), - new Message( - new ProfileCreated(ProfileId::fromString('1'), Email::fromString('info@patchlevel.de')), - ), - new Message( - new ProfileCreated(ProfileId::fromString('1'), Email::fromString('info@patchlevel.de')), - ), - ]); - - $this->criteria = (new CriteriaBuilder())->fromIndex(0)->build(); - } - - public function testSuccessful(): void - { - $projectionA = new DummyProjection(); - $repository = new InMemoryProjectorRepository([$projectionA]); - - $store = $this->prophesize(Store::class); - $store->count($this->criteria)->willReturn(5); - $store->load($this->criteria)->willReturn($this->stream); - - $command = new ProjectionRebuildCommand( - $store->reveal(), - $repository, - ); - - $input = new ArrayInput([]); - $output = new BufferedOutput(); - - $exitCode = $command->run($input, $output); - - self::assertSame(0, $exitCode); - - $content = $output->fetch(); - - self::assertInstanceOf(Message::class, $projectionA->handledMessage); - self::assertInstanceOf(ProfileCreated::class, $projectionA->handledMessage->event()); - - self::assertStringContainsString('[WARNING] rebuild projections', $content); - self::assertStringContainsString('[OK] finish', $content); - } - - public function testSpecificProjection(): void - { - $store = $this->prophesize(Store::class); - $store->count($this->criteria)->willReturn(5); - $store->load($this->criteria)->willReturn($this->stream); - - $projectionA = new DummyProjection(); - $projectionB = new Dummy2Projection(); - $repository = new InMemoryProjectorRepository([$projectionA, $projectionB]); - - $command = new ProjectionRebuildCommand( - $store->reveal(), - $repository, - ); - - $input = new ArrayInput(['--projection' => $projectionA::class]); - $output = new BufferedOutput(); - - $exitCode = $command->run($input, $output); - - self::assertSame(0, $exitCode); - self::assertNotNull($projectionA->handledMessage); - self::assertNull($projectionB->handledMessage); - - $content = $output->fetch(); - - self::assertStringContainsString('[WARNING] rebuild projections', $content); - self::assertStringContainsString('[OK] finish', $content); - } - - public function testRecreate(): void - { - $projectionA = new DummyProjection(); - - $store = $this->prophesize(Store::class); - $store->count($this->criteria)->willReturn(5); - $store->load($this->criteria)->willReturn($this->stream); - - $repository = new InMemoryProjectorRepository([$projectionA]); - - $command = new ProjectionRebuildCommand( - $store->reveal(), - $repository, - ); - - $input = new ArrayInput(['--recreate' => true]); - $output = new BufferedOutput(); - - $exitCode = $command->run($input, $output); - - self::assertSame(0, $exitCode); - - $content = $output->fetch(); - - self::assertTrue($projectionA->createCalled); - self::assertTrue($projectionA->dropCalled); - - self::assertStringContainsString('[OK] projection schema deleted', $content); - self::assertStringContainsString('[OK] projection schema created', $content); - self::assertStringContainsString('[WARNING] rebuild projections', $content); - self::assertStringContainsString('[OK] finish', $content); - } - - public function testRecreateWithSpecificProjection(): void - { - $store = $this->prophesize(Store::class); - $store->count($this->criteria)->willReturn(5); - $store->load($this->criteria)->willReturn($this->stream); - - $projectionA = new DummyProjection(); - $projectionB = new Dummy2Projection(); - $repository = new InMemoryProjectorRepository([$projectionA, $projectionB]); - - $command = new ProjectionRebuildCommand( - $store->reveal(), - $repository, - ); - - $input = new ArrayInput(['--recreate' => true, '--projection' => DummyProjection::class]); - $output = new BufferedOutput(); - - $exitCode = $command->run($input, $output); - - self::assertSame(0, $exitCode); - self::assertNotNull($projectionA->handledMessage); - self::assertTrue($projectionA->createCalled); - self::assertTrue($projectionA->dropCalled); - self::assertNull($projectionB->handledMessage); - self::assertFalse($projectionB->createCalled); - self::assertFalse($projectionB->dropCalled); - - $content = $output->fetch(); - - self::assertStringContainsString('[OK] projection schema deleted', $content); - self::assertStringContainsString('[OK] projection schema created', $content); - self::assertStringContainsString('[WARNING] rebuild projections', $content); - self::assertStringContainsString('[OK] finish', $content); - } -}