Skip to content

Commit

Permalink
Added Cli adapter, fix jobRepository and tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
zerai committed Dec 14, 2021
1 parent 2106c87 commit ff07a89
Show file tree
Hide file tree
Showing 8 changed files with 109 additions and 6 deletions.
4 changes: 4 additions & 0 deletions config/services.yaml
Expand Up @@ -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'
44 changes: 44 additions & 0 deletions core/ingesting/src/PublicJob/Adapter/Cli/IngestingJobCommand.php
@@ -0,0 +1,44 @@
<?php declare(strict_types=1);

namespace Ingesting\PublicJob\Adapter\Cli;

use Ingesting\PublicJob\Application\Usecase\JobRssDataSourceChecker;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;

class IngestingJobCommand extends Command
{
protected static $defaultName = 'app:ingesting:job';

protected static string $defaultDescription = 'Download rss from Gazzetta Ufficiale';

private JobRssDataSourceChecker $usecase;

public function __construct(JobRssDataSourceChecker $usecase)
{
$this->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;
}
}
46 changes: 46 additions & 0 deletions 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'
Expand Up @@ -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;
Expand Down
Expand Up @@ -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;
}

Expand Down
Expand Up @@ -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)) {
Expand Down
Expand Up @@ -66,14 +66,25 @@ 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);
$this->repository->save($jobFeed);

$result = $this->repository->isUniqueIdentity($identity);

self::assertTrue($result);
self::assertFalse($result);
}

/**
Expand Down
Expand Up @@ -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;
Expand Down

0 comments on commit ff07a89

Please sign in to comment.