Skip to content

Commit

Permalink
IBX-201: Refactored ExportCommand
Browse files Browse the repository at this point in the history
  • Loading branch information
ciastektk committed Jul 27, 2021
1 parent b66cb73 commit 5424bdb
Show file tree
Hide file tree
Showing 7 changed files with 167 additions and 128 deletions.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@
"EzSystems\\EzRecommendationClientBundle\\": "src/bundle/",
"EzSystems\\EzRecommendationClient\\": "src/lib/",
"Ibexa\\Contracts\\Personalization\\": "src/contracts/",
"Ibexa\\Personalization\\": "src/lib/"
"Ibexa\\Personalization\\": "src/lib/",
"Ibexa\\Bundle\\Personalization\\": "src/bundle/"
}
},
"autoload-dev": {
Expand Down
98 changes: 14 additions & 84 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
@@ -1,20 +1,5 @@
parameters:
ignoreErrors:
-
message: "#^Cannot call method getDefinition\\(\\) on Symfony\\\\Component\\\\Console\\\\Application\\|null\\.$#"
count: 1
path: src/bundle/Command/ExportCommand.php

-
message: "#^Method EzSystems\\\\EzRecommendationClientBundle\\\\Command\\\\ExportCommand\\:\\:configure\\(\\) has no return typehint specified\\.$#"
count: 1
path: src/bundle/Command/ExportCommand.php

-
message: "#^Parameter \\#5 \\$default of method Symfony\\\\Component\\\\Console\\\\Command\\\\Command\\:\\:addOption\\(\\) expects array\\<string\\>\\|bool\\|string\\|null, int given\\.$#"
count: 3
path: src/bundle/Command/ExportCommand.php

-
message: "#^Left side of && is always true\\.$#"
count: 1
Expand Down Expand Up @@ -555,16 +540,6 @@ parameters:
count: 1
path: src/lib/Exception/BadResponseException.php

-
message: "#^Parameter \\#3 \\$previous of method Exception\\:\\:__construct\\(\\) expects Throwable\\|null, EzSystems\\\\EzRecommendationClient\\\\Exception\\\\Throwable\\|null given\\.$#"
count: 1
path: src/lib/Exception/CredentialsNotFoundException.php

-
message: "#^Parameter \\$previous of method EzSystems\\\\EzRecommendationClient\\\\Exception\\\\CredentialsNotFoundException\\:\\:__construct\\(\\) has invalid typehint type EzSystems\\\\EzRecommendationClient\\\\Exception\\\\Throwable\\.$#"
count: 1
path: src/lib/Exception/CredentialsNotFoundException.php

-
message: "#^Method EzSystems\\\\EzRecommendationClient\\\\Exception\\\\FileNotFoundException\\:\\:__construct\\(\\) has parameter \\$code with no typehint specified\\.$#"
count: 1
Expand Down Expand Up @@ -611,54 +586,44 @@ parameters:
path: src/lib/Exception/InvalidRelationException.php

-
message: "#^Method EzSystems\\\\EzRecommendationClient\\\\Exporter\\\\Exporter\\:\\:generateUrlList\\(\\) return type has no value type specified in iterable type array\\.$#"
count: 1
message: "#^Access to an undefined property Ibexa\\\\Personalization\\\\Value\\\\Export\\\\Parameters\\:\\:\\$lang\\.$#"
count: 3
path: src/lib/Exporter/Exporter.php

-
message: "#^Method EzSystems\\\\EzRecommendationClient\\\\Exporter\\\\Exporter\\:\\:getContentForGivenLanguages\\(\\) return type has no value type specified in iterable type array\\.$#"
count: 1
message: "#^Access to an undefined property Ibexa\\\\Personalization\\\\Value\\\\Export\\\\Parameters\\:\\:\\$page\\.$#"
count: 2
path: src/lib/Exporter/Exporter.php

-
message: "#^Method EzSystems\\\\EzRecommendationClient\\\\Exporter\\\\Exporter\\:\\:run\\(\\) return type has no value type specified in iterable type array\\.$#"
message: "#^Call to an undefined method Ibexa\\\\Personalization\\\\Value\\\\Export\\\\Parameters\\:\\:getProperties\\(\\)\\.$#"
count: 1
path: src/lib/Exporter/Exporter.php

-
message: "#^Parameter \\#2 \\$lang of method EzSystems\\\\EzRecommendationClient\\\\Exporter\\\\Exporter\\:\\:generateUrlList\\(\\) expects string, string\\|null given\\.$#"
message: "#^Method EzSystems\\\\EzRecommendationClient\\\\Exporter\\\\Exporter\\:\\:generateUrlList\\(\\) return type has no value type specified in iterable type array\\.$#"
count: 1
path: src/lib/Exporter/Exporter.php

-
message: "#^Method EzSystems\\\\EzRecommendationClient\\\\Exporter\\\\ExporterInterface\\:\\:run\\(\\) return type has no value type specified in iterable type array\\.$#"
count: 1
path: src/lib/Exporter/ExporterInterface.php

-
message: "#^Method EzSystems\\\\EzRecommendationClient\\\\Factory\\\\ConfigurableExportParametersFactory\\:\\:create\\(\\) has parameter \\$properties with no value type specified in iterable type array\\.$#"
count: 1
path: src/lib/Factory/ConfigurableExportParametersFactory.php

-
message: "#^Method EzSystems\\\\EzRecommendationClient\\\\Factory\\\\ConfigurableExportParametersFactory\\:\\:getMissingRequiredOptions\\(\\) has parameter \\$options with no value type specified in iterable type array\\.$#"
message: "#^Method EzSystems\\\\EzRecommendationClient\\\\Exporter\\\\Exporter\\:\\:getContentForGivenLanguages\\(\\) return type has no value type specified in iterable type array\\.$#"
count: 1
path: src/lib/Factory/ConfigurableExportParametersFactory.php
path: src/lib/Exporter/Exporter.php

-
message: "#^Method EzSystems\\\\EzRecommendationClient\\\\Factory\\\\ConfigurableExportParametersFactory\\:\\:getMissingRequiredOptions\\(\\) return type has no value type specified in iterable type array\\.$#"
message: "#^Method EzSystems\\\\EzRecommendationClient\\\\Exporter\\\\Exporter\\:\\:run\\(\\) return type has no value type specified in iterable type array\\.$#"
count: 1
path: src/lib/Factory/ConfigurableExportParametersFactory.php
path: src/lib/Exporter/Exporter.php

-
message: "#^Method EzSystems\\\\EzRecommendationClient\\\\Factory\\\\ExportParametersFactory\\:\\:create\\(\\) has parameter \\$properties with no value type specified in iterable type array\\.$#"
message: "#^Parameter \\#2 \\$parameters of method EzSystems\\\\EzRecommendationClient\\\\Service\\\\ContentServiceInterface\\:\\:fetchContent\\(\\) expects EzSystems\\\\EzRecommendationClient\\\\Value\\\\ExportParameters, Ibexa\\\\Personalization\\\\Value\\\\Export\\\\Parameters given\\.$#"
count: 1
path: src/lib/Factory/ExportParametersFactory.php
path: src/lib/Exporter/Exporter.php

-
message: "#^Method EzSystems\\\\EzRecommendationClient\\\\Factory\\\\ExportParametersFactoryInterface\\:\\:create\\(\\) has parameter \\$properties with no value type specified in iterable type array\\.$#"
message: "#^Method EzSystems\\\\EzRecommendationClient\\\\Exporter\\\\ExporterInterface\\:\\:run\\(\\) return type has no value type specified in iterable type array\\.$#"
count: 1
path: src/lib/Factory/ExportParametersFactoryInterface.php
path: src/lib/Exporter/ExporterInterface.php

-
message: "#^Parameter \\#1 \\$str of function strtolower expects string, string\\|null given\\.$#"
Expand Down Expand Up @@ -1100,11 +1065,6 @@ parameters:
count: 1
path: src/lib/SPI/Content.php

-
message: "#^Method EzSystems\\\\EzRecommendationClient\\\\SPI\\\\ExportParametersFactoryDecorator\\:\\:create\\(\\) has parameter \\$properties with no value type specified in iterable type array\\.$#"
count: 1
path: src/lib/SPI/ExportParametersFactoryDecorator.php

-
message: "#^Property EzSystems\\\\EzRecommendationClient\\\\SPI\\\\Notification\\:\\:\\$events type has no value type specified in iterable type array\\.$#"
count: 1
Expand Down Expand Up @@ -1280,11 +1240,6 @@ parameters:
count: 1
path: src/lib/Service/ExportNotificationService.php

-
message: "#^Cannot cast Symfony\\\\Component\\\\Validator\\\\ConstraintViolationListInterface to string\\.$#"
count: 1
path: src/lib/Service/ExportService.php

-
message: "#^Property EzSystems\\\\EzRecommendationClient\\\\Service\\\\ExportService\\:\\:\\$notificationService \\(EzSystems\\\\EzRecommendationClient\\\\Service\\\\ExportNotificationService\\) does not accept EzSystems\\\\EzRecommendationClient\\\\Service\\\\NotificationService\\.$#"
count: 1
Expand Down Expand Up @@ -2005,31 +1960,6 @@ parameters:
count: 1
path: tests/lib/Service/EventNotificationServiceTest.php

-
message: "#^Method EzSystems\\\\EzRecommendationClient\\\\Tests\\\\Service\\\\ExportNotificationServiceTest\\:\\:testCreateExportNotification\\(\\) has no return typehint specified\\.$#"
count: 1
path: tests/lib/Service/ExportNotificationServiceTest.php

-
message: "#^Method EzSystems\\\\EzRecommendationClient\\\\Tests\\\\Service\\\\ExportNotificationServiceTest\\:\\:testCreateInstanceOfEventNotificationService\\(\\) has no return typehint specified\\.$#"
count: 1
path: tests/lib/Service/ExportNotificationServiceTest.php

-
message: "#^Method EzSystems\\\\EzRecommendationClient\\\\Tests\\\\Service\\\\ExportNotificationServiceTest\\:\\:testSendNotification\\(\\) has no return typehint specified\\.$#"
count: 1
path: tests/lib/Service/ExportNotificationServiceTest.php

-
message: "#^Property EzSystems\\\\EzRecommendationClient\\\\Tests\\\\Service\\\\ExportNotificationServiceTest\\:\\:\\$notificationOptions type has no value type specified in iterable type array\\.$#"
count: 1
path: tests/lib/Service/ExportNotificationServiceTest.php

-
message: "#^Property EzSystems\\\\EzRecommendationClient\\\\Tests\\\\Service\\\\ExportNotificationServiceTest\\:\\:\\$urls type has no value type specified in iterable type array\\.$#"
count: 1
path: tests/lib/Service/ExportNotificationServiceTest.php

-
message: "#^Property EzSystems\\\\EzRecommendationClient\\\\Tests\\\\Service\\\\NotificationServiceTest\\:\\:\\$basicNotificationOptions type has no value type specified in iterable type array\\.$#"
count: 1
Expand Down
5 changes: 5 additions & 0 deletions phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,9 @@
<extensions>
<extension class="EzSystems\EzRecommendationClient\PHPUnit\BypassFinalHook"/>
</extensions>
<php>
<env name="RECOMMENDATION_CUSTOMER_ID" value="0" />
<env name="RECOMMENDATION_LICENSE_KEY" value="" />
<env name="RECOMMENDATION_HOST_URI" value="" />
</php>
</phpunit>
60 changes: 26 additions & 34 deletions src/bundle/Command/ExportCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@
*/
declare(strict_types=1);

namespace EzSystems\EzRecommendationClientBundle\Command;
namespace Ibexa\Bundle\Personalization\Command;

use eZ\Bundle\EzPublishCoreBundle\Command\BackwardCompatibleCommand;
use EzSystems\EzRecommendationClient\Factory\ExportParametersFactoryInterface;
use EzSystems\EzRecommendationClient\Http\HttpEnvironmentInterface;
use EzSystems\EzRecommendationClient\Service\ExportServiceInterface;
use Ibexa\Personalization\Export\Input\CommandInputResolverInterface;
use Ibexa\Personalization\Factory\Export\ParametersFactoryInterface;
use Psr\Log\LoggerInterface;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
Expand All @@ -25,53 +26,45 @@ final class ExportCommand extends Command implements BackwardCompatibleCommand
{
public const SUCCESS = 0;

/** @var \EzSystems\EzRecommendationClient\Service\ExportServiceInterface */
private $exportService;
private ExportServiceInterface $exportService;

/** @var \EzSystems\EzRecommendationClient\Http\HttpEnvironmentInterface */
private $httpEnvironment;
private HttpEnvironmentInterface $httpEnvironment;

/** @var \Psr\Log\LoggerInterface */
private $logger;
private LoggerInterface $logger;

/** @var \EzSystems\EzRecommendationClient\Factory\ExportParametersFactoryInterface */
private $exportParametersFactory;
private CommandInputResolverInterface $inputResolver;

private ParametersFactoryInterface $exportParametersFactory;

public function __construct(
ExportServiceInterface $exportService,
HttpEnvironmentInterface $httpEnvironment,
LoggerInterface $logger,
ExportParametersFactoryInterface $exportParametersFactory
CommandInputResolverInterface $inputResolver,
ParametersFactoryInterface $exportParametersFactory
) {
parent::__construct();

$this->exportService = $exportService;
$this->httpEnvironment = $httpEnvironment;
$this->logger = $logger;
$this->inputResolver = $inputResolver;
$this->exportParametersFactory = $exportParametersFactory;
}

/**
* {@inheritdoc}
*/
protected function configure()
protected function configure(): void
{
$this
->setName('ibexa:recommendation:run-export')
->setAliases(['ezrecommendation:export:run'])
->setDescription('Run export to files.')
->addOption('webHook', null, InputOption::VALUE_OPTIONAL, 'Guzzle Client base_uri parameter, will be used to send recommendation data')
->addOption('customer-id', null, InputOption::VALUE_REQUIRED, 'Personalization customer id')
->addOption('license-key', null, InputOption::VALUE_REQUIRED, 'Personalization license key')
->addOption('web-hook', null, InputOption::VALUE_OPTIONAL, 'Recommendation engine URI used to send recommendation data')
->addOption('host', null, InputOption::VALUE_OPTIONAL, 'Host used in exportDownload url for notifier in export feature')
->addOption('customerId', null, InputOption::VALUE_OPTIONAL, 'Your eZ Recommendation customer ID')
->addOption('licenseKey', null, InputOption::VALUE_OPTIONAL, 'Your eZ Recommendation license key')
->addOption('pageSize', null, InputOption::VALUE_OPTIONAL, '', 500)
->addOption('page', null, InputOption::VALUE_OPTIONAL, '', 1)
->addOption('path', null, InputOption::VALUE_OPTIONAL, 'A string of subtree path, eg: /1/2/')
->addOption('hidden', null, InputOption::VALUE_OPTIONAL, 'If set to 1 - Criterion Visibility: VISIBLE will be used', 0)
->addOption('image', null, InputOption::VALUE_OPTIONAL, 'Image_variations used for images')
->addOption('contentTypeIdList', null, InputOption::VALUE_REQUIRED, 'List of Content Types ID')
->addOption('fields', null, InputOption::VALUE_OPTIONAL, 'List of the fields, eg: title, description')
;
->addOption('item-type-identifier-list', null, InputOption::VALUE_REQUIRED, 'List of item types identifiers')
->addOption('languages', null, InputOption::VALUE_REQUIRED, 'List of items languages')
->addOption('page-size', null, InputOption::VALUE_OPTIONAL, '', '500');
}

/**
Expand All @@ -84,14 +77,13 @@ protected function execute(InputInterface $input, OutputInterface $output): int

date_default_timezone_set('UTC');

$options = array_diff_key(
$input->getOptions(),
$this->getApplication()->getDefinition()->getOptions()
);
$options['siteaccess'] = $input->getOption('siteaccess');

$this->exportService->process(
$this->exportParametersFactory->create($options),
$this->exportService->runExport(
$this->exportParametersFactory->create(
$this->inputResolver->resolve(
$input, $this->getApplication()
),
ParametersFactoryInterface::COMMAND_TYPE
),
$output
);

Expand Down
12 changes: 3 additions & 9 deletions src/bundle/Resources/config/services/commands.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,12 @@ services:
autoconfigure: true
public: false

EzSystems\EzRecommendationClientBundle\Command\:
resource: '../../../../src/bundle/Command/*'

EzSystems\EzRecommendationClientBundle\Command\ExportCommand:
arguments:
$exportParametersFactory: '@EzSystems\EzRecommendationClient\Factory\ConfigurableExportParametersFactory'

Ibexa\Bundle\Personalization\Command\ExportCommand:
tags:
- { name: console.command }
- { name: monolog.logger, channel: ezrecommendation }
- { name: monolog.logger, channel: ibexa-recommendation }

EzSystems\EzRecommendationClientBundle\Command\UserAttributesUpdateCommand:
tags:
- { name: console.command }
- { name: monolog.logger, channel: ezrecommendation }
- { name: monolog.logger, channel: ibexa-recommendation }
31 changes: 31 additions & 0 deletions tests/bundle/Command/AbstractCommandTestCase.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

/**
* @copyright Copyright (C) Ibexa AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/
declare(strict_types=1);

namespace Ibexa\Tests\Bundle\Personalization\Command;

use Ibexa\Tests\Integration\Personalization\IbexaKernelTestCase;
use Symfony\Bundle\FrameworkBundle\Console\Application;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Tester\CommandTester;

abstract class AbstractCommandTestCase extends IbexaKernelTestCase
{
protected Command $command;

protected CommandTester $commandTester;

protected function setUp(): void
{
static::bootKernel();
$application = new Application(self::$kernel);
$this->command = $application->find(static::getCommandName());
$this->commandTester = new CommandTester($this->command);
}

abstract protected static function getCommandName(): string;
}
Loading

0 comments on commit 5424bdb

Please sign in to comment.