From ff07a89dca7f21dbd8a7e75c166279262409db5c Mon Sep 17 00:00:00 2001 From: zero Date: Mon, 13 Dec 2021 18:44:13 +0100 Subject: [PATCH] Added Cli adapter, fix jobRepository and tests. --- config/services.yaml | 4 ++ .../Adapter/Cli/IngestingJobCommand.php | 44 ++++++++++++++++++ .../src/PublicJob/Adapter/Cli/services.yaml | 46 +++++++++++++++++++ .../Doctrine/DoctrineJobFeedRepository.php | 2 +- .../Persistence/InMemoryJobFeedRepository.php | 2 +- .../Application/Usecase/ReadJobRssUsecase.php | 2 - .../Persistence/JobRepositoryContractTest.php | 13 +++++- .../Unit/Usecase/ReadJobRssUsecaseTest.php | 2 +- 8 files changed, 109 insertions(+), 6 deletions(-) create mode 100644 core/ingesting/src/PublicJob/Adapter/Cli/IngestingJobCommand.php create mode 100644 core/ingesting/src/PublicJob/Adapter/Cli/services.yaml diff --git a/config/services.yaml b/config/services.yaml index 584fa6e8..70a5d17d 100644 --- a/config/services.yaml +++ b/config/services.yaml @@ -40,3 +40,7 @@ services: Ingesting\PublicJob\Application\PublicJobModule: factory: [ '@Ingesting\PublicJob\Infrastructure\ProductionServiceContainer', 'module' ] public: true + + Ingesting\PublicJob\Adapter\Cli\IngestingJobCommand: + arguments: + - '@Ingesting\PublicJob\Application\PublicJobModule' diff --git a/core/ingesting/src/PublicJob/Adapter/Cli/IngestingJobCommand.php b/core/ingesting/src/PublicJob/Adapter/Cli/IngestingJobCommand.php new file mode 100644 index 00000000..14a47bcb --- /dev/null +++ b/core/ingesting/src/PublicJob/Adapter/Cli/IngestingJobCommand.php @@ -0,0 +1,44 @@ +usecase = $usecase; + parent::__construct(); + } + + protected function configure(): void + { + $this + ->setDescription(self::$defaultDescription); + } + + protected function execute(InputInterface $input, OutputInterface $output): int + { + $io = new SymfonyStyle($input, $output); + try { + $this->usecase->readJobRssDataSource(); + $io->success('You have a new command! Now make it your own! Pass --help to see your options.'); + } catch (\Exception $exception) { + $io->error($exception->getMessage()); + return 1; + } + + return 0; + } +} diff --git a/core/ingesting/src/PublicJob/Adapter/Cli/services.yaml b/core/ingesting/src/PublicJob/Adapter/Cli/services.yaml new file mode 100644 index 00000000..70a5d17d --- /dev/null +++ b/core/ingesting/src/PublicJob/Adapter/Cli/services.yaml @@ -0,0 +1,46 @@ +# This file is the entry point to configure your own services. +# Files in the packages/ subdirectory configure your dependencies. + +# Put parameters here that don't need to change on each machine where the app is deployed +# https://symfony.com/doc/current/best_practices/configuration.html#application-related-configuration +parameters: + +services: + # default configuration for services in *this* file + _defaults: + autowire: true # Automatically injects dependencies in your services. + autoconfigure: true # Automatically registers your services as commands, event subscribers, etc. + + # makes classes in src/ available to be used as services + # this creates a service per class whose id is the fully-qualified class name + App\: + resource: '../src/' + exclude: + - '../src/DependencyInjection/' + - '../src/Entity/' + - '../src/Kernel.php' + - '../src/Tests/' + + # controllers are imported separately to make sure services can be injected + # as action arguments even if you don't extend any base controller class + App\Controller\: + resource: '../src/Controller/' + tags: ['controller.service_arguments'] + + # add more service definitions when explicit configuration is needed + # please note that last definitions always *replace* previous ones + + Ingesting\PublicJob\Adapter\Persistence\Doctrine\DoctrineJobFeedRepository: + public: true + + Ingesting\PublicJob\Infrastructure\ProductionServiceContainer: + arguments: + - '@Ingesting\PublicJob\Adapter\Persistence\Doctrine\DoctrineJobFeedRepository' + + Ingesting\PublicJob\Application\PublicJobModule: + factory: [ '@Ingesting\PublicJob\Infrastructure\ProductionServiceContainer', 'module' ] + public: true + + Ingesting\PublicJob\Adapter\Cli\IngestingJobCommand: + arguments: + - '@Ingesting\PublicJob\Application\PublicJobModule' diff --git a/core/ingesting/src/PublicJob/Adapter/Persistence/Doctrine/DoctrineJobFeedRepository.php b/core/ingesting/src/PublicJob/Adapter/Persistence/Doctrine/DoctrineJobFeedRepository.php index 7af5cba5..3f5fba89 100644 --- a/core/ingesting/src/PublicJob/Adapter/Persistence/Doctrine/DoctrineJobFeedRepository.php +++ b/core/ingesting/src/PublicJob/Adapter/Persistence/Doctrine/DoctrineJobFeedRepository.php @@ -44,7 +44,7 @@ public function withId(JobId $jobId): JobFeed public function isUniqueIdentity(JobId $jobId): bool { $result = false; - if (null !== ($this->find($jobId))) { + if (null === ($this->find($jobId))) { $result = true; } return $result; diff --git a/core/ingesting/src/PublicJob/Adapter/Persistence/InMemoryJobFeedRepository.php b/core/ingesting/src/PublicJob/Adapter/Persistence/InMemoryJobFeedRepository.php index be0986d4..33d09814 100644 --- a/core/ingesting/src/PublicJob/Adapter/Persistence/InMemoryJobFeedRepository.php +++ b/core/ingesting/src/PublicJob/Adapter/Persistence/InMemoryJobFeedRepository.php @@ -38,7 +38,7 @@ public function withId(JobId $jobId): JobFeed public function isUniqueIdentity(JobId $jobId): bool { $result = false; - if (\array_key_exists($jobId->toString(), $this->items)) { + if (! \array_key_exists($jobId->toString(), $this->items)) { $result = true; } diff --git a/core/ingesting/src/PublicJob/Application/Usecase/ReadJobRssUsecase.php b/core/ingesting/src/PublicJob/Application/Usecase/ReadJobRssUsecase.php index c937f45b..d090dab4 100644 --- a/core/ingesting/src/PublicJob/Application/Usecase/ReadJobRssUsecase.php +++ b/core/ingesting/src/PublicJob/Application/Usecase/ReadJobRssUsecase.php @@ -38,12 +38,10 @@ public function readJobRssDataSource(): void /** @var RssData $item */ foreach ($downloadedItem as $item) { - // IS UNIQUE LINK SEND FEEDBACK MESSAGE AND RETURN if (! $this->linkChecker->isUniqueLink($item->link())) { return; } - //Todo randomness in domain (unpredictable test/assertion) $jobId = JobId::generate(); if (! $this->identityChecker->isUnique($jobId)) { diff --git a/core/ingesting/tests/PublicJob/Integration/Persistence/JobRepositoryContractTest.php b/core/ingesting/tests/PublicJob/Integration/Persistence/JobRepositoryContractTest.php index ced69cc3..e2a7ea90 100644 --- a/core/ingesting/tests/PublicJob/Integration/Persistence/JobRepositoryContractTest.php +++ b/core/ingesting/tests/PublicJob/Integration/Persistence/JobRepositoryContractTest.php @@ -66,6 +66,17 @@ public function duplicate_identity_should_throw_exception(): void * @test */ public function should_detect_unique_identity(): void + { + $identity = JobId::generate(); +// $jobFeed = $this->createJobFeed($identity); +// $this->repository->save($jobFeed); +// + $result = $this->repository->isUniqueIdentity($identity); + + self::assertTrue($result); + } + + public function should_detect_a_not_unique_identity(): void { $identity = JobId::generate(); $jobFeed = $this->createJobFeed($identity); @@ -73,7 +84,7 @@ public function should_detect_unique_identity(): void $result = $this->repository->isUniqueIdentity($identity); - self::assertTrue($result); + self::assertFalse($result); } /** diff --git a/core/ingesting/tests/PublicJob/Unit/Usecase/ReadJobRssUsecaseTest.php b/core/ingesting/tests/PublicJob/Unit/Usecase/ReadJobRssUsecaseTest.php index f93614e9..90cfb807 100644 --- a/core/ingesting/tests/PublicJob/Unit/Usecase/ReadJobRssUsecaseTest.php +++ b/core/ingesting/tests/PublicJob/Unit/Usecase/ReadJobRssUsecaseTest.php @@ -94,7 +94,7 @@ function (JobFeed $param): bool { $param->title() === self::ITEM_TITLE && $param->description() === self::ITEM_DESCRIPTION // TODO fix input date format - //&& $param->publicationDate()->sameValueAs(PublicationDate::fromString(self::ITEM_PUB_DATE)) + //&& $param->publicationDate() === new \DateTimeImmutable(self::ITEM_PUB_DATE) && $param->link() === self::ITEM_LINK ) { return true;