diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php index 84f11232..e1f1d9f1 100644 --- a/.php-cs-fixer.dist.php +++ b/.php-cs-fixer.dist.php @@ -1,14 +1,15 @@ in(__DIR__ . '/src') ->name('*.php') ->ignoreDotFiles(true) - ->exclude(['bin','views','out','translations', 'metadata']) + ->exclude(['bin', 'views', 'out', 'translations', 'metadata']) ->notPath(['src/metadata.php']) ->ignoreVCS(true); @@ -27,23 +28,22 @@ 'operators' => [ '=' => 'align', '=>' => 'align', - ] + ], ], - 'blank_line_after_opening_tag' => true, - 'line_ending' => true, - 'class_attributes_separation' => false, - 'blank_line_before_statement' => ['statements' => ['break', 'continue', 'declare', 'throw', 'try']], - 'concat_space' => ['spacing' => 'one'], - 'declare_strict_types' => true, - 'increment_style' => ['style' => 'post'], - 'no_superfluous_phpdoc_tags' => false, - 'no_useless_else' => true, - 'no_useless_return' => true, - 'ordered_class_elements' => true, - 'ordered_imports' => ['imports_order' => ['class', 'function', 'const']], - 'strict_comparison' => true, - 'yoda_style' => ['equal' => false, 'identical' => false, 'less_and_greater' => false], + 'blank_line_after_opening_tag' => true, + 'line_ending' => true, + 'class_attributes_separation' => false, + 'blank_line_before_statement' => ['statements' => ['break', 'continue', 'declare', 'throw', 'try']], + 'concat_space' => ['spacing' => 'one'], + 'declare_strict_types' => true, + 'increment_style' => ['style' => 'post'], + 'no_superfluous_phpdoc_tags' => false, + 'no_useless_else' => true, + 'no_useless_return' => true, + 'ordered_class_elements' => true, + 'ordered_imports' => ['imports_order' => ['class', 'function', 'const']], + 'strict_comparison' => true, + 'yoda_style' => ['equal' => false, 'identical' => false, 'less_and_greater' => false], 'nullable_type_declaration_for_default_null_value' => false, ]) ->setFinder($finder); - diff --git a/spec/Config/CommunicationSpec.php b/spec/Config/CommunicationSpec.php index 6e0c5a92..f5163acb 100644 --- a/spec/Config/CommunicationSpec.php +++ b/spec/Config/CommunicationSpec.php @@ -1,5 +1,7 @@ beConstructedWith($configService); } - function it_should_cast_credentials_to_string() + public function it_should_cast_credentials_to_string(): void { $this->getCredentials()->shouldContainOnlyStrings(); } - function it_should_return_factfinder_channel_configured_for_specific_saleschannel(SystemConfigService $configService) + public function it_should_return_channel_for_specific_saleschannel(SystemConfigService $configService): void { $configService->get('OmikronFactFinder.config.channel', '1')->willReturn('channel_1'); $configService->get('OmikronFactFinder.config.channel', '2')->willReturn('channel_2'); @@ -29,9 +31,7 @@ function it_should_return_factfinder_channel_configured_for_specific_saleschanne public function getMatchers(): array { return [ - 'containOnlyStrings' => function ($subject) { - return count(array_filter($subject, 'is_string')) === count($subject); - }, + 'containOnlyStrings' => fn ($subject) => count(array_filter($subject, 'is_string')) === count($subject), ]; } } diff --git a/spec/Config/FtpConfigSpec.php b/spec/Config/FtpConfigSpec.php index 92cb9442..a8af6df6 100644 --- a/spec/Config/FtpConfigSpec.php +++ b/spec/Config/FtpConfigSpec.php @@ -1,5 +1,7 @@ beConstructedWith($configService); } - function it_should_use_channel_name_as_part_of_uploaded_file_name(SystemConfigService $configService) + public function it_should_use_channel_name_as_part_of_uploaded_file_name(SystemConfigService $configService): void { $salesChannelId = '1'; $channel = 'ff_channel_name'; $configService->get('OmikronFactFinder.config.channel', $salesChannelId)->willReturn($channel); - $this->getUploadFileName($salesChannelId)->shouldContain($channel); } } diff --git a/spec/DataAbstractionLayer/FeedPreprocessorSpec.php b/spec/DataAbstractionLayer/FeedPreprocessorSpec.php index 495f6561..10b065fd 100644 --- a/spec/DataAbstractionLayer/FeedPreprocessorSpec.php +++ b/spec/DataAbstractionLayer/FeedPreprocessorSpec.php @@ -10,6 +10,7 @@ use Omikron\FactFinder\Shopware6\TestUtil\ProductMockFactory; use Omikron\FactFinder\Shopware6\TestUtil\ProductVariantMockFactory; use PhpSpec\ObjectBehavior; +use PhpSpec\Wrapper\Collaborator; use PhpSpec\Wrapper\Subject; use PHPUnit\Framework\Assert; use Prophecy\Argument; @@ -20,7 +21,6 @@ use Shopware\Core\Framework\Context; use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Symfony\Contracts\EventDispatcher\Event; -use PhpSpec\Wrapper\Collaborator; class FeedPreprocessorSpec extends ObjectBehavior { @@ -29,148 +29,17 @@ class FeedPreprocessorSpec extends ObjectBehavior private Collaborator $customFields; private Context $context; - function let(EventDispatcherInterface $eventDispatcher, ExportCustomFields $customFields) + public function let(EventDispatcherInterface $eventDispatcher, ExportCustomFields $customFields): void { $eventDispatcher->dispatch(Argument::any())->willReturn(new Event()); $this->beConstructedWith(new PropertyFormatter(new TextFilter()), $eventDispatcher, $customFields); - $this->context = new Context(new SystemSource()); + $this->context = new Context(new SystemSource()); $this->productMockFactory = new ProductMockFactory(); $this->variantMockFactory = new ProductVariantMockFactory(); - $this->customFields = $customFields; + $this->customFields = $customFields; } -// function it_should_create_only_entries_for_variants_that_should_be_visible() -// { -// $productEntity = $this->productMockFactory->create(); -// $variants = [ -// $this->variantMockFactory->create($productEntity, ['productNumber' => 'SW100.1', 'size' => 'S', 'color' => 'red', 'material' => 'cotton']), -// $this->variantMockFactory->create($productEntity, ['productNumber' => 'SW100.2', 'size' => 'M', 'color' => 'red', 'material' => 'cotton']), -// $this->variantMockFactory->create($productEntity, ['productNumber' => 'SW100.3', 'size' => 'L', 'color' => 'red', 'material' => 'cotton']), -// $this->variantMockFactory->create($productEntity, ['productNumber' => 'SW100.4', 'size' => 'S', 'color' => 'blue', 'material' => 'cotton']), -// $this->variantMockFactory->create($productEntity, ['productNumber' => 'SW100.5', 'size' => 'M', 'color' => 'blue', 'material' => 'cotton']), -// $this->variantMockFactory->create($productEntity, ['productNumber' => 'SW100.6', 'size' => 'L', 'color' => 'blue', 'material' => 'cotton']), -// $this->variantMockFactory->create($productEntity, ['productNumber' => 'SW100.7', 'size' => 'S', 'color' => 'green', 'material' => 'cotton']), -// $this->variantMockFactory->create($productEntity, ['productNumber' => 'SW100.8', 'size' => 'M', 'color' => 'green', 'material' => 'cotton']), -// $this->variantMockFactory->create($productEntity, ['productNumber' => 'SW100.9', 'size' => 'L', 'color' => 'green', 'material' => 'cotton']), -// $this->variantMockFactory->create($productEntity, ['productNumber' => 'SW100.10', 'size' => 'S', 'color' => 'red', 'material' => 'linen']), -// $this->variantMockFactory->create($productEntity, ['productNumber' => 'SW100.11', 'size' => 'M', 'color' => 'red', 'material' => 'linen']), -// $this->variantMockFactory->create($productEntity, ['productNumber' => 'SW100.12', 'size' => 'L', 'color' => 'red', 'material' => 'linen']), -// $this->variantMockFactory->create($productEntity, ['productNumber' => 'SW100.13', 'size' => 'S', 'color' => 'blue', 'material' => 'linen']), -// $this->variantMockFactory->create($productEntity, ['productNumber' => 'SW100.14', 'size' => 'M', 'color' => 'blue', 'material' => 'linen']), -// $this->variantMockFactory->create($productEntity, ['productNumber' => 'SW100.15', 'size' => 'L', 'color' => 'blue', 'material' => 'linen']), -// $this->variantMockFactory->create($productEntity, ['productNumber' => 'SW100.16', 'size' => 'S', 'color' => 'green', 'material' => 'linen']), -// $this->variantMockFactory->create($productEntity, ['productNumber' => 'SW100.17', 'size' => 'M', 'color' => 'green', 'material' => 'linen']), -// $this->variantMockFactory->create($productEntity, ['productNumber' => 'SW100.18', 'size' => 'L', 'color' => 'green', 'material' => 'linen']), -// ]; -// foreach ($variants as $variant) { -// $this->customFields->getValue($variant)->willReturn(''); -// } -// -// $productEntity->setChildren( -// new ProductCollection( -// array_reduce($variants, fn(array $carriedVariants, ProductEntity $product): array -// => $carriedVariants + [$product->getId() => $product], []))); -// -// /** @var Subject $entries */ -// $entries = $this->createEntries($productEntity, $this->context); -// -// $entries->shouldBeArray(); -// //3 colors * 2 materials = 6 combinations -// $entries->shouldHaveCount(1); //invalid -// -// $this->validateFilterAttributes( -// $entries->getWrappedObject(), -// [ -// 'size=S|size=M|size=L|color=red|material=cotton', -// 'size=S|size=M|size=L|color=blue|material=cotton', -// 'size=S|size=M|size=L|color=green|material=cotton', -// 'size=S|size=M|size=L|color=red|material=linen', -// 'size=S|size=M|size=L|color=blue|material=linen', -// 'size=S|size=M|size=L|color=green|material=linen', -// ] -// ); -// } -// -// function it_should_create_entries_with_empty_string_in_custom_fields_when_custom_fields_not_set() -// { -// // Given -// $productEntity = $this->productMockFactory->create(); -// $productEntity->setVariantListingConfig(new VariantListingConfig(null, 'SW100', null)); -// $variant = $this->variantMockFactory->create( -// $productEntity, -// ['productNumber' => 'SW100.1', 'size' => 'S', 'color' => 'red', 'material' => 'cotton', 'customFields' => ''] -// ); -// $productEntity->setChildren(new ProductCollection([$variant])); -// -// // Expect -// $this->customFields->getValue($variant)->willReturn(''); -// -// // When -// $entries = $this->createEntries($productEntity, $this->context); -// $entries->shouldBeArray(); -// $entries->shouldHaveCount(1); -// -// // Then -// Assert::assertEquals('', array_values($entries->getWrappedObject())[0]['customFields']); -// } -// -//// function it_should_create_entries_with_proper_custom_fields_for_each_display_group() -//// { -//// $this->validateCustomFields( -//// [ -//// [md5('size'), 'true'], -//// [md5('color'), 'false'], -//// [md5('material'), 'false'] -//// ], -//// [ -//// '|pattern=dots|pattern=patterned|pattern=stripes|shape=circle|shape=rectangle|shape=square|shape=triangle|', -//// '|pattern=dots|pattern=patterned|pattern=stripes|shape=circle|shape=rectangle|shape=triangle|', -//// ] -//// ); -//// $this->validateCustomFields( -//// [ -//// [md5('size'), 'false'], -//// [md5('color'), 'true'], -//// [md5('material'), 'false'] -//// ], -//// [ -//// '|pattern=dots|pattern=patterned|pattern=stripes|shape=circle|shape=rectangle|shape=square|shape=triangle|', -//// '|pattern=dots|pattern=stripes|shape=circle|shape=rectangle|', -//// ] -//// ); -//// $this->validateCustomFields( -//// [ -//// [md5('size'), 'false'], -//// [md5('color'), 'true'], -//// [md5('material'), 'true'] -//// ], -//// [ -//// '|pattern=dots|pattern=stripes|shape=triangle|', -//// '|pattern=dots|pattern=patterned|shape=square|shape=triangle|', -//// '|pattern=dots|pattern=stripes|shape=rectangle|', -//// '|pattern=dots|pattern=stripes|shape=circle|shape=rectangle|', -//// ] -//// ); -//// $this->validateCustomFields( -//// [ -//// [md5('size'), 'true'], -//// [md5('color'), 'true'], -//// [md5('material'), 'true'] -//// ], -//// [ -//// '|pattern=stripes|shape=triangle|', -//// '|pattern=dots|shape=triangle|', -//// '|pattern=dots|shape=square|', -//// '|pattern=patterned|shape=triangle|', -//// '|pattern=dots|shape=rectangle|', -//// '|pattern=stripes|shape=rectangle|', -//// '|pattern=dots|shape=rectangle|', -//// '|pattern=stripes|shape=circle|', -//// ] -//// ); -//// } -// - function it_should_export_only_one_entry_if_main_variant_is_selected() + public function it_should_export_only_one_entry_if_main_variant_is_selected(): void { $productEntity = $this->productMockFactory->create(); $productEntity->setVariantListingConfig(new VariantListingConfig(null, 'SW100', null)); @@ -187,9 +56,36 @@ function it_should_export_only_one_entry_if_main_variant_is_selected() ]; $variants = [ - $this->variantMockFactory->create($productEntity, ['productNumber' => 'SW100.1', 'size' => 'S', 'color' => 'red', 'material' => 'cotton', 'customFields' => $customFieldsData['SW100.1']]), - $this->variantMockFactory->create($productEntity, ['productNumber' => 'SW100.2', 'size' => 'M', 'color' => 'red', 'material' => 'linen', 'customFields' => $customFieldsData['SW100.1']]), - $this->variantMockFactory->create($productEntity, ['productNumber' => 'SW100.3', 'size' => 'L', 'color' => 'red', 'material' => 'wool', 'customFields' => $customFieldsData['SW100.1']]) + $this->variantMockFactory->create( + $productEntity, + [ + 'productNumber' => 'SW100.1', + 'size' => 'S', + 'color' => 'red', + 'material' => 'cotton', + 'customFields' => $customFieldsData['SW100.1'], + ] + ), + $this->variantMockFactory->create( + $productEntity, + [ + 'productNumber' => 'SW100.2', + 'size' => 'M', + 'color' => 'red', + 'material' => 'linen', + 'customFields' => $customFieldsData['SW100.1'], + ] + ), + $this->variantMockFactory->create( + $productEntity, + [ + 'productNumber' => 'SW100.3', + 'size' => 'L', + 'color' => 'red', + 'material' => 'wool', + 'customFields' => $customFieldsData['SW100.1'], + ] + ), ]; foreach ($variants as $variant) { @@ -198,97 +94,26 @@ function it_should_export_only_one_entry_if_main_variant_is_selected() $productEntity->setChildren( new ProductCollection( - array_reduce($variants, fn(array $carriedVariants, ProductEntity $product): array - => $carriedVariants + [$product->getId() => $product], []))); + array_reduce($variants, fn (array $carriedVariants, ProductEntity $product): array => $carriedVariants + [$product->getId() => $product], []))); /** @var Subject $entries */ $entries = $this->createEntries($productEntity, $this->context); $entries->shouldBeArray(); - //only one entry should be producted + // only one entry should be producted $entries->shouldHaveCount(1); $this->validateFilterAttributes($entries->getWrappedObject(), [ - 'size=S|size=M|size=L|color=red|material=cotton|material=linen|material=wool' + 'size=S|size=M|size=L|color=red|material=cotton|material=linen|material=wool', ]); - - } -// - private function validateFilterAttributes(array $entries, array $filters) + + private function validateFilterAttributes(array $entries, array $filters): void { - $expected = count($filters); - $isContainingFilter = fn(string $filter): callable - => fn(array $entry): bool - => strpos($entry['filterAttributes'], $filter) !== false; + $expected = count($filters); + $isContainingFilter = fn (string $filter): callable => fn (array $entry): bool => strpos($entry['filterAttributes'], $filter) !== false; - $match = array_reduce($filters, fn (int $score, string $filter) - => $score + (int) array_filter($entries, $isContainingFilter($filter)), 0); + $match = array_reduce($filters, fn (int $score, string $filter) => $score + (int) array_filter($entries, $isContainingFilter($filter)), 0); Assert::assertEquals($expected, $match); } -// -// private function validateCustomFields(array $groupConfigurationConfig, array $expectedValues) -// { -// // Given -// $productMockFactory = new ProductMockFactory(); -// $variantMockFactory = new ProductVariantMockFactory(); -// $productEntity = $productMockFactory->create(); -// $productEntity->setVariantListingConfig( -// new VariantListingConfig( -// null, -// 'SW100', -// ProductMockFactory::getGroupConfigurationConfig($groupConfigurationConfig) -// ) -// ); -// -// $customFieldsData = [ -// 'SW100.1' => ['shape' => 'triangle', 'pattern' => 'stripes'], -// 'SW100.2' => ['shape' => 'triangle', 'pattern' => 'dots'], -// 'SW100.3' => ['shape' => 'square', 'pattern' => 'dots'], -// 'SW100.4' => ['shape' => 'triangle', 'pattern' => 'patterned'], -// 'SW100.5' => ['shape' => 'rectangle', 'pattern' => 'dots'], -// 'SW100.6' => ['shape' => 'rectangle', 'pattern' => 'stripes'], -// 'SW100.7' => ['shape' => 'rectangle', 'pattern' => 'dots'], -// 'SW100.8' => ['shape' => 'circle', 'pattern' => 'stripes'], -// ]; -// $customFieldsValues = [ -// 'SW100.1' => '|shape=triangle|pattern=stripes|', -// 'SW100.2' => '|shape=triangle|pattern=dots|', -// 'SW100.3' => '|shape=square|pattern=dots|', -// 'SW100.4' => '|shape=triangle|pattern=patterned|', -// 'SW100.5' => '|shape=rectangle|pattern=dots|', -// 'SW100.6' => '|shape=rectangle|pattern=stripes|', -// 'SW100.7' => '|shape=rectangle|pattern=dots|', -// 'SW100.8' => '|shape=circle|pattern=stripes|', -// ]; -// $variants = [ -// $variantMockFactory->create($productEntity, ['productNumber' => 'SW100.1', 'size' => 'S', 'color' => 'green', 'material' => 'cotton', 'customFields' => $customFieldsData['SW100.1']]), -// $variantMockFactory->create($productEntity, ['productNumber' => 'SW100.2', 'size' => 'M', 'color' => 'green', 'material' => 'cotton', 'customFields' => $customFieldsData['SW100.2']]), -// $variantMockFactory->create($productEntity, ['productNumber' => 'SW100.3', 'size' => 'S', 'color' => 'green', 'material' => 'linen', 'customFields' => $customFieldsData['SW100.3']]), -// $variantMockFactory->create($productEntity, ['productNumber' => 'SW100.4', 'size' => 'M', 'color' => 'green', 'material' => 'linen', 'customFields' => $customFieldsData['SW100.4']]), -// $variantMockFactory->create($productEntity, ['productNumber' => 'SW100.5', 'size' => 'S', 'color' => 'red', 'material' => 'cotton', 'customFields' => $customFieldsData['SW100.5']]), -// $variantMockFactory->create($productEntity, ['productNumber' => 'SW100.6', 'size' => 'M', 'color' => 'red', 'material' => 'cotton', 'customFields' => $customFieldsData['SW100.6']]), -// $variantMockFactory->create($productEntity, ['productNumber' => 'SW100.7', 'size' => 'S', 'color' => 'red', 'material' => 'linen', 'customFields' => $customFieldsData['SW100.7']]), -// $variantMockFactory->create($productEntity, ['productNumber' => 'SW100.8', 'size' => 'M', 'color' => 'red', 'material' => 'linen', 'customFields' => $customFieldsData['SW100.8']]), -// ]; -// $productEntity->setChildren(new ProductCollection(array_reduce($variants, fn(array $carriedVariants, ProductEntity $product): array => $carriedVariants + [$product->getId() => $product], []))); -// -// // Expected -// foreach ($variants as $variant) { -// $this->customFields->getValue($variant)->willReturn($customFieldsValues[$variant->getProductNumber()]); -// } -// -// // When -// $entries = $this->createEntries($productEntity, $this->context); -// -// // Then -// $entries = array_values($entries->getWrappedObject()); -// -// foreach ($expectedValues as $key => $expectedValue) { -// $gluedCustomFields = explode('|', trim($entries[$key]['customFields'], '|')); -// sort($gluedCustomFields); -// $gluedCustomFields = sprintf('|%s|', implode('|', $gluedCustomFields)); -// Assert::assertEquals($expectedValue, $gluedCustomFields); -// } -// } } diff --git a/spec/Domain/RedirectMappingSpec.php b/spec/Domain/RedirectMappingSpec.php index b40ee462..e4c54486 100644 --- a/spec/Domain/RedirectMappingSpec.php +++ b/spec/Domain/RedirectMappingSpec.php @@ -32,12 +32,10 @@ public function it_should_return_empty_array_as_value() public function it_should_return_array_with_one_valid_item_as_value() { Assert::assertEquals(['abc' => '/some/page'], (new RedirectMapping('abc=/some/page'))->getValue()); - Assert::assertEquals(['abc' => 'http://domain.com/some/page'], (new RedirectMapping('abc=http://domain.com/some/page'))->getValue()); Assert::assertEquals(['abc' => 'https://domain.com/some/page'], (new RedirectMapping('abc=https://domain.com/some/page'))->getValue()); Assert::assertEquals(['abc' => 'https://domain.com/some/page?page=4&foo=bar'], (new RedirectMapping('abc=https://domain.com/some/page?page=4&foo=bar'))->getValue()); Assert::assertEquals(['abc def' => '/some/page'], (new RedirectMapping('abc def=/some/page'))->getValue()); - Assert::assertEquals(['abc def' => 'http://domain.com/some/page'], (new RedirectMapping('abc def=http://domain.com/some/page'))->getValue()); Assert::assertEquals(['abc def' => 'https://domain.com/some/page'], (new RedirectMapping('abc def=https://domain.com/some/page'))->getValue()); Assert::assertEquals(['abc def' => 'https://domain.com/some/page?page=4&foo=bar'], (new RedirectMapping('abc def=https://domain.com/some/page?page=4&foo=bar'))->getValue()); } diff --git a/spec/Export/ChannelTypeNamingStrategySpec.php b/spec/Export/ChannelTypeNamingStrategySpec.php index d2f2c90f..9fb0e509 100644 --- a/spec/Export/ChannelTypeNamingStrategySpec.php +++ b/spec/Export/ChannelTypeNamingStrategySpec.php @@ -4,7 +4,6 @@ namespace spec\Omikron\FactFinder\Shopware6\Export; -use Omikron\FactFinder\Shopware6\Export\ChannelTypeNamingStrategy; use PhpSpec\ObjectBehavior; class ChannelTypeNamingStrategySpec extends ObjectBehavior diff --git a/spec/Export/CurrencyFieldsProviderSpec.php b/spec/Export/CurrencyFieldsProviderSpec.php index 5ccfd8fa..e303b10a 100644 --- a/spec/Export/CurrencyFieldsProviderSpec.php +++ b/spec/Export/CurrencyFieldsProviderSpec.php @@ -16,14 +16,17 @@ class CurrencyFieldsProviderSpec extends ObjectBehavior { - public function let(EntityRepository $currencyRepository, ExportSettings $exportSettings) + public function let(EntityRepository $currencyRepository, ExportSettings $exportSettings): void { $exportSettings->isMultiCurrencyPriceExportEnable()->willReturn(true); $this->beConstructedWith($currencyRepository, $exportSettings, new NumberFormatter()); } - public function it_will_return_currency_list_if_no_cache_available(EntityRepository $currencyRepository, EntitySearchResult $entitySearchResult, ExportSettings $exportSettings) - { + public function it_will_return_currency_list_if_no_cache_available( + EntityRepository $currencyRepository, + EntitySearchResult $entitySearchResult, + ExportSettings $exportSettings + ): void { $currencyRepository ->search(Argument::cetera(), Context::createDefaultContext()) ->will($this->mockCurrencyRepository($entitySearchResult)); @@ -34,8 +37,10 @@ public function it_will_return_currency_list_if_no_cache_available(EntityReposit $this->getCurrencyFields()->shouldReturn($priceCurrency); } - public function it_will_return_currency_list_from_cache(EntityRepository $currencyRepository, EntitySearchResult $entitySearchResult) - { + public function it_will_return_currency_list_from_cache( + EntityRepository $currencyRepository, + EntitySearchResult $entitySearchResult + ): void { $currencyRepository ->search(Argument::cetera(), Context::createDefaultContext()) ->will($this->mockCurrencyRepository($entitySearchResult)) diff --git a/spec/Export/CustomFieldsServiceSpec.php b/spec/Export/CustomFieldsServiceSpec.php index 2d500ab4..74d4a154 100644 --- a/spec/Export/CustomFieldsServiceSpec.php +++ b/spec/Export/CustomFieldsServiceSpec.php @@ -1,5 +1,7 @@ getContext()->willReturn($context); $salesChannelContext->getLanguageId()->willReturn(''); $salesChannelService->getSalesChannelContext()->willReturn($salesChannelContext); - $this->productMockFactory = new ProductMockFactory(); - $this->variantMockFactory = new ProductVariantMockFactory(); + $this->productMockFactory = new ProductMockFactory(); + $this->variantMockFactory = new ProductVariantMockFactory(); $this->feedPreprocessorEntryMockFactory = new FeedPreprocessorEntryMockFactory(); - $this->exportProductMockFactory = new ExportProductMockFactory(); - $this->salesChannelProductMockFactory = new SalesChannelProductMockFactory(); - $this->feedPreprocessorReader = $feedPreprocessorReader; - $this->decoratedFactory = $decoratedFactory; - $this->cachedFields = new \ArrayIterator(); + $this->exportProductMockFactory = new ExportProductMockFactory(); + $this->salesChannelProductMockFactory = new SalesChannelProductMockFactory(); + $this->feedPreprocessorReader = $feedPreprocessorReader; + $this->decoratedFactory = $decoratedFactory; + $this->cachedFields = new \ArrayIterator(); $exportSettings->isExportCacheEnable()->willReturn(true); - $this->exportSettings = $exportSettings; + $this->exportSettings = $exportSettings; $this->salesChannelService = $salesChannelService; - $this->feedPreprocessor = $feedPreprocessor; + $this->feedPreprocessor = $feedPreprocessor; $this->beConstructedWith( $this->decoratedFactory, $this->salesChannelService, @@ -99,16 +99,16 @@ public function it_should_create_entities_for_variants_that_should_be_visible(): { // Given $productEntity = $this->productMockFactory->create(); - $variantsData = [ - 'SW100.1' => ['productNumber' => 'SW100.1', 'size' => 'S', 'color' => 'red', 'material' => 'cotton'], - 'SW100.2' => ['productNumber' => 'SW100.2', 'size' => 'M', 'color' => 'red', 'material' => 'cotton'], - 'SW100.3' => ['productNumber' => 'SW100.3', 'size' => 'L', 'color' => 'red', 'material' => 'cotton'], - 'SW100.4' => ['productNumber' => 'SW100.4', 'size' => 'S', 'color' => 'blue', 'material' => 'cotton'], - 'SW100.5' => ['productNumber' => 'SW100.5', 'size' => 'M', 'color' => 'blue', 'material' => 'cotton'], - 'SW100.6' => ['productNumber' => 'SW100.6', 'size' => 'L', 'color' => 'blue', 'material' => 'cotton'], - 'SW100.7' => ['productNumber' => 'SW100.7', 'size' => 'S', 'color' => 'green', 'material' => 'cotton'], - 'SW100.8' => ['productNumber' => 'SW100.8', 'size' => 'M', 'color' => 'green', 'material' => 'cotton'], - 'SW100.9' => ['productNumber' => 'SW100.9', 'size' => 'L', 'color' => 'green', 'material' => 'cotton'], + $variantsData = [ + 'SW100.1' => ['productNumber' => 'SW100.1', 'size' => 'S', 'color' => 'red', 'material' => 'cotton'], + 'SW100.2' => ['productNumber' => 'SW100.2', 'size' => 'M', 'color' => 'red', 'material' => 'cotton'], + 'SW100.3' => ['productNumber' => 'SW100.3', 'size' => 'L', 'color' => 'red', 'material' => 'cotton'], + 'SW100.4' => ['productNumber' => 'SW100.4', 'size' => 'S', 'color' => 'blue', 'material' => 'cotton'], + 'SW100.5' => ['productNumber' => 'SW100.5', 'size' => 'M', 'color' => 'blue', 'material' => 'cotton'], + 'SW100.6' => ['productNumber' => 'SW100.6', 'size' => 'L', 'color' => 'blue', 'material' => 'cotton'], + 'SW100.7' => ['productNumber' => 'SW100.7', 'size' => 'S', 'color' => 'green', 'material' => 'cotton'], + 'SW100.8' => ['productNumber' => 'SW100.8', 'size' => 'M', 'color' => 'green', 'material' => 'cotton'], + 'SW100.9' => ['productNumber' => 'SW100.9', 'size' => 'L', 'color' => 'green', 'material' => 'cotton'], 'SW100.10' => ['productNumber' => 'SW100.10', 'size' => 'S', 'color' => 'red', 'material' => 'linen'], 'SW100.11' => ['productNumber' => 'SW100.11', 'size' => 'M', 'color' => 'red', 'material' => 'linen'], 'SW100.12' => ['productNumber' => 'SW100.12', 'size' => 'L', 'color' => 'red', 'material' => 'linen'], @@ -119,11 +119,11 @@ public function it_should_create_entities_for_variants_that_should_be_visible(): 'SW100.17' => ['productNumber' => 'SW100.17', 'size' => 'M', 'color' => 'green', 'material' => 'linen'], 'SW100.18' => ['productNumber' => 'SW100.18', 'size' => 'L', 'color' => 'green', 'material' => 'linen'], ]; - $variants = array_map(fn (array $variantData) => $this->variantMockFactory->create($productEntity, $variantData), $variantsData); + $variants = array_map(fn (array $variantData) => $this->variantMockFactory->create($productEntity, $variantData), $variantsData); $filterAttributes = [ - 'SW100.1' => 'size=S|size=M|size=L|color=red|material=cotton', - 'SW100.5' => 'size=S|size=M|size=L|color=blue|material=cotton', - 'SW100.7' => 'size=S|size=M|size=L|color=green|material=cotton', + 'SW100.1' => 'size=S|size=M|size=L|color=red|material=cotton', + 'SW100.5' => 'size=S|size=M|size=L|color=blue|material=cotton', + 'SW100.7' => 'size=S|size=M|size=L|color=green|material=cotton', 'SW100.10' => 'size=S|size=M|size=L|color=red|material=linen', 'SW100.13' => 'size=S|size=M|size=L|color=blue|material=linen', 'SW100.16' => 'size=S|size=M|size=L|color=green|material=linen', @@ -153,7 +153,7 @@ public function it_should_create_entities_for_variants_that_should_be_visible(): // Then Assert::assertEquals( - array_values(array_map(fn(ExportProductEntity $variant) => $variant->toArray(), $expectedVariants)), + array_values(array_map(fn (ExportProductEntity $variant) => $variant->toArray(), $expectedVariants)), array_values(array_map(fn (ExportProductEntity $product) => $product->toArray(), $exportedProducts)) ); } @@ -162,9 +162,9 @@ public function it_should_create_entities_with_cached_category_path( CategoryPath $categoryPathField, FieldsProvider $fieldsProvider, FeedPreprocessorEntryPersister $entryPersister - ) { + ): void { // Given - $categoryPathName = 'CategoryPath'; + $categoryPathName = 'CategoryPath'; $categoryPathValue = 'Sports/Books%2C+Clothing+%26+Games/Movies%2C+Electronics+%26+Clothing'; $this->beConstructedWith( $this->decoratedFactory, @@ -178,18 +178,18 @@ public function it_should_create_entities_with_cached_category_path( ); $productEntity = $this->productMockFactory->create(); - $variantsData = [ + $variantsData = [ 'SW100.1' => ['productNumber' => 'SW100.1', 'size' => 'S', 'color' => 'red', 'material' => 'cotton'], 'SW100.2' => ['productNumber' => 'SW100.2', 'size' => 'M', 'color' => 'blue', 'material' => 'cotton'], ]; - $variants = array_map(fn (array $variantData) => $this->variantMockFactory->create($productEntity, $variantData), $variantsData); + $variants = array_map(fn (array $variantData) => $this->variantMockFactory->create($productEntity, $variantData), $variantsData); $filterAttributes = [ 'SW100.1' => 'size=S|size=M|color=red|material=cotton', 'SW100.2' => 'size=S|size=M|color=blue|material=cotton', ]; - $expectedVariants = array_map(function(array $expectedVariantData) use ($filterAttributes, $categoryPathField, $variants, $categoryPathName, $categoryPathValue, $productEntity): ExportProductEntity { + $expectedVariants = array_map(function (array $expectedVariantData) use ($filterAttributes, $categoryPathField, $variants, $categoryPathName, $categoryPathValue, $productEntity): ExportProductEntity { $productNumber = $expectedVariantData['productNumber']; - $product = $variants[$productNumber]; + $product = $variants[$productNumber]; $categoryPathField->getName()->willReturn($categoryPathName); $categoryPathField->getValue($product)->willReturn($categoryPathValue); @@ -197,9 +197,9 @@ public function it_should_create_entities_with_cached_category_path( $product, [ 'filterAttributes' => $filterAttributes[$productNumber], - 'additionalCache' => [$categoryPathName => $categoryPathValue], - 'productFields' => [$categoryPathField->getWrappedObject()], - 'parent' => $productEntity + 'additionalCache' => [$categoryPathName => $categoryPathValue], + 'productFields' => [$categoryPathField->getWrappedObject()], + 'parent' => $productEntity, ] ); }, $variantsData); @@ -207,7 +207,7 @@ public function it_should_create_entities_with_cached_category_path( foreach ($variantsData as $variantData) { $productNumber = $variantData['productNumber']; - $product = $variants[$productNumber]; + $product = $variants[$productNumber]; $categoryPathField->getName()->willReturn($categoryPathName); $fieldsProvider->getFields(SalesChannelProductEntity::class)->willReturn([$categoryPathField]); } @@ -233,27 +233,27 @@ public function it_should_create_entities_with_cached_category_path( // Then Assert::assertEquals( - array_values(array_map(fn(ExportProductEntity $variant) => $variant->toArray(), $expectedVariants)), + array_values(array_map(fn (ExportProductEntity $variant) => $variant->toArray(), $expectedVariants)), array_values(array_map(fn (ExportProductEntity $product) => $product->toArray(), $exportedProducts)) ); } - public function it_should_create_entities_with_proper_custom_fields_for_each_display_group() + public function it_should_create_entities_with_proper_custom_fields_for_each_display_group(): void { $this->validateExportedCustomFields( [ - [md5('size'), 'true'], - [md5('color'), 'false'], - [md5('material'), 'false'] + [hash('sha512', 'size'), 'true'], + [hash('sha512', 'color'), 'false'], + [hash('sha512', 'material'), 'false'], ], [ 'SW100.1' => [ 'filterAttributes' => 'material=cotton|material=linen|color=red|color=green|size=S', - 'customFields' => '|shape=rectangle|pattern=dots|shape=square|shape=triangle|pattern=stripes|', + 'customFields' => '|shape=rectangle|pattern=dots|shape=square|shape=triangle|pattern=stripes|', ], 'SW100.8' => [ 'filterAttributes' => 'material=cotton|material=linen|color=red|color=green|size=M', - 'customFields' => '|shape=triangle|pattern=patterned|pattern=dots|shape=rectangle|pattern=stripes|shape=circle|', + 'customFields' => '|shape=triangle|pattern=patterned|pattern=dots|shape=rectangle|pattern=stripes|shape=circle|', ], ], [ @@ -263,18 +263,18 @@ public function it_should_create_entities_with_proper_custom_fields_for_each_dis ); $this->validateExportedCustomFields( [ - [md5('size'), 'false'], - [md5('color'), 'true'], - [md5('material'), 'false'] + [hash('sha512', 'size'), 'false'], + [hash('sha512', 'color'), 'true'], + [hash('sha512', 'material'), 'false'], ], [ 'SW100.1' => [ 'filterAttributes' => 'size=S|size=M|material=cotton|material=linen|color=green', - 'customFields' => '|shape=triangle|pattern=patterned|pattern=dots|shape=square|pattern=stripes|' + 'customFields' => '|shape=triangle|pattern=patterned|pattern=dots|shape=square|pattern=stripes|', ], 'SW100.8' => [ 'filterAttributes' => 'size=S|size=M|material=cotton|material=linen|color=red', - 'customFields' => '|shape=rectangle|pattern=dots|pattern=stripes|shape=circle|' + 'customFields' => '|shape=rectangle|pattern=dots|pattern=stripes|shape=circle|', ], ], [ @@ -284,26 +284,26 @@ public function it_should_create_entities_with_proper_custom_fields_for_each_dis ); $this->validateExportedCustomFields( [ - [md5('size'), 'false'], - [md5('color'), 'true'], - [md5('material'), 'true'] + [hash('sha512', 'size'), 'false'], + [hash('sha512', 'color'), 'true'], + [hash('sha512', 'material'), 'true'], ], [ 'SW100.1' => [ 'filterAttributes' => 'size=S|size=M|material=cotton|color=green', - 'customFields' => '|shape=triangle|pattern=dots|pattern=stripes|', + 'customFields' => '|shape=triangle|pattern=dots|pattern=stripes|', ], 'SW100.3' => [ 'filterAttributes' => 'size=S|size=M|color=green|material=linen', - 'customFields' => '|shape=triangle|pattern=patterned|shape=square|pattern=dots|', + 'customFields' => '|shape=triangle|pattern=patterned|shape=square|pattern=dots|', ], 'SW100.6' => [ 'filterAttributes' => 'size=S|size=M|material=cotton|color=red', - 'customFields' => '|shape=rectangle|pattern=dots|pattern=stripes|', + 'customFields' => '|shape=rectangle|pattern=dots|pattern=stripes|', ], 'SW100.8' => [ 'filterAttributes' => 'size=S|size=M|color=red|material=linen', - 'customFields' => '|shape=rectangle|pattern=dots|shape=circle|pattern=stripes|', + 'customFields' => '|shape=rectangle|pattern=dots|shape=circle|pattern=stripes|', ], ], [ @@ -315,42 +315,42 @@ public function it_should_create_entities_with_proper_custom_fields_for_each_dis ); $this->validateExportedCustomFields( [ - [md5('size'), 'true'], - [md5('color'), 'true'], - [md5('material'), 'true'] + [hash('sha512', 'size'), 'true'], + [hash('sha512', 'color'), 'true'], + [hash('sha512', 'material'), 'true'], ], [ 'SW100.1' => [ 'filterAttributes' => '|size=S|material=cotton|color=green', - 'customFields' => '|shape=triangle|pattern=stripes|', + 'customFields' => '|shape=triangle|pattern=stripes|', ], 'SW100.2' => [ 'filterAttributes' => '|material=cotton|color=green|size=M', - 'customFields' => '|shape=triangle|pattern=dots|', + 'customFields' => '|shape=triangle|pattern=dots|', ], 'SW100.3' => [ 'filterAttributes' => '|size=S|color=green|material=linen', - 'customFields' => '|shape=square|pattern=dots|', + 'customFields' => '|shape=square|pattern=dots|', ], 'SW100.4' => [ 'filterAttributes' => '|color=green|size=M|material=linen', - 'customFields' => '|shape=triangle|pattern=patterned|', + 'customFields' => '|shape=triangle|pattern=patterned|', ], 'SW100.5' => [ 'filterAttributes' => '|size=S|material=cotton|color=red', - 'customFields' => '|shape=rectangle|pattern=dots|', + 'customFields' => '|shape=rectangle|pattern=dots|', ], 'SW100.6' => [ 'filterAttributes' => '|material=cotton|color=red|size=M', - 'customFields' => '|shape=rectangle|pattern=stripes|', + 'customFields' => '|shape=rectangle|pattern=stripes|', ], 'SW100.7' => [ 'filterAttributes' => '|size=S|color=red|material=linen', - 'customFields' => '|shape=rectangle|pattern=dots|', + 'customFields' => '|shape=rectangle|pattern=dots|', ], 'SW100.8' => [ 'filterAttributes' => '|color=red|size=M|material=linen', - 'customFields' => '|shape=circle|pattern=stripes|', + 'customFields' => '|shape=circle|pattern=stripes|', ], ], [ @@ -408,7 +408,7 @@ private function validateExportedCustomFields( $this->feedPreprocessorReader->read($productEntity->getProductNumber(), Argument::any())->willReturn( $this->getFeedPreprocessorEntries( $productEntity, - array_map(fn(string $productNumber, array $data) => $variantsData[$productNumber] + $feedPreprocessorReaderData[$productNumber], array_keys($feedPreprocessorReaderData), array_values($feedPreprocessorReaderData)) + array_map(fn (string $productNumber, array $data) => $variantsData[$productNumber] + $feedPreprocessorReaderData[$productNumber], array_keys($feedPreprocessorReaderData), array_values($feedPreprocessorReaderData)) ) ); @@ -424,22 +424,23 @@ private function validateExportedCustomFields( } /** - * @var ProductEntity[] $expectedVariants + * @var ProductEntity[] + * * @return FeedPreprocessorEntry[] */ private function getFeedPreprocessorEntries(ProductEntity $parent, array $variantsData): array { return array_reduce( $variantsData, - fn(array $acc, array $variantData): array => $acc + [ + fn (array $acc, array $variantData): array => $acc + [ $variantData['productNumber'] => $this->feedPreprocessorEntryMockFactory->create( $this->variantMockFactory->create($parent, $variantData), [ 'filterAttributes' => $variantData['filterAttributes'], - 'customFields' => $variantData['customFields'] ?? '', - 'additionalCache' => $variantData['additionalCache'] ?? [] + 'customFields' => $variantData['customFields'] ?? '', + 'additionalCache' => $variantData['additionalCache'] ?? [], ] - ) + ), ], [] ); @@ -453,8 +454,7 @@ private function getProductCollection(array $variants): ProductCollection return new ProductCollection( array_reduce( $variants, - fn(array $carriedVariants, ProductEntity $product): array => - $carriedVariants + [$product->getId() => $this->salesChannelProductMockFactory->create($product)], + fn (array $carriedVariants, ProductEntity $product): array => $carriedVariants + [$product->getId() => $this->salesChannelProductMockFactory->create($product)], [] )); } diff --git a/spec/Export/Field/BrandSpec.php b/spec/Export/Field/BrandSpec.php index 0f54191b..7b876424 100644 --- a/spec/Export/Field/BrandSpec.php +++ b/spec/Export/Field/BrandSpec.php @@ -1,5 +1,7 @@ shouldHaveType(FieldInterface::class); } - function it_has_a_name() + public function it_has_a_name(): void { $this->getName()->shouldReturn('Brand'); } - function it_does_not_fail_if_the_brand_is_not_present(Product $product, Manufacturer $manufacturer) + public function it_does_not_fail_if_the_brand_is_not_present(Product $product, Manufacturer $manufacturer): void { $this->shouldNotThrow()->during('getValue', [$product]); $this->getValue($product)->shouldReturn(''); @@ -33,7 +35,7 @@ function it_does_not_fail_if_the_brand_is_not_present(Product $product, Manufact $this->getValue($product)->shouldReturn('ACME Inc.'); } - function it_gets_the_value_from_the_manufacturer(Product $product, Manufacturer $manufacturer) + public function it_gets_the_value_from_the_manufacturer(Product $product, Manufacturer $manufacturer): void { $product->getManufacturer()->willReturn($manufacturer); $manufacturer->getTranslation('name')->willReturn('FACT-Finder'); diff --git a/spec/Export/Field/CategoryPathSpec.php b/spec/Export/Field/CategoryPathSpec.php index 56a953da..b8cdbcba 100644 --- a/spec/Export/Field/CategoryPathSpec.php +++ b/spec/Export/Field/CategoryPathSpec.php @@ -1,5 +1,7 @@ beConstructedWith($salesChannelService, $breadcrumbBuilder, 'CategoryPath'); } - function it_is_a_field() + public function it_is_a_field() { $this->shouldHaveType(FieldInterface::class); } - function it_has_a_name() + public function it_has_a_name() { $this->getName()->shouldReturn('CategoryPath'); } - function it_should_create_correct_path_if_product_is_assigned_to_multiple_categories( + public function it_should_create_correct_path_if_product_is_assigned_to_multiple_categories( Product $product, CategoryBreadcrumbBuilder $breadcrumbBuilder, SalesChannelService $salesChannelService, @@ -64,7 +66,7 @@ function it_should_create_correct_path_if_product_is_assigned_to_multiple_catego $this->getValue($product)->shouldReturn('Category1-1/Category1-2/Category1-3|Category2-1/Category2-2'); } - function it_should_create_correct_path_for_category( + public function it_should_create_correct_path_for_category( CategoryBreadcrumbBuilder $breadcrumbBuilder, SalesChannelService $salesChannelService, SalesChannelContext $channelContext @@ -95,7 +97,7 @@ function it_should_create_correct_path_for_category( } - function it_should_filter_out_categories_from_not_active_sales_channel( + public function it_should_filter_out_categories_from_not_active_sales_channel( Product $product, CategoryBreadcrumbBuilder $breadcrumbBuilder, SalesChannelService $salesChannelService, diff --git a/spec/Export/Field/CustomFieldsSpec.php b/spec/Export/Field/CustomFieldsSpec.php index 64f16eb5..e9dc9dfe 100644 --- a/spec/Export/Field/CustomFieldsSpec.php +++ b/spec/Export/Field/CustomFieldsSpec.php @@ -53,7 +53,7 @@ class CustomFieldsSpec extends ObjectBehavior ], ]; - function let( + public function let( SalesChannelService $salesChannelService, SalesChannelContext $channelContext, EntityRepository $customFieldRepository, @@ -83,12 +83,12 @@ function let( ); } - function it_is_a_field() + public function it_is_a_field() { $this->shouldBeAnInstanceOf(FieldInterface::class); } - function it_should_join_multiselect_option_values( + public function it_should_join_multiselect_option_values( Product $product, EntityRepository $customFieldRepository, EntityRepository $languageRepository, @@ -111,7 +111,7 @@ function it_should_join_multiselect_option_values( $this->getValue($product)->shouldReturn('|SelectFieldDE=option1DE#option2DE|'); } - function it_will_use_default_language_if_none_is_stored_in_context( + public function it_will_use_default_language_if_none_is_stored_in_context( Product $product, EntityRepository $customFieldRepository ) { @@ -136,7 +136,7 @@ function it_will_use_default_language_if_none_is_stored_in_context( $this->getValue($product)->shouldReturn('|SelectFieldEN=option1EN#option2EN|'); } - function it_will_return_label_technical_value_if_no_translation_is_provided( + public function it_will_return_label_technical_value_if_no_translation_is_provided( Product $product, EntityRepository $customFieldRepository ) { @@ -161,7 +161,7 @@ function it_will_return_label_technical_value_if_no_translation_is_provided( $this->getValue($product)->shouldReturn('|test-multi-select-field=option1#option2|'); } - function it_will_skip_disabled_custom_fields( + public function it_will_skip_disabled_custom_fields( Product $product, EntityRepository $customFieldRepository, ExportSettings $exportSettings, CustomFieldsService $customFieldsService) { @@ -210,7 +210,7 @@ function it_will_skip_disabled_custom_fields( $this->getValue($product)->shouldReturn('|Enabled attribute=exported value|'); } - function it_should_join_multiselect_entity_value( + public function it_should_join_multiselect_entity_value( Product $product, EntityRepository $customFieldRepository ) { diff --git a/spec/Export/Field/DescriptionSpec.php b/spec/Export/Field/DescriptionSpec.php index 3c16a6f3..77a247cf 100644 --- a/spec/Export/Field/DescriptionSpec.php +++ b/spec/Export/Field/DescriptionSpec.php @@ -1,5 +1,7 @@ shouldHaveType(FieldInterface::class); } - function it_should_return_the_description(Product $product) + public function it_should_return_the_description(Product $product) { $product->getTranslation('description')->willReturn('FACT-Finder Web Components'); $this->getValue($product)->shouldReturn('FACT-Finder Web Components'); } - function it_should_not_throw_errors(Product $product) + public function it_should_not_throw_errors(Product $product) { $this->shouldNotThrow()->during('getValue', [$product]); } diff --git a/spec/Export/Field/FilterAttributesSpec.php b/spec/Export/Field/FilterAttributesSpec.php index 7ab354ad..da1fe199 100644 --- a/spec/Export/Field/FilterAttributesSpec.php +++ b/spec/Export/Field/FilterAttributesSpec.php @@ -1,5 +1,7 @@ getDisabledPropertyGroups()->willReturn([]); $this->beConstructedWith($propertyFormatter, $exportSettings); } - function it_does_not_fail_if_product_have_no_properties( + public function it_does_not_fail_if_product_have_no_properties( Product $product, ProductCollection $productCollection, PropertyGroupOptionCollection $emptyProperties diff --git a/spec/Export/Field/ImageUrlSpec.php b/spec/Export/Field/ImageUrlSpec.php index f72e9686..0ffd5fd0 100644 --- a/spec/Export/Field/ImageUrlSpec.php +++ b/spec/Export/Field/ImageUrlSpec.php @@ -14,17 +14,17 @@ class ImageUrlSpec extends ObjectBehavior { - function it_is_a_field() + public function it_is_a_field() { $this->shouldBeAnInstanceOf(FieldInterface::class); } - function it_has_a_name() + public function it_has_a_name() { $this->getName()->shouldReturn('ImageUrl'); } - function it_does_not_fail_if_the_image_is_not_present( + public function it_does_not_fail_if_the_image_is_not_present( Product $product, ProductMediaCollection $mediaCollection, ProductMediaEntity $productMediaEntity, @@ -41,14 +41,14 @@ function it_does_not_fail_if_the_image_is_not_present( $this->getValue($product)->shouldReturn('/product_image.jpg'); } - function it_does_not_fail_if_media_is_not_a_collection(CategoryEntity $category, Media $media) + public function it_does_not_fail_if_media_is_not_a_collection(CategoryEntity $category, Media $media) { $category->getMedia()->willReturn($media); $media->getUrl()->willReturn('/category_image.jpg'); $this->getValue($category)->shouldReturn('/category_image.jpg'); } - function it_does_not_fail_if_media_first_is_null(Product $product, ProductMediaCollection $mediaCollection) + public function it_does_not_fail_if_media_first_is_null(Product $product, ProductMediaCollection $mediaCollection) { $product->getMedia()->willReturn($mediaCollection); $mediaCollection->first()->willReturn(null); @@ -56,7 +56,7 @@ function it_does_not_fail_if_media_first_is_null(Product $product, ProductMediaC $this->shouldNotThrow()->during('getValue', [$product]); } - function it_does_not_fail_if_media_is_null(Product $product) + public function it_does_not_fail_if_media_is_null(Product $product) { $product->getMedia()->willReturn(null); diff --git a/spec/Export/Field/LayoutSpec.php b/spec/Export/Field/LayoutSpec.php index 5cf5e823..545094ec 100644 --- a/spec/Export/Field/LayoutSpec.php +++ b/spec/Export/Field/LayoutSpec.php @@ -17,12 +17,12 @@ class LayoutSpec extends ObjectBehavior { - function let(): void + public function let(): void { $this->beConstructedWith(new TextFilter()); } - function it_should_strip_html_tags(CategoryEntity $categoryEntity): void + public function it_should_strip_html_tags(CategoryEntity $categoryEntity): void { $cmsPage = new CmsPageEntity(); $cmsPage->setSections( @@ -44,7 +44,7 @@ function it_should_strip_html_tags(CategoryEntity $categoryEntity): void $this->getValue($categoryEntity)->shouldReturn('Lorem Ipsum Dolor sit amet'); } - function it_should_concatenate_values_from_all_slots_configs(CategoryEntity $categoryEntity): void + public function it_should_concatenate_values_from_all_slots_configs(CategoryEntity $categoryEntity): void { $cmsPage = new CmsPageEntity(); $cmsPage->setSections( @@ -75,7 +75,7 @@ function it_should_concatenate_values_from_all_slots_configs(CategoryEntity $cat $this->getValue($categoryEntity)->shouldReturn('I am concatenated'); } - function it_should_sort_output_by_position(CategoryEntity $categoryEntity): void + public function it_should_sort_output_by_position(CategoryEntity $categoryEntity): void { $cmsPage = new CmsPageEntity(); $cmsPage->setSections( @@ -109,7 +109,7 @@ function it_should_sort_output_by_position(CategoryEntity $categoryEntity): void $this->getValue($categoryEntity)->shouldReturn('I am not Yoda'); } - function it_should_not_throw_if_section_has_no_blocks(CategoryEntity $categoryEntity) + public function it_should_not_throw_if_section_has_no_blocks(CategoryEntity $categoryEntity) { $cmsPage = new CmsPageEntity(); $cmsPage->setSections( @@ -124,13 +124,13 @@ function it_should_not_throw_if_section_has_no_blocks(CategoryEntity $categoryEn $this->getValue($categoryEntity)->shouldReturn(''); } - function it_should_not_throw_if_category_has_no_layout_assigned(CategoryEntity $categoryEntity) + public function it_should_not_throw_if_category_has_no_layout_assigned(CategoryEntity $categoryEntity) { $categoryEntity->getCmsPage()->willReturn(null); $this->getValue($categoryEntity)->shouldReturn(''); } - function it_should_not_throw_if_block_has_no_slots(CategoryEntity $categoryEntity) + public function it_should_not_throw_if_block_has_no_slots(CategoryEntity $categoryEntity) { $cmsPage = new CmsPageEntity(); $cmsPage->setSections( diff --git a/spec/Export/Field/ParentCategorySpec.php b/spec/Export/Field/ParentCategorySpec.php index 41ec54a3..46f9fde4 100644 --- a/spec/Export/Field/ParentCategorySpec.php +++ b/spec/Export/Field/ParentCategorySpec.php @@ -22,7 +22,7 @@ class ParentCategorySpec extends ObjectBehavior /** @var SalesChannelEntity|Collaborator */ private Collaborator $salesChannelEntity; - function let( + public function let( SalesChannelService $channelService, CategoryBreadcrumbBuilder $breadcrumbBuilder, SalesChannelContext $salesChannelContext, diff --git a/spec/Export/Field/PriceCurrencySpec.php b/spec/Export/Field/PriceCurrencySpec.php index 95b718bb..d7efd07d 100644 --- a/spec/Export/Field/PriceCurrencySpec.php +++ b/spec/Export/Field/PriceCurrencySpec.php @@ -13,28 +13,29 @@ class PriceCurrencySpec extends ObjectBehavior { - function let(NumberFormatter $numberFormatter, CurrencyEntity $currencyEntity) + public function let(NumberFormatter $numberFormatter, CurrencyEntity $currencyEntity): void { $this->beConstructedWith($currencyEntity, $numberFormatter); } - function it_is_a_field() + public function it_is_a_field(): void { $this->shouldHaveType(FieldInterface::class); } - function it_has_a_name(CurrencyEntity $currencyEntity) + public function it_has_a_name(CurrencyEntity $currencyEntity): void { $currencyEntity->getIsoCode()->willReturn('EUR'); $this->getName()->shouldReturn('Price_EUR'); } - function it_gets_the_product_price_in_a_given_currency(Product $product, CalculatedPrice $price, NumberFormatter $numberFormatter, CurrencyEntity $currencyEntity) - { + public function it_gets_the_product_price_in_a_given_currency( + Product $product, CalculatedPrice $price, NumberFormatter $numberFormatter, CurrencyEntity $currencyEntity + ): void { $currencyEntity->getFactor()->willReturn(pi()); $product->getCalculatedPrice()->willReturn($price); $price->getTotalPrice()->willReturn(pi()); - $numberFormatter->format(pow(pi(),2))->willReturn('9.86'); + $numberFormatter->format(pi() ** 2)->willReturn('9.86'); $this->getValue($product)->shouldReturn('9.86'); } } diff --git a/spec/Export/Field/PriceSpec.php b/spec/Export/Field/PriceSpec.php index 80dfebba..1b788adf 100644 --- a/spec/Export/Field/PriceSpec.php +++ b/spec/Export/Field/PriceSpec.php @@ -12,23 +12,26 @@ class PriceSpec extends ObjectBehavior { - function let(NumberFormatter $numberFormatter) + public function let(NumberFormatter $numberFormatter): void { $this->beConstructedWith($numberFormatter); } - function it_is_a_field() + public function it_is_a_field(): void { $this->shouldHaveType(FieldInterface::class); } - function it_has_a_name() + public function it_has_a_name(): void { $this->getName()->shouldReturn('Price'); } - function it_gets_the_product_price(Product $product, CalculatedPrice $price, NumberFormatter $numberFormatter) - { + public function it_gets_the_product_price( + Product $product, + CalculatedPrice $price, + NumberFormatter $numberFormatter + ): void { $product->getCalculatedPrice()->willReturn($price); $price->getTotalPrice()->willReturn(pi()); $numberFormatter->format(pi())->willReturn('3.14'); diff --git a/spec/Export/Field/SourceFieldSpec.php b/spec/Export/Field/SourceFieldSpec.php index 8638c529..184e1612 100644 --- a/spec/Export/Field/SourceFieldSpec.php +++ b/spec/Export/Field/SourceFieldSpec.php @@ -10,24 +10,24 @@ class SourceFieldSpec extends ObjectBehavior { - private string $configuredFieldName = "Configured Category Path Field Name"; + private string $configuredFieldName = 'Configured Category Path Field Name'; - public function let() + public function let(): void { $this->beConstructedWith($this->configuredFieldName); } - public function it_is_a_field() + public function it_is_a_field(): void { $this->shouldHaveType(FieldInterface::class); } - function it_has_a_name() + public function it_has_a_name(): void { $this->getName()->shouldReturn('sourceField'); } - function it_it_should_export_configured_field_name(Category $category) + public function it_it_should_export_configured_field_name(Category $category): void { $this->beConstructedWith($this->configuredFieldName); diff --git a/spec/Export/Formatter/NumberFormatterSpec.php b/spec/Export/Formatter/NumberFormatterSpec.php index 186b54f5..ef9be274 100644 --- a/spec/Export/Formatter/NumberFormatterSpec.php +++ b/spec/Export/Formatter/NumberFormatterSpec.php @@ -1,23 +1,25 @@ format(3)->shouldReturn('3.00'); } - function it_should_respect_passed_precision() + public function it_should_respect_passed_precision() { $this->format(3, 0)->shouldReturn('3'); $this->format(3, 1)->shouldReturn('3.0'); } - function it_should_round_passed_values() + public function it_should_round_passed_values() { $this->format(3.1421)->shouldReturn('3.14'); } diff --git a/spec/Export/PropertyFormatterSpec.php b/spec/Export/PropertyFormatterSpec.php index 5793fa52..58601f78 100644 --- a/spec/Export/PropertyFormatterSpec.php +++ b/spec/Export/PropertyFormatterSpec.php @@ -11,7 +11,7 @@ class PropertyFormatterSpec extends ObjectBehavior { - function it_casts_values_to_string(FilterInterface $filter, Option $option, Group $group) + public function it_casts_values_to_string(FilterInterface $filter, Option $option, Group $group): void { $this->beConstructedWith($filter); $filter->filterValue('')->willReturn(''); diff --git a/spec/Storefront/Controller/ProxyControllerSpec.php b/spec/Storefront/Controller/ProxyControllerSpec.php index 50171845..eb73f7e9 100644 --- a/spec/Storefront/Controller/ProxyControllerSpec.php +++ b/spec/Storefront/Controller/ProxyControllerSpec.php @@ -32,7 +32,7 @@ public function let( Communication $config, ClientInterface $client, ClientBuilder $clientBuilder - ) { + ): void { $serverUrl = 'https://example.fact-finder.de/fact-finder'; $config->getServerUrl()->willReturn($serverUrl); $config->getVersion()->willReturn('ng'); @@ -45,7 +45,7 @@ public function let( $clientBuilder->withServerUrl(Argument::any())->willReturn($clientBuilder); $clientBuilder->withCredentials(Argument::any())->willReturn($clientBuilder); $clientBuilder->withVersion(Argument::any())->willReturn($clientBuilder); - $this->client = $client; + $this->client = $client; $this->clientBuilder = $clientBuilder; } @@ -55,10 +55,10 @@ public function it_should_return_success_response( EventDispatcherInterface $eventDispatcher, EnrichProxyDataEvent $event, Stream $stream - ) { + ): void { // Expect & Given $request->getMethod()->willReturn(Request::METHOD_GET); - $uri = 'rest/v5/search/example_channel?query=bag&sid=123&format=json'; + $uri = 'rest/v5/search/example_channel?query=bag&sid=123&format=json'; $_SERVER['REQUEST_URI'] = sprintf('/fact-finder/proxy/%s', $uri); $this->client->request(Request::METHOD_GET, $uri)->willReturn($response); $jsonResponse = file_get_contents(dirname(__DIR__, 2) . '/data/proxy/search-bag.json'); @@ -81,10 +81,10 @@ public function it_should_return_error_response( EventDispatcherInterface $eventDispatcher, BeforeProxyErrorResponseEvent $event, RequestInterface $requestInterface - ) { + ): void { // Expect & Given $request->getMethod()->willReturn(Request::METHOD_GET); - $uri = 'rest/v5/search/example_channel?query=bag&sid=123&format=json'; + $uri = 'rest/v5/search/example_channel?query=bag&sid=123&format=json'; $_SERVER['REQUEST_URI'] = sprintf('/fact-finder/proxy/%s', $uri); $this->client->request(Request::METHOD_GET, $uri)->willThrow(new ConnectException('Unable to connect with server.', $requestInterface->getWrappedObject())); $eventDispatcher->dispatch(Argument::type(BeforeProxyErrorResponseEvent::class))->willReturn($event); diff --git a/spec/Storefront/Controller/ResultControllerSpec.php b/spec/Storefront/Controller/ResultControllerSpec.php index 3a837469..7bfdd9d1 100644 --- a/spec/Storefront/Controller/ResultControllerSpec.php +++ b/spec/Storefront/Controller/ResultControllerSpec.php @@ -49,13 +49,13 @@ public function let( SystemConfigService $systemConfigService, Environment $twig, SeoUrlPlaceholderHandlerInterface $seoUrlPlaceholderHandler - ) { - $this->request = $request; - $this->config = $config; - $this->pageLoader = $pageLoader; - $this->container = $container; - $this->salesChannelContext = $salesChannelContext; - $this->twig = $twig; + ): void { + $this->request = $request; + $this->config = $config; + $this->pageLoader = $pageLoader; + $this->container = $container; + $this->salesChannelContext = $salesChannelContext; + $this->twig = $twig; $this->seoUrlPlaceholderHandler = $seoUrlPlaceholderHandler; $this->beConstructedWith($config, $pageLoader); $requestStack->getCurrentRequest()->willReturn($request); @@ -77,7 +77,7 @@ public function it_should_return_original_response_content_when_ssr_is_not_activ SearchAdapter $searchAdapter, Page $page, Engine $mustache - ) { + ): void { $content = 'original content'; $this->pageLoader->load($this->request, $this->salesChannelContext)->willReturn($page); $this->config->isSsrActive()->willReturn(false); diff --git a/spec/Subscriber/BeforeSendResponseEventSubscriberSpec.php b/spec/Subscriber/BeforeSendResponseEventSubscriberSpec.php index 3ee427ac..83ca3ff9 100644 --- a/spec/Subscriber/BeforeSendResponseEventSubscriberSpec.php +++ b/spec/Subscriber/BeforeSendResponseEventSubscriberSpec.php @@ -4,7 +4,6 @@ namespace spec\Omikron\FactFinder\Shopware6\Subscriber; -use DateTime; use Omikron\FactFinder\Shopware6\Subscriber\BeforeSendResponseEventSubscriber; use PhpSpec\ObjectBehavior; use PhpSpec\Wrapper\Collaborator; @@ -22,6 +21,8 @@ class BeforeSendResponseEventSubscriberSpec extends ObjectBehavior { + private const ONE_DAY_PLUS = '+1 day'; + /** @var BeforeSendResponseEvent|Collaborator */ private Collaborator $event; @@ -42,20 +43,20 @@ class BeforeSendResponseEventSubscriberSpec extends ObjectBehavior private array $subscriberMethods; - function let( + public function let( Request $request, StorefrontResponse $response, BeforeSendResponseEvent $event, SessionInterface $session, ResponseHeaderBag $headers, SalesChannelContext $context - ) { - $this->request = $request; + ): void { + $this->request = $request; $this->response = $response; - $this->session = $session; - $this->event = $event; - $this->headers = $headers; - $this->context = $context; + $this->session = $session; + $this->event = $event; + $this->headers = $headers; + $this->context = $context; $this->request->getSession()->willReturn($this->session); $this->request->isXmlHttpRequest()->willReturn(false); @@ -73,7 +74,7 @@ function let( ); } - public function it_should_not_pass_request_validation_when_ajax_request() + public function it_should_not_pass_request_validation_when_ajax_request(): void { foreach ($this->subscriberMethods as $subscriberMethod) { // Expect & Given @@ -85,7 +86,7 @@ public function it_should_not_pass_request_validation_when_ajax_request() } } - public function it_should_not_pass_request_validation_when_unsupported_response_code() + public function it_should_not_pass_request_validation_when_unsupported_response_code(): void { foreach ($this->subscriberMethods as $subscriberMethod) { // Expect & Given @@ -100,7 +101,7 @@ public function it_should_not_pass_request_validation_when_unsupported_response_ public function it_should_not_pass_request_validation_when_response_is_not_instance_of_storefront_response( BeforeSendResponseEvent $event, Response $symfonyResponse - ) { + ): void { foreach ($this->subscriberMethods as $subscriberMethod) { // Expect & Given $event->getRequest()->willReturn($this->request); @@ -111,7 +112,7 @@ public function it_should_not_pass_request_validation_when_response_is_not_insta } } - public function it_should_clear_user_id_cookie_and_has_just_logged_out_cookie_when_customer_logged_out() + public function it_should_clear_user_id_cookie_and_has_just_logged_out_cookie_when_customer_logged_out(): void { // Expect & Given $this->context->getCustomer()->willReturn(null); @@ -122,7 +123,7 @@ public function it_should_clear_user_id_cookie_and_has_just_logged_out_cookie_wh $this->isCustomerLoggedOut($this->event); } - public function it_should_clear_has_just_logged_in_cookie_when_is_already_set(ParameterBag $cookies) + public function it_should_clear_has_just_logged_in_cookie_when_is_already_set(ParameterBag $cookies): void { // Expect & Given $this->request->cookies = $cookies; @@ -134,7 +135,7 @@ public function it_should_clear_has_just_logged_in_cookie_when_is_already_set(Pa $this->isHasJustLoggedInCookieSet($this->event); } - public function it_should_set_has_just_logged_in_cookie_and_user_id_cookie(CustomerEntity $customer) + public function it_should_set_has_just_logged_in_cookie_and_user_id_cookie(CustomerEntity $customer): void { // Expect & Given $customer->getId()->willReturn('test_id_1'); @@ -142,11 +143,11 @@ public function it_should_set_has_just_logged_in_cookie_and_user_id_cookie(Custo $this->session->get('ff_has_just_logged_in', Argument::any())->willReturn(true); $this->headers->setCookie(Cookie::create('ff_has_just_logged_in') ->withValue('1') - ->withExpires((new DateTime())->modify('+1 day')->getTimestamp()) + ->withExpires((new \DateTime())->modify(self::ONE_DAY_PLUS)->getTimestamp()) ->withHttpOnly(false))->shouldBeCalled(); $this->headers->setCookie(Cookie::create('ff_user_id') ->withValue('test_id_1') - ->withExpires((new DateTime())->modify('+1 day')->getTimestamp()) + ->withExpires((new \DateTime())->modify(self::ONE_DAY_PLUS)->getTimestamp()) ->withHttpOnly(false))->shouldBeCalled(); $this->session->set('ff_has_just_logged_in', false)->shouldBeCalled(); @@ -154,13 +155,13 @@ public function it_should_set_has_just_logged_in_cookie_and_user_id_cookie(Custo $this->hasCustomerJustLoggedIn($this->event); } - public function it_should_set_has_just_logged_out_cookie() + public function it_should_set_has_just_logged_out_cookie(): void { // Expect & Given $this->session->get('ff_has_just_logged_out', Argument::any())->willReturn(true); $this->headers->setCookie(Cookie::create('ff_has_just_logged_out') ->withValue('1') - ->withExpires((new DateTime())->modify('+1 day')->getTimestamp()) + ->withExpires((new \DateTime())->modify(self::ONE_DAY_PLUS)->getTimestamp()) ->withHttpOnly(false))->shouldBeCalled(); $this->headers->clearCookie('ff_user_id')->shouldBeCalled(); $this->session->set('ff_has_just_logged_out', false)->shouldBeCalled(); diff --git a/spec/Subscriber/CategoryPageSubscriberSpec.php b/spec/Subscriber/CategoryPageSubscriberSpec.php index 9b665cbc..ae77b7d0 100644 --- a/spec/Subscriber/CategoryPageSubscriberSpec.php +++ b/spec/Subscriber/CategoryPageSubscriberSpec.php @@ -36,7 +36,7 @@ public function let( SalesChannelContext $salesChannelContext, SalesChannelEntity $salesChannelEntity, CategoryRouteResponse $categoryRouteResponse - ) { + ): void { $config->isSsrActive()->willReturn(false); $this->configure($cmsPageRoute, $config, $extensionConfig, $event, $request, $categoryEntity, $navigationPage, $extension, $salesChannelContext, $salesChannelEntity, $categoryRouteResponse); } @@ -45,7 +45,7 @@ public function it_should_add_category_page_attribute_in_category_config( CategoryEntity $categoryEntity, ArrayEntity $extension, NavigationPageLoadedEvent $event - ) { + ): void { $categoryEntity->getCustomFields()->willReturn([OmikronFactFinder::DISABLE_SEARCH_IMMEDIATE_CUSTOM_FIELD_NAME => false]); $extension->assign(Argument::withEntry('communication', Argument::withEntry('category-page', Argument::any())))->shouldBeCalled(); $this->onPageLoaded($event); @@ -56,7 +56,7 @@ public function it_should_not_add_category_page_attribute_in_category_config( ArrayEntity $extension, NavigationPageLoadedEvent $event, Request $request - ) { + ): void { $request->get('_route')->willReturn('frontend.not_home.page'); $event->getRequest()->willReturn($request); $categoryEntity->getCustomFields()->willReturn([OmikronFactFinder::DISABLE_SEARCH_IMMEDIATE_CUSTOM_FIELD_NAME => true]); @@ -67,7 +67,7 @@ public function it_should_not_add_category_page_attribute_in_category_config( public function it_should_not_fail_if_ff_cms_use_search_immediate_is_not_present_in_custom_fields( NavigationPageLoadedEvent $event, ArrayEntity $extension - ) { + ): void { $extension->assign(Argument::cetera())->shouldBeCalled(); $this->shouldNotThrow()->during('onPageLoaded', [$event]); } @@ -76,7 +76,7 @@ public function it_should_encode_category_path_correctly( CategoryEntity $categoryEntity, ArrayEntity $extension, NavigationPageLoadedEvent $event - ) { + ): void { $extension->assign(Argument::withEntry('communication', Argument::withEntry('category-page', $this->filterCategoryPath)))->shouldBeCalled(); $this->onPageLoaded($event); } @@ -85,7 +85,7 @@ public function it_should_not_add_category_path_to_add_params( CategoryEntity $categoryEntity, ArrayEntity $extension, NavigationPageLoadedEvent $event - ) { + ): void { $extension->assign(Argument::withEntry('communication', Argument::withEntry('add-params', Argument::not(Argument::containingString($this->filterCategoryPath)))))->shouldBeCalled(); $this->onPageLoaded($event); } @@ -94,7 +94,7 @@ public function it_should_configure_add_params_if_set( CategoryEntity $categoryEntity, ArrayEntity $extension, NavigationPageLoadedEvent $event - ) { + ): void { $extension->assign(Argument::withEntry('communication', Argument::withEntry('add-params', 'navigation=true')))->shouldBeCalled(); $this->onPageLoaded($event); } @@ -111,7 +111,7 @@ public function it_should_implode_multiple_add_params_correctly( SalesChannelContext $salesChannelContext, SalesChannelEntity $salesChannelEntity, CategoryRouteResponse $categoryRouteResponse - ) { + ): void { $this->configure($cmsPageRoute, $config, $extensionConfig, $event, $request, $categoryEntity, $navigationPage, $extension, $salesChannelContext, $salesChannelEntity, $categoryRouteResponse, ['param1' => 'navigation=true', 'param2' =>'filterCustom=customValue']); $categoryEntity->getCustomFields()->willReturn([]); $extension->assign(Argument::withEntry('communication', Argument::withEntry('add-params', 'navigation=true,filterCustom=customValue')))->shouldBeCalled(); @@ -130,7 +130,7 @@ public function it_should_merge_add_params_from_the_configuration_subscriber( SalesChannelContext $salesChannelContext, SalesChannelEntity $salesChannelEntity, CategoryRouteResponse $categoryRouteResponse - ) { + ): void { $baseAddParams = 'configurationParam=baseValue,configurationParam2=baseValue'; $categoryAddParams = ['param1'=>'configurationParam=overridden', 'param2'=>'categoryParam=value1']; @@ -156,8 +156,8 @@ private function configure( SalesChannelContext $salesChannelContext, SalesChannelEntity $salesChannelEntity, CategoryRouteResponse $categoryRouteResponse, - array $addParams = ['param1' =>'navigation=true'] //addParams parameters collections are passed as associative array (see comment src/Subscriber/CategoryPageSubscriber.php:55) - ) { + array $addParams = ['param1' =>'navigation=true'] // addParams parameters collections are passed as associative array (see comment src/Subscriber/CategoryPageSubscriber.php:55) + ): void { $navigationId = '1'; $extensionConfig->getTrackingSettings()->willReturn( [ diff --git a/spec/Subscriber/ConfigurationSubscriberSpec.php b/spec/Subscriber/ConfigurationSubscriberSpec.php index a5f2baf7..52c4cc38 100644 --- a/spec/Subscriber/ConfigurationSubscriberSpec.php +++ b/spec/Subscriber/ConfigurationSubscriberSpec.php @@ -4,7 +4,6 @@ namespace spec\Omikron\FactFinder\Shopware6\Subscriber; -use Exception; use Omikron\FactFinder\Communication\Version; use Omikron\FactFinder\Shopware6\Config\Communication; use Omikron\FactFinder\Shopware6\Config\ExtensionConfig; @@ -31,7 +30,7 @@ public function let( Communication $communication, ExtensionConfig $extensionConfig, RouterInterface $router - ) { + ): void { $fieldRoles = []; $communicationParameters = []; $communication->getServerUrl()->willReturn('https://factfinder.server.com'); @@ -47,15 +46,15 @@ public function let( } public function it_will_return_factfinderchannel_for_specific_sales_channel_id( - Communication $communication, + Communication $communication, GenericPageLoadedEvent $event, - SalesChannelContext $salesChannelContext, - SalesChannelEntity $salesChannel, - CustomerEntity $customer, - CurrencyEntity $currency, - Request $request, - Page $page - ) { + SalesChannelContext $salesChannelContext, + SalesChannelEntity $salesChannel, + CustomerEntity $customer, + CurrencyEntity $currency, + Request $request, + Page $page + ): void { $event->getSalesChannelContext()->willReturn($salesChannelContext); $salesChannelContext->getCustomer()->willReturn($customer); $customer->getId()->willReturn(1); @@ -81,7 +80,7 @@ public function it_will_return_factfinderchannel_for_specific_sales_channel_id( new LogicalAndToken( [ new TypeToken(ArrayEntity::class), - Argument::withEntry('communication', Argument::withEntry('channel', 'some_ff_channel')) + Argument::withEntry('communication', Argument::withEntry('channel', 'some_ff_channel')), ] ))->shouldBeCalled(); @@ -89,16 +88,16 @@ public function it_will_return_factfinderchannel_for_specific_sales_channel_id( } public function it_will_add_page_extension_for_storefront_render_event( - Communication $communication, - StorefrontRenderEvent $event, - SalesChannelContext $salesChannelContext, - SalesChannelEntity $salesChannel, - CustomerEntity $customer, - CurrencyEntity $currency, - Request $request, - Struct $extension, - Page $page - ) { + Communication $communication, + StorefrontRenderEvent $event, + SalesChannelContext $salesChannelContext, + SalesChannelEntity $salesChannel, + CustomerEntity $customer, + CurrencyEntity $currency, + Request $request, + Struct $extension, + Page $page + ): void { $event->getSalesChannelContext()->willReturn($salesChannelContext); $salesChannelContext->getCustomer()->willReturn($customer); $customer->getId()->willReturn(1); @@ -124,7 +123,7 @@ public function it_will_add_page_extension_for_storefront_render_event( new LogicalAndToken( [ new TypeToken(ArrayEntity::class), - Argument::withEntry('communication', Argument::withEntry('channel', 'some_ff_channel')) + Argument::withEntry('communication', Argument::withEntry('channel', 'some_ff_channel')), ] ))->shouldBeCalled(); @@ -132,14 +131,14 @@ public function it_will_add_page_extension_for_storefront_render_event( } public function it_will_throw_exception_when_event_does_not_have_page( - Communication $communication, - StorefrontRenderEvent $event, - SalesChannelContext $salesChannelContext, - SalesChannelEntity $salesChannel, - CustomerEntity $customer, - CurrencyEntity $currency, - Request $request - ) { + Communication $communication, + StorefrontRenderEvent $event, + SalesChannelContext $salesChannelContext, + SalesChannelEntity $salesChannel, + CustomerEntity $customer, + CurrencyEntity $currency, + Request $request + ): void { $event->getSalesChannelContext()->willReturn($salesChannelContext); $salesChannelContext->getCustomer()->willReturn($customer); $customer->getId()->willReturn(1); @@ -159,6 +158,8 @@ public function it_will_throw_exception_when_event_does_not_have_page( $request->isXmlHttpRequest()->willReturn(false); $event->getParameters()->willReturn([]); $this->onPageLoaded($event); - $this->shouldThrow(new Exception(sprintf('Unable to get page from event %s.', get_class($event->getWrappedObject())))); + $this->shouldThrow( + new \Exception(sprintf('Unable to get page from event %s.', get_class($event->getWrappedObject()))) + ); } } diff --git a/src/Command/RunPreprocessorCommand.php b/src/Command/RunPreprocessorCommand.php index ee264561..1924c1c2 100644 --- a/src/Command/RunPreprocessorCommand.php +++ b/src/Command/RunPreprocessorCommand.php @@ -4,23 +4,9 @@ namespace Omikron\FactFinder\Shopware6\Command; -use Omikron\FactFinder\Shopware6\DataAbstractionLayer\FeedPreprocessor; -use Omikron\FactFinder\Shopware6\DataAbstractionLayer\FeedPreprocessorEntryPersister; -use Omikron\FactFinder\Shopware6\Export\ExportProducts; -use Omikron\FactFinder\Shopware6\Export\SalesChannelService; -use Shopware\Core\Content\Product\ProductEntity; -use Shopware\Core\Defaults; -use Shopware\Core\Framework\Api\Context\SystemSource; -use Shopware\Core\Framework\Context; -use Shopware\Core\Framework\DataAbstractionLayer\EntityRepository; -use Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria; -use Shopware\Core\System\Language\LanguageEntity; -use Shopware\Core\System\SalesChannel\SalesChannelEntity; use Symfony\Component\Console\Command\Command; -use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; -use Symfony\Component\Console\Question\Question; /** * @SuppressWarnings(PHPMD.CouplingBetweenObjects) @@ -31,77 +17,19 @@ class RunPreprocessorCommand extends Command public const SALES_CHANNEL_ARGUMENT = 'sales_channel'; public const SALES_CHANNEL_LANGUAGE_ARGUMENT = 'language'; - private FeedPreprocessor $feedPreprocessor; - private FeedPreprocessorEntryPersister $entryPersister; - private ExportProducts $exportProducts; - private SalesChannelService $channelService; - private EntityRepository $languageRepository; - private EntityRepository $channelRepository; - - public function __construct( - FeedPreprocessor $feedPreprocessor, - FeedPreprocessorEntryPersister $entryPersister, - SalesChannelService $salesChannelService, - ExportProducts $exportProducts, - EntityRepository $languageRepository, - EntityRepository $channelRepository - ) { - parent::__construct(); - $this->feedPreprocessor = $feedPreprocessor; - $this->entryPersister = $entryPersister; - $this->channelService = $salesChannelService; - $this->exportProducts = $exportProducts; - $this->languageRepository = $languageRepository; - $this->channelRepository = $channelRepository; - } - public function configure(): void { $this->setName('factfinder:data:pre-process'); $this->setDescription('Run the Feed preprocessor'); - $this->addArgument(self::SALES_CHANNEL_LANGUAGE_ARGUMENT, InputArgument::OPTIONAL, 'ID of the sales channel language'); - $this->addArgument(self::SALES_CHANNEL_ARGUMENT, InputArgument::OPTIONAL, 'ID of the sales channel'); } - public function execute(InputInterface $input, OutputInterface $output) + /** + * @SuppressWarnings(PHPMD.UnusedFormalParameter) + */ + public function execute(InputInterface $input, OutputInterface $output): int { $output->writeln('Cache export is not support in SDK version 5.x'); return 0; - - if ($input->isInteractive()) { - $helper = $this->getHelper('question'); - $salesChannel = $this->getSalesChannel($helper->ask($input, $output, new Question('ID of the sales channel (leave empty if no value): '))); - $language = $this->getLanguage($helper->ask($input, $output, new Question('ID of the sales channel language (leave empty if no value): '))); - } else { - $salesChannel = $this->getSalesChannel($input->getArgument(self::SALES_CHANNEL_ARGUMENT)); - $language = $this->getLanguage($input->getArgument(self::SALES_CHANNEL_LANGUAGE_ARGUMENT)); - } - - $salesChannelContext = $this->channelService->getSalesChannelContext($salesChannel, $language->getId()); - $context = $salesChannelContext->getContext(); - - /** @var ProductEntity $product */ - foreach ($this->exportProducts->getByContext($salesChannelContext) as $product) { - $this->entryPersister->deleteAllProductEntries($product->getProductNumber(), $context); - $this->entryPersister->insertProductEntries($this->feedPreprocessor->createEntries($product, $context), $context); - } - - return 0; - } - - private function getLanguage(string $id = null): LanguageEntity - { - return $this->languageRepository->search( - new Criteria([$id ?: Defaults::LANGUAGE_SYSTEM]), - new Context(new SystemSource()) - )->first(); - } - - private function getSalesChannel(string $id = null): ?SalesChannelEntity - { - return !is_null($id) - ? $this->channelRepository->search(new Criteria([$id]), new Context(new SystemSource()))->first() - : null; } } diff --git a/src/Resources/views/storefront/components/factfinder/record-list-slider.html.twig b/src/Resources/views/storefront/components/factfinder/record-list-slider.html.twig index 1a0d8a0a..def9a862 100644 --- a/src/Resources/views/storefront/components/factfinder/record-list-slider.html.twig +++ b/src/Resources/views/storefront/components/factfinder/record-list-slider.html.twig @@ -8,7 +8,7 @@