From 58eebdda23bb41e5d57325735344f5027db8fea0 Mon Sep 17 00:00:00 2001 From: Michael Telgmann Date: Tue, 12 Mar 2024 09:37:18 +0100 Subject: [PATCH] NEXT-34339 - Update PHPStan to 1.10.60 --- composer.json | 2 +- .../Cms/ProductListingCmsElementResolver.php | 9 ++- .../Hook/Pricing/PriceCollectionFacade.php | 6 +- .../MediaRepositoryTest.php | 4 +- .../Framework/Api/Sync/SyncFkResolver.php | 6 +- .../CompilerPass/RateLimiterCompilerPass.php | 3 +- src/Core/Framework/Struct/Collection.php | 3 - .../Validation/SalesChannelValidator.php | 18 ++--- .../Subscriber/CustomFieldSubscriber.php | 2 +- .../StateMachine/StateMachineRegistryTest.php | 4 +- .../DeleteUnusedGuestCustomersCommandTest.php | 4 +- .../DeleteUnusedGuestCustomerServiceTest.php | 4 +- .../Checkout/Order/OrderRepositoryTest.php | 4 +- .../Order/SalesChannel/OrderRouteTest.php | 4 +- .../Action/SetOrderStateActionTest.php | 4 +- .../ProductExportGenerateTaskHandlerTest.php | 69 +++++++++---------- .../App/Manifest/ModuleLoaderTest.php | 2 + .../Page/Account/EditOrderPageTest.php | 3 - .../Page/StorefrontPageTestBehaviour.php | 40 +++++++---- 19 files changed, 103 insertions(+), 88 deletions(-) diff --git a/composer.json b/composer.json index d8065be0496..1bdd57f089e 100644 --- a/composer.json +++ b/composer.json @@ -174,7 +174,7 @@ "phpdocumentor/reflection-docblock": "^5.3.0", "phpdocumentor/type-resolver": "^1.7.1", "phpstan/extension-installer": "^1.3.1", - "phpstan/phpstan": "1.10.59", + "phpstan/phpstan": "1.10.60", "phpstan/phpstan-deprecation-rules": "1.1.4", "phpstan/phpstan-phpunit": "1.3.16", "phpstan/phpstan-symfony": "1.3.7", diff --git a/src/Core/Content/Product/Cms/ProductListingCmsElementResolver.php b/src/Core/Content/Product/Cms/ProductListingCmsElementResolver.php index 21fa336abae..3b301a741c9 100644 --- a/src/Core/Content/Product/Cms/ProductListingCmsElementResolver.php +++ b/src/Core/Content/Product/Cms/ProductListingCmsElementResolver.php @@ -12,6 +12,7 @@ use Shopware\Core\Framework\DataAbstractionLayer\EntityRepository; use Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria; use Shopware\Core\Framework\Log\Package; +use Shopware\Core\Framework\Uuid\Uuid; use Shopware\Core\System\SalesChannel\SalesChannelContext; use Symfony\Component\HttpFoundation\Request; @@ -106,12 +107,16 @@ private function addDefaultSorting(Request $request, CmsSlotEntity $slot, SalesC return; } - // if we have no specific order given at this point, set the order to be the highest's priority available sorting + // if we have no specific order given at this point, set the order to the highest priority available sorting if ($request->get('availableSortings')) { $availableSortings = $request->get('availableSortings'); arsort($availableSortings, \SORT_DESC | \SORT_NUMERIC); + $sortingId = array_key_first($availableSortings); + if (!\is_string($sortingId) || !Uuid::isValid($sortingId)) { + return; + } - $criteria = new Criteria([array_key_first($availableSortings)]); + $criteria = new Criteria([$sortingId]); $request->request->set('order', $this->sortingRepository->search($criteria, $context->getContext())->first()?->get('key')); } diff --git a/src/Core/Content/Product/Hook/Pricing/PriceCollectionFacade.php b/src/Core/Content/Product/Hook/Pricing/PriceCollectionFacade.php index ab7c6bc9453..fce3cd64f3d 100644 --- a/src/Core/Content/Product/Hook/Pricing/PriceCollectionFacade.php +++ b/src/Core/Content/Product/Hook/Pricing/PriceCollectionFacade.php @@ -45,7 +45,7 @@ public function reset(): void /** * The `change()` function allows a complete overwrite of the product quantity prices * - * @param array{to: int|null, price: PriceCollection}[] $changes + * @param list $changes * * @example pricing-cases/product-pricing.twig 40 5 Overwrite the product prices with a new quantity price graduation */ @@ -65,7 +65,9 @@ public function change(array $changes): void unset($mapped[null]); \ksort($mapped, \SORT_NUMERIC); - $max = \max(\array_keys($mapped)); + $arrayKeys = \array_keys($mapped); + \assert(!empty($arrayKeys)); + $max = \max($arrayKeys); $mapped[$max + 1] = $last; diff --git a/src/Core/Content/Test/Media/DataAbstractionLayer/MediaRepositoryTest.php b/src/Core/Content/Test/Media/DataAbstractionLayer/MediaRepositoryTest.php index f18c2a1dd2f..7836614cb65 100644 --- a/src/Core/Content/Test/Media/DataAbstractionLayer/MediaRepositoryTest.php +++ b/src/Core/Content/Test/Media/DataAbstractionLayer/MediaRepositoryTest.php @@ -582,8 +582,8 @@ private function getOrderData(string $orderId, ?string $mediaId = null): array 'stateId' => $this->getContainer()->get(InitialStateIdLoader::class)->get(OrderDeliveryStates::STATE_MACHINE), 'shippingMethodId' => $this->getValidShippingMethodId(), 'shippingCosts' => new CalculatedPrice(10, 10, new CalculatedTaxCollection(), new TaxRuleCollection()), - 'shippingDateEarliest' => date(\DATE_ISO8601), - 'shippingDateLatest' => date(\DATE_ISO8601), + 'shippingDateEarliest' => date(\DATE_ATOM), + 'shippingDateLatest' => date(\DATE_ATOM), 'shippingOrderAddress' => [ 'salutationId' => $salutation, 'firstName' => 'Floy', diff --git a/src/Core/Framework/Api/Sync/SyncFkResolver.php b/src/Core/Framework/Api/Sync/SyncFkResolver.php index fe5cd9d4a09..99c1ea0fc1d 100644 --- a/src/Core/Framework/Api/Sync/SyncFkResolver.php +++ b/src/Core/Framework/Api/Sync/SyncFkResolver.php @@ -80,7 +80,7 @@ public function resolve(string $key, string $entity, array $payload): array } /** - * @param array> $payload + * @param array> $payload * * @return array> */ @@ -116,14 +116,14 @@ private function collect(string $entity, array &$payload, string $pointer): arra $resolver = (string) $value['resolver']; - $row[$fieldName] = $reference = new FkReference( + $reference = new FkReference( implode('/', [$current, $fieldName]), $definition->getEntityName(), $field->getPropertyName(), $value['value'], $value['nullOnMissing'] ?? false ); - + $row[$fieldName] = $reference; $map[$resolver][] = $reference; } diff --git a/src/Core/Framework/DependencyInjection/CompilerPass/RateLimiterCompilerPass.php b/src/Core/Framework/DependencyInjection/CompilerPass/RateLimiterCompilerPass.php index cb07903b49f..36b25343939 100644 --- a/src/Core/Framework/DependencyInjection/CompilerPass/RateLimiterCompilerPass.php +++ b/src/Core/Framework/DependencyInjection/CompilerPass/RateLimiterCompilerPass.php @@ -25,7 +25,6 @@ public function process(ContainerBuilder $container): void { $rateLimiter = $container->getDefinition(RateLimiter::class); - /** @var array> $rateLimiterConfig */ $rateLimiterConfig = $container->getParameter('shopware.api.rate_limiter'); foreach ($rateLimiterConfig as $name => $config) { @@ -48,7 +47,7 @@ public function process(ContainerBuilder $container): void } /** - * @param array|bool|string|int> $config + * @param array $config */ private function setConfigDefaults(array &$config): void { diff --git a/src/Core/Framework/Struct/Collection.php b/src/Core/Framework/Struct/Collection.php index 1d956f3dfc3..ff3519d66b3 100644 --- a/src/Core/Framework/Struct/Collection.php +++ b/src/Core/Framework/Struct/Collection.php @@ -151,9 +151,6 @@ public function getElements(): array return $this->elements; } - /** - * @return list - */ public function jsonSerialize(): array { return array_values($this->elements); diff --git a/src/Core/System/SalesChannel/Validation/SalesChannelValidator.php b/src/Core/System/SalesChannel/Validation/SalesChannelValidator.php index 2644dbafbf8..a969065d0f6 100644 --- a/src/Core/System/SalesChannel/Validation/SalesChannelValidator.php +++ b/src/Core/System/SalesChannel/Validation/SalesChannelValidator.php @@ -21,6 +21,8 @@ /** * @internal + * + * @phpstan-type Mapping array, updateId: string, deletions: list, state: list}> */ #[Package('buyers-experience')] class SalesChannelValidator implements EventSubscriberInterface @@ -74,12 +76,12 @@ public function handleSalesChannelLanguageIds(PreWriteValidationEvent $event): v * 'current_default' => 'en', * 'new_default' => 'de', * 'inserts' => ['de', 'en'], - * 'updates' => ['de', 'de'], + * 'updateId' => 'de', * 'deletions' => ['gb'], * 'state' => ['en', 'gb'] * ] * - * @return array>> + * @return Mapping */ private function extractMapping(PreWriteValidationEvent $event): array { @@ -100,7 +102,7 @@ private function extractMapping(PreWriteValidationEvent $event): array } /** - * @param array>> $mapping + * @param Mapping $mapping */ private function handleSalesChannelMapping(array &$mapping, WriteCommand $command): void { @@ -110,7 +112,7 @@ private function handleSalesChannelMapping(array &$mapping, WriteCommand $comman if ($command instanceof UpdateCommand) { $id = Uuid::fromBytesToHex($command->getPrimaryKey()['id']); - $mapping[$id]['updates'] = Uuid::fromBytesToHex($command->getPayload()['language_id']); + $mapping[$id]['updateId'] = Uuid::fromBytesToHex($command->getPayload()['language_id']); return; } @@ -134,7 +136,7 @@ private function isSupportedSalesChannelType(WriteCommand $command): bool } /** - * @param array> $mapping + * @param Mapping $mapping */ private function handleSalesChannelLanguageMapping(array &$mapping, WriteCommand $command): void { @@ -180,8 +182,8 @@ private function validateLanguages(array $mapping, PreWriteValidationEvent $even $deletions[$id] = $channel['current_default']; } - if (isset($channel['updates']) && !$this->validUpdateCase($channel)) { - $updates[$id] = $channel['updates']; + if (isset($channel['updateId']) && !$this->validUpdateCase($channel)) { + $updates[$id] = $channel['updateId']; } } @@ -205,7 +207,7 @@ private function validInsertCase(array $channel): bool */ private function validUpdateCase(array $channel): bool { - $updateId = $channel['updates']; + $updateId = $channel['updateId']; return \in_array($updateId, $channel['state'], true) || empty($channel['new_default']) && $updateId === $channel['current_default'] diff --git a/src/Core/System/Snippet/Subscriber/CustomFieldSubscriber.php b/src/Core/System/Snippet/Subscriber/CustomFieldSubscriber.php index c8a89fa3ba2..8bab773ec43 100644 --- a/src/Core/System/Snippet/Subscriber/CustomFieldSubscriber.php +++ b/src/Core/System/Snippet/Subscriber/CustomFieldSubscriber.php @@ -84,7 +84,7 @@ public function customFieldIsDeleted(EntityDeletedEvent $event): void /** * @param array> $snippetSets - * @param array $snippets + * @param list> $snippets */ private function setInsertSnippets(EntityWriteResult $writeResult, array $snippetSets, array &$snippets): void { diff --git a/src/Core/System/Test/StateMachine/StateMachineRegistryTest.php b/src/Core/System/Test/StateMachine/StateMachineRegistryTest.php index 0c4cd71a45c..5803bb483e1 100644 --- a/src/Core/System/Test/StateMachine/StateMachineRegistryTest.php +++ b/src/Core/System/Test/StateMachine/StateMachineRegistryTest.php @@ -230,8 +230,8 @@ private function createOrderWithPartiallyReturnedDeliveryState(): string 'id' => $orderDeliveryId, 'shippingMethodId' => $this->getValidShippingMethodId(), 'shippingCosts' => new CalculatedPrice(10, 10, new CalculatedTaxCollection(), new TaxRuleCollection()), - 'shippingDateEarliest' => date(\DATE_ISO8601), - 'shippingDateLatest' => date(\DATE_ISO8601), + 'shippingDateEarliest' => date(\DATE_ATOM), + 'shippingDateLatest' => date(\DATE_ATOM), 'stateId' => $returnedPartially, 'shippingOrderAddress' => [ 'salutationId' => $this->getValidSalutationId(), diff --git a/tests/integration/Core/Checkout/Customer/Command/DeleteUnusedGuestCustomersCommandTest.php b/tests/integration/Core/Checkout/Customer/Command/DeleteUnusedGuestCustomersCommandTest.php index e287aa409e6..84daa68a02b 100644 --- a/tests/integration/Core/Checkout/Customer/Command/DeleteUnusedGuestCustomersCommandTest.php +++ b/tests/integration/Core/Checkout/Customer/Command/DeleteUnusedGuestCustomersCommandTest.php @@ -209,8 +209,8 @@ private function createOrderForCustomer(array $customer): string 'stateId' => $this->getContainer()->get(InitialStateIdLoader::class)->get(OrderDeliveryStates::STATE_MACHINE), 'shippingMethodId' => $this->getValidShippingMethodId(), 'shippingCosts' => new CalculatedPrice(10, 10, new CalculatedTaxCollection(), new TaxRuleCollection()), - 'shippingDateEarliest' => date(\DATE_ISO8601), - 'shippingDateLatest' => date(\DATE_ISO8601), + 'shippingDateEarliest' => date(\DATE_ATOM), + 'shippingDateLatest' => date(\DATE_ATOM), 'shippingOrderAddressId' => $customer['defaultShippingAddressId'], 'positions' => [ [ diff --git a/tests/integration/Core/Checkout/Customer/DeleteUnusedGuestCustomerServiceTest.php b/tests/integration/Core/Checkout/Customer/DeleteUnusedGuestCustomerServiceTest.php index b024f974be2..48548081d49 100644 --- a/tests/integration/Core/Checkout/Customer/DeleteUnusedGuestCustomerServiceTest.php +++ b/tests/integration/Core/Checkout/Customer/DeleteUnusedGuestCustomerServiceTest.php @@ -290,8 +290,8 @@ private function createOrderForCustomer(array $customer): string 'stateId' => $this->getContainer()->get(InitialStateIdLoader::class)->get(OrderDeliveryStates::STATE_MACHINE), 'shippingMethodId' => $this->getValidShippingMethodId(), 'shippingCosts' => new CalculatedPrice(10, 10, new CalculatedTaxCollection(), new TaxRuleCollection()), - 'shippingDateEarliest' => date(\DATE_ISO8601), - 'shippingDateLatest' => date(\DATE_ISO8601), + 'shippingDateEarliest' => date(\DATE_ATOM), + 'shippingDateLatest' => date(\DATE_ATOM), 'shippingOrderAddressId' => $customer['defaultShippingAddressId'], 'positions' => [ [ diff --git a/tests/integration/Core/Checkout/Order/OrderRepositoryTest.php b/tests/integration/Core/Checkout/Order/OrderRepositoryTest.php index e06d385b6af..0577ff07c5c 100644 --- a/tests/integration/Core/Checkout/Order/OrderRepositoryTest.php +++ b/tests/integration/Core/Checkout/Order/OrderRepositoryTest.php @@ -261,8 +261,8 @@ private function getOrderData(string $orderId, Context $context): array 'stateId' => $this->getContainer()->get(InitialStateIdLoader::class)->get(OrderDeliveryStates::STATE_MACHINE), 'shippingMethodId' => $this->getValidShippingMethodId(), 'shippingCosts' => new CalculatedPrice(10, 10, new CalculatedTaxCollection(), new TaxRuleCollection()), - 'shippingDateEarliest' => date(\DATE_ISO8601), - 'shippingDateLatest' => date(\DATE_ISO8601), + 'shippingDateEarliest' => date(\DATE_ATOM), + 'shippingDateLatest' => date(\DATE_ATOM), 'shippingOrderAddress' => [ 'salutationId' => $salutation, 'firstName' => 'Floy', diff --git a/tests/integration/Core/Checkout/Order/SalesChannel/OrderRouteTest.php b/tests/integration/Core/Checkout/Order/SalesChannel/OrderRouteTest.php index 4c47080aa7e..95fd9d1b0cc 100644 --- a/tests/integration/Core/Checkout/Order/SalesChannel/OrderRouteTest.php +++ b/tests/integration/Core/Checkout/Order/SalesChannel/OrderRouteTest.php @@ -748,8 +748,8 @@ private function getOrderData(string $orderId, string $customerId, string $email 'stateId' => $this->getContainer()->get(InitialStateIdLoader::class)->get(OrderDeliveryStates::STATE_MACHINE), 'shippingMethodId' => $this->getValidShippingMethodId(), 'shippingCosts' => new CalculatedPrice(10, 10, new CalculatedTaxCollection(), new TaxRuleCollection()), - 'shippingDateEarliest' => date(\DATE_ISO8601), - 'shippingDateLatest' => date(\DATE_ISO8601), + 'shippingDateEarliest' => date(\DATE_ATOM), + 'shippingDateLatest' => date(\DATE_ATOM), 'shippingOrderAddress' => [ 'salutationId' => $salutation, 'firstName' => 'Floy', diff --git a/tests/integration/Core/Content/Flow/Dispatching/Action/SetOrderStateActionTest.php b/tests/integration/Core/Content/Flow/Dispatching/Action/SetOrderStateActionTest.php index 2b6b4318461..80cac287a72 100644 --- a/tests/integration/Core/Content/Flow/Dispatching/Action/SetOrderStateActionTest.php +++ b/tests/integration/Core/Content/Flow/Dispatching/Action/SetOrderStateActionTest.php @@ -265,8 +265,8 @@ private function getOrderData(string $orderId, Context $context): array 'stateId' => $this->getContainer()->get(InitialStateIdLoader::class)->get(OrderDeliveryStates::STATE_MACHINE), 'shippingMethodId' => $this->getValidShippingMethodId(), 'shippingCosts' => new CalculatedPrice(10, 10, new CalculatedTaxCollection(), new TaxRuleCollection()), - 'shippingDateEarliest' => date(\DATE_ISO8601), - 'shippingDateLatest' => date(\DATE_ISO8601), + 'shippingDateEarliest' => date(\DATE_ATOM), + 'shippingDateLatest' => date(\DATE_ATOM), 'shippingOrderAddress' => [ 'salutationId' => $salutation, 'firstName' => 'Floy', diff --git a/tests/integration/Core/Content/ProductExport/ScheduledTask/ProductExportGenerateTaskHandlerTest.php b/tests/integration/Core/Content/ProductExport/ScheduledTask/ProductExportGenerateTaskHandlerTest.php index ca4266ff331..7db137b88ad 100644 --- a/tests/integration/Core/Content/ProductExport/ScheduledTask/ProductExportGenerateTaskHandlerTest.php +++ b/tests/integration/Core/Content/ProductExport/ScheduledTask/ProductExportGenerateTaskHandlerTest.php @@ -3,7 +3,6 @@ namespace Shopware\Tests\Integration\Core\Content\ProductExport\ScheduledTask; use Doctrine\DBAL\Connection; -use Doctrine\DBAL\Exception; use League\Flysystem\FilesystemOperator; use PHPUnit\Framework\Attributes\Group; use PHPUnit\Framework\TestCase; @@ -20,6 +19,7 @@ use Shopware\Core\Framework\Test\TestCaseBase\AdminFunctionalTestBehaviour; use Shopware\Core\Framework\Test\TestCaseBase\QueueTestBehaviour; use Shopware\Core\Framework\Uuid\Uuid; +use Shopware\Core\System\Language\LanguageEntity; use Shopware\Core\System\SalesChannel\Aggregate\SalesChannelDomain\SalesChannelDomainCollection; use Shopware\Core\System\SalesChannel\Aggregate\SalesChannelDomain\SalesChannelDomainEntity; use Shopware\Core\System\SalesChannel\Context\SalesChannelContextFactory; @@ -48,13 +48,13 @@ class ProductExportGenerateTaskHandlerTest extends TestCase protected function setUp(): void { - if (!$this->getContainer()->has(ProductPageSeoUrlRoute::class)) { + if (!static::getContainer()->has(ProductPageSeoUrlRoute::class)) { static::markTestSkipped('ProductExport tests need storefront bundle to be active'); } - $this->productExportRepository = $this->getContainer()->get('product_export.repository'); + $this->productExportRepository = static::getContainer()->get('product_export.repository'); $this->context = Context::createDefaultContext(); - $this->fileSystem = $this->getContainer()->get('shopware.filesystem.private'); + $this->fileSystem = static::getContainer()->get('shopware.filesystem.private'); } #[Group('quarantined')] @@ -82,12 +82,12 @@ public function testRun(): void static::assertIsInt($response['handledMessages']); static::assertSame(1, $response['handledMessages']); - $filePath = sprintf('%s/Testexport.csv', $this->getContainer()->getParameter('product_export.directory')); + $filePath = sprintf('%s/Testexport.csv', static::getContainer()->getParameter('product_export.directory')); $fileContent = $this->fileSystem->read($filePath); - $csvRows = explode(\PHP_EOL, (string) $fileContent); + $csvRows = explode(\PHP_EOL, $fileContent); - static::assertTrue($this->fileSystem->directoryExists($this->getContainer()->getParameter('product_export.directory'))); + static::assertTrue($this->fileSystem->directoryExists(static::getContainer()->getParameter('product_export.directory'))); static::assertTrue($this->fileSystem->fileExists($filePath)); static::assertCount(4, $csvRows); @@ -96,7 +96,6 @@ public function testRun(): void static::assertGreaterThan($previousGeneratedAt, $newExport->getGeneratedAt()); } - #[Group('quarantined')] public function testSkipGenerateByCronjobFalseProductExports(): void { $this->createProductStream(); @@ -117,12 +116,12 @@ public function testSkipGenerateByCronjobFalseProductExports(): void static::assertIsInt($response['handledMessages']); static::assertSame(0, $response['handledMessages']); - $filePath = sprintf('%s/Testexport.csv', $this->getContainer()->getParameter('product_export.directory')); + $filePath = sprintf('%s/Testexport.csv', static::getContainer()->getParameter('product_export.directory')); static::assertFalse($this->fileSystem->fileExists($filePath)); $newExport = $this->productExportRepository->search(new Criteria([$exportId]), $this->context)->getEntities()->first(); static::assertNotNull($newExport); - static::assertSame($previousGeneratedAt, $newExport->getGeneratedAt()); + static::assertEquals($previousGeneratedAt, $newExport->getGeneratedAt()); } #[Group('quarantined')] @@ -134,12 +133,12 @@ public function testGeneratedAtAndIntervalsAreRespected(): void $now = new \DateTimeImmutable('now', new \DateTimeZone('UTC')); // Create one ProductExport, last exported 30 days ago, to be exported every hour - $this->createTestEntity($now->sub(new \DateInterval('P30M')), 3600, 'Testexport.csv'); + $this->createTestEntity($now->sub(new \DateInterval('P30M')), 3600); // Create a second ProductExport, last exported 30 minutes ago, to be exported every hour $this->createTestEntity($now->sub(new \DateInterval('PT30M')), 3600, 'Testexport1.csv'); - $bus = $this->getContainer()->get('messenger.bus.shopware'); + $bus = static::getContainer()->get('messenger.bus.shopware'); static::assertInstanceOf(TraceableMessageBus::class, $bus); $this->clearQueue(); @@ -160,12 +159,12 @@ public function testGeneratedAtIsNullWorks(): void $now = new \DateTimeImmutable('now', new \DateTimeZone('UTC')); // Create one ProductExport, last exported 30 days ago, to be exported every hour - $this->createTestEntity(null, 3600, 'Testexport.csv'); + $this->createTestEntity(null, 3600); // Create a second ProductExport, last exported 30 minutes ago, to be exported every hour $this->createTestEntity($now->sub(new \DateInterval('PT30M')), 3600, 'Testexport1.csv'); - $bus = $this->getContainer()->get('messenger.bus.shopware'); + $bus = static::getContainer()->get('messenger.bus.shopware'); static::assertInstanceOf(TraceableMessageBus::class, $bus); $this->clearQueue(); @@ -182,7 +181,7 @@ public function testSchedulerRunIfSalesChannelIsActive(): void { $this->prepareProductExportForScheduler(true); - $bus = $this->getContainer()->get('messenger.bus.shopware'); + $bus = static::getContainer()->get('messenger.bus.shopware'); static::assertInstanceOf(TraceableMessageBus::class, $bus); $this->clearQueue(); @@ -199,7 +198,7 @@ public function testSchedulerDontRunIfSalesChannelIsNotActive(): void { $this->prepareProductExportForScheduler(false); - $bus = $this->getContainer()->get('messenger.bus.shopware'); + $bus = static::getContainer()->get('messenger.bus.shopware'); static::assertInstanceOf(TraceableMessageBus::class, $bus); $this->clearQueue(); @@ -214,7 +213,7 @@ public function testSchedulerDontRunIfSalesChannelIsNotActive(): void protected function createSecondStorefrontSalesChannel(): void { /** @var EntityRepository $salesChannelRepository */ - $salesChannelRepository = $this->getContainer()->get('sales_channel.repository'); + $salesChannelRepository = static::getContainer()->get('sales_channel.repository'); $criteria = (new Criteria()) ->setIds([$this->getSalesChannelDomain()->getSalesChannelId()]) ->addAssociation('languages'); @@ -225,7 +224,7 @@ protected function createSecondStorefrontSalesChannel(): void $originalSalesChannelLanguages = $originalSalesChannel->getLanguages(); static::assertNotNull($originalSalesChannelLanguages); $originalSalesChannelArray = $originalSalesChannelLanguages->jsonSerialize(); - $languages = array_map(static fn ($language) => ['id' => $language->getId()], $originalSalesChannelArray); + $languages = array_map(static fn (LanguageEntity $language): array => ['id' => $language->getId()], $originalSalesChannelArray); $id = '000000009276457086da48d5b5628f3c'; $data = [ @@ -248,19 +247,19 @@ protected function createSecondStorefrontSalesChannel(): void private function getTaskHandler(): ProductExportGenerateTaskHandler { return new ProductExportGenerateTaskHandler( - $this->getContainer()->get('scheduled_task.repository'), + static::getContainer()->get('scheduled_task.repository'), $this->createMock(LoggerInterface::class), - $this->getContainer()->get(SalesChannelContextFactory::class), - $this->getContainer()->get('sales_channel.repository'), - $this->getContainer()->get('product_export.repository'), - $this->getContainer()->get('messenger.bus.shopware') + static::getContainer()->get(SalesChannelContextFactory::class), + static::getContainer()->get('sales_channel.repository'), + static::getContainer()->get('product_export.repository'), + static::getContainer()->get('messenger.bus.shopware') ); } private function getSalesChannelId(): string { /** @var EntityRepository $repository */ - $repository = $this->getContainer()->get('sales_channel.repository'); + $repository = static::getContainer()->get('sales_channel.repository'); $id = $repository->search(new Criteria(), $this->context)->getEntities()->first()?->getId(); static::assertIsString($id); @@ -271,7 +270,7 @@ private function getSalesChannelId(): string private function getSalesChannelDomain(): SalesChannelDomainEntity { /** @var EntityRepository $repository */ - $repository = $this->getContainer()->get('sales_channel_domain.repository'); + $repository = static::getContainer()->get('sales_channel_domain.repository'); $criteria = new Criteria(); $criteria->addAssociation('salesChannel'); @@ -314,19 +313,16 @@ private function createTestEntity(?\DateTimeInterface $generatedAt = null, int $ return $id; } - /** - * @throws Exception - */ private function createProductStream(): void { - $connection = $this->getContainer()->get(Connection::class); + $connection = static::getContainer()->get(Connection::class); $randomProductIds = implode('|', \array_slice(array_column($this->createProducts(), 'id'), 0, 2)); $connection->executeStatement(" INSERT INTO `product_stream` (`id`, `api_filter`, `invalid`, `created_at`, `updated_at`) VALUES - (UNHEX('137B079935714281BA80B40F83F8D7EB'), '[{\"type\": \"multi\", \"queries\": [{\"type\": \"multi\", \"queries\": [{\"type\": \"equalsAny\", \"field\": \"product.id\", \"value\": \"{$randomProductIds}\"}], \"operator\": \"AND\"}, {\"type\": \"multi\", \"queries\": [{\"type\": \"range\", \"field\": \"product.width\", \"parameters\": {\"gte\": 221, \"lte\": 932}}], \"operator\": \"AND\"}, {\"type\": \"multi\", \"queries\": [{\"type\": \"range\", \"field\": \"product.width\", \"parameters\": {\"lte\": 245}}], \"operator\": \"AND\"}, {\"type\": \"multi\", \"queries\": [{\"type\": \"equals\", \"field\": \"product.manufacturer.id\", \"value\": \"02f6b9aa385d4f40aaf573661b2cf919\"}, {\"type\": \"range\", \"field\": \"product.height\", \"parameters\": {\"gte\": 182}}], \"operator\": \"AND\"}], \"operator\": \"OR\"}]', 0, '2019-08-16 08:43:57.488', NULL); + (UNHEX('137B079935714281BA80B40F83F8D7EB'), '[{\"type\": \"multi\", \"queries\": [{\"type\": \"multi\", \"queries\": [{\"type\": \"equalsAny\", \"field\": \"product.id\", \"value\": \"$randomProductIds\"}], \"operator\": \"AND\"}, {\"type\": \"multi\", \"queries\": [{\"type\": \"range\", \"field\": \"product.width\", \"parameters\": {\"gte\": 221, \"lte\": 932}}], \"operator\": \"AND\"}, {\"type\": \"multi\", \"queries\": [{\"type\": \"range\", \"field\": \"product.width\", \"parameters\": {\"lte\": 245}}], \"operator\": \"AND\"}, {\"type\": \"multi\", \"queries\": [{\"type\": \"equals\", \"field\": \"product.manufacturer.id\", \"value\": \"02f6b9aa385d4f40aaf573661b2cf919\"}, {\"type\": \"range\", \"field\": \"product.height\", \"parameters\": {\"gte\": 182}}], \"operator\": \"AND\"}], \"operator\": \"OR\"}]', 0, '2019-08-16 08:43:57.488', NULL); "); $connection->executeStatement(" @@ -340,7 +336,7 @@ private function createProductStream(): void (UNHEX('56C5DF0B41954334A7B0CDFEDFE1D7E9'), UNHEX('137B079935714281BA80B40F83F8D7EB'), UNHEX('272B4392E7B34EF2ABB4827A33630C1D'), 'range', 'width', NULL, NULL, '{\"lte\":932,\"gte\":221}', 1, NULL, '2019-08-16 08:43:57.488', NULL), (UNHEX('6382E03A768F444E9C2A809C63102BD4'), UNHEX('137B079935714281BA80B40F83F8D7EB'), UNHEX('BB87D86524FB4E7EA01EE548DD43A5AC'), 'range', 'height', NULL, NULL, '{\"gte\":182}', 2, NULL, '2019-08-16 08:43:57.485', NULL), (UNHEX('7CBC1236ABCD43CAA697E9600BF1DF6E'), UNHEX('137B079935714281BA80B40F83F8D7EB'), UNHEX('4A7AEB36426A482A8BFFA049F795F5E7'), 'range', 'width', NULL, NULL, '{\"lte\":245}', 1, NULL, '2019-08-16 08:43:57.476', NULL), - (UNHEX('80B2B90171454467B769A4C161E74B87'), UNHEX('137B079935714281BA80B40F83F8D7EB'), UNHEX('0EE60B6A87774E9884A832D601BE6B8F'), 'equalsAny', 'id', NULL, '{$randomProductIds}', NULL, 1, NULL, '2019-08-16 08:43:57.480', NULL); + (UNHEX('80B2B90171454467B769A4C161E74B87'), UNHEX('137B079935714281BA80B40F83F8D7EB'), UNHEX('0EE60B6A87774E9884A832D601BE6B8F'), 'equalsAny', 'id', NULL, '$randomProductIds', NULL, 1, NULL, '2019-08-16 08:43:57.480', NULL); "); } @@ -349,7 +345,7 @@ private function createProductStream(): void */ private function createProducts(): array { - $productRepository = $this->getContainer()->get('product.repository'); + $productRepository = static::getContainer()->get('product.repository'); $manufacturerId = Uuid::randomHex(); $taxId = Uuid::randomHex(); $salesChannelId = $this->getSalesChannelDomain()->getSalesChannelId(); @@ -377,9 +373,10 @@ private function createProducts(): array private function clearProductExports(): void { + /** @var list $ids */ $ids = $this->productExportRepository->searchIds(new Criteria(), $this->context)->getIds(); - $ids = array_map(fn ($id) => ['id' => $id], $ids); + $ids = array_map(static fn (string $id): array => ['id' => $id], $ids); $this->productExportRepository->delete($ids, $this->context); } @@ -390,7 +387,7 @@ private function prepareProductExportForScheduler(bool $active): void $this->clearProductExports(); $this->createTestEntity(); - $salesChannelRepository = $this->getContainer()->get('sales_channel.repository'); + $salesChannelRepository = static::getContainer()->get('sales_channel.repository'); $criteria = new Criteria(); $criteria->addFilter(new EqualsFilter('id', $this->getSalesChannelId())); $salesChannelId = $salesChannelRepository->searchIds($criteria, $this->context)->firstId(); @@ -404,11 +401,11 @@ private function prepareProductExportForScheduler(bool $active): void } /** - * @return array + * @return list> */ private function getDispatchedMessages(): array { - $bus = $this->getContainer()->get('messenger.bus.shopware'); + $bus = static::getContainer()->get('messenger.bus.shopware'); static::assertInstanceOf(TraceableMessageBus::class, $bus); return $bus->getDispatchedMessages(); diff --git a/tests/integration/Core/Framework/App/Manifest/ModuleLoaderTest.php b/tests/integration/Core/Framework/App/Manifest/ModuleLoaderTest.php index f9ea821a2ca..5c35f41e6c2 100644 --- a/tests/integration/Core/Framework/App/Manifest/ModuleLoaderTest.php +++ b/tests/integration/Core/Framework/App/Manifest/ModuleLoaderTest.php @@ -242,6 +242,8 @@ private function getSortedModules(): array /** * @param array $loadedModules + * + * @param-out array, modules: array, parent: string, source?: string|null, position: int}>, mainModule: array{source: string}|null}> $loadedModules */ private function validateSources(array &$loadedModules): void { diff --git a/tests/integration/Storefront/Page/Account/EditOrderPageTest.php b/tests/integration/Storefront/Page/Account/EditOrderPageTest.php index fa8bcf9d08b..7fc063e77d8 100644 --- a/tests/integration/Storefront/Page/Account/EditOrderPageTest.php +++ b/tests/integration/Storefront/Page/Account/EditOrderPageTest.php @@ -105,9 +105,6 @@ public function testEditPageNotAvailableOrderIsPaid(): void $orderId = $this->placeRandomOrder($context); $this->setOrderToTransactionState($orderId, $context, StateMachineTransitionActions::ACTION_PAID); - $event = null; - $this->catchEvent(AccountEditOrderPageLoader::class, $event); - $this->expectException(OrderException::class); $request->request->set('orderId', $orderId); diff --git a/tests/integration/Storefront/Page/StorefrontPageTestBehaviour.php b/tests/integration/Storefront/Page/StorefrontPageTestBehaviour.php index 4849c07a6b6..ba9498f9c0e 100644 --- a/tests/integration/Storefront/Page/StorefrontPageTestBehaviour.php +++ b/tests/integration/Storefront/Page/StorefrontPageTestBehaviour.php @@ -6,12 +6,15 @@ use Shopware\Core\Checkout\Cart\CartRuleLoader; use Shopware\Core\Checkout\Cart\LineItem\LineItem; use Shopware\Core\Checkout\Cart\SalesChannel\CartService; +use Shopware\Core\Checkout\Customer\CustomerCollection; use Shopware\Core\Checkout\Customer\CustomerEntity; use Shopware\Core\Content\Product\Aggregate\ProductVisibility\ProductVisibilityDefinition; +use Shopware\Core\Content\Product\ProductCollection; use Shopware\Core\Content\Product\ProductEntity; use Shopware\Core\Defaults; use Shopware\Core\Framework\Api\Util\AccessKeyHelper; use Shopware\Core\Framework\Context; +use Shopware\Core\Framework\DataAbstractionLayer\EntityRepository; use Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria; use Shopware\Core\Framework\Routing\RoutingException; use Shopware\Core\Framework\Struct\Struct; @@ -27,17 +30,21 @@ use Shopware\Storefront\Pagelet\PageletLoadedEvent; use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\HttpFoundation\Request; +use Symfony\Contracts\EventDispatcher\Event; trait StorefrontPageTestBehaviour { use TaxAddToSalesChannelTestBehaviour; /** - * @param class-string $expectedClass + * @template TEvent of PageLoadedEvent + * + * @param class-string $expectedClass + * @param TEvent|null $event */ public static function assertPageEvent( string $expectedClass, - PageLoadedEvent $event, + ?PageLoadedEvent $event, SalesChannelContext $salesChannelContext, Request $request, Struct $page @@ -50,7 +57,10 @@ public static function assertPageEvent( } /** - * @param class-string $expectedClass + * @template TEvent of PageletLoadedEvent + * + * @param class-string $expectedClass + * @param TEvent $event */ public static function assertPageletEvent( string $expectedClass, @@ -121,12 +131,10 @@ protected function getRandomProduct(SalesChannelContext $context, ?int $stock = $productRepository->create([$data], $context->getContext()); $this->addTaxDataToSalesChannel($context, $data['tax']); - /** @var SalesChannelRepository $storefrontProductRepository */ + /** @var SalesChannelRepository $storefrontProductRepository */ $storefrontProductRepository = $this->getContainer()->get('sales_channel.product.repository'); - $searchResult = $storefrontProductRepository->search(new Criteria([$id]), $context); - - /** @var ProductEntity $product */ - $product = $searchResult->first(); + $product = $storefrontProductRepository->search(new Criteria([$id]), $context)->getEntities()->first(); + static::assertNotNull($product); return $product; } @@ -244,9 +252,15 @@ protected function createSalesChannelContext(?array $salesChannelData = null): S return $this->createContext($data, []); } - protected function catchEvent(string $eventName, ?object &$eventResult): void + /** + * @template TEventName of Event + * + * @param class-string $eventName + * @param TEventName|null $eventResult + */ + protected function catchEvent(string $eventName, ?Event &$eventResult): void { - $this->addEventListener($this->getContainer()->get('event_dispatcher'), $eventName, static function ($event) use (&$eventResult): void { + $this->addEventListener($this->getContainer()->get('event_dispatcher'), $eventName, static function (Event $event) use (&$eventResult): void { $eventResult = $event; }); } @@ -284,13 +298,13 @@ private function createCustomer(): CustomerEntity ], ]; + /** @var EntityRepository $repo */ $repo = $this->getContainer()->get('customer.repository'); $repo->create($data, Context::createDefaultContext()); - $result = $repo->search(new Criteria([$customerId]), Context::createDefaultContext()); - /** @var CustomerEntity $customer */ - $customer = $result->first(); + $customer = $repo->search(new Criteria([$customerId]), Context::createDefaultContext())->getEntities()->first(); + static::assertNotNull($customer); return $customer; }