From a08ff3a6b9c1fc9d496e9ccfbaca7dc004d8a4ab Mon Sep 17 00:00:00 2001 From: Aydin Hassan Date: Wed, 17 Jan 2024 16:59:54 +0100 Subject: [PATCH] Fix phpstan issues --- tests/Checkout/Cart/ExcludedProductValidatorTest.php | 6 ++---- .../Migration/Migration1692001928VaultTokenTest.php | 4 ++-- tests/OrdersApi/Builder/APMOrderBuilderTest.php | 12 ++++-------- tests/Pos/Mock/Repositories/RepoTrait.php | 2 +- tests/Pos/Run/RunTaskTest.php | 6 ++---- tests/ShopwarePluginClassTest.php | 9 +++------ tests/TestBootstrapper.php | 8 ++++++-- tests/Util/Availability/AvailabilityServiceTest.php | 9 +++------ 8 files changed, 23 insertions(+), 33 deletions(-) diff --git a/tests/Checkout/Cart/ExcludedProductValidatorTest.php b/tests/Checkout/Cart/ExcludedProductValidatorTest.php index a70241907..02f595bff 100644 --- a/tests/Checkout/Cart/ExcludedProductValidatorTest.php +++ b/tests/Checkout/Cart/ExcludedProductValidatorTest.php @@ -151,9 +151,8 @@ public function testIsExcludedProduct(?string $settingKey, ?string $settingIdNam /** * this test is related to the ExpressCheckoutSubscriber - * - * @dataProvider dataProviderConstellations */ + #[DataProvider('dataProviderConstellations')] public function testExcludedProductTaggedInSearchResults(?string $settingKey, ?string $settingIdName, ?string $expectedIdName): void { if ($settingKey && $settingIdName) { @@ -179,9 +178,8 @@ public function testExcludedProductTaggedInSearchResults(?string $settingKey, ?s /** * this test is related to the ExpressCheckoutSubscriber - * - * @dataProvider dataProviderConstellations */ + #[DataProvider('dataProviderConstellations')] public function testExcludedProductTaggedInSearchResultsWithListingDisabled(?string $settingKey, ?string $settingIdName): void { if ($settingKey && $settingIdName) { diff --git a/tests/Migration/Migration1692001928VaultTokenTest.php b/tests/Migration/Migration1692001928VaultTokenTest.php index 074a68eab..0cef7e0de 100644 --- a/tests/Migration/Migration1692001928VaultTokenTest.php +++ b/tests/Migration/Migration1692001928VaultTokenTest.php @@ -10,6 +10,7 @@ namespace Swag\PayPal\Test\Migration; use Doctrine\DBAL\Connection; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; use Shopware\Core\Framework\Log\Package; use Shopware\Core\Framework\Test\TestCaseBase\DatabaseTransactionBehaviour; @@ -17,11 +18,10 @@ use Swag\PayPal\Migration\Migration1692001928VaultToken; /** - * @covers \Swag\PayPal\Migration\Migration1692001928VaultToken - * * @internal */ #[Package('checkout')] +#[CoversClass(\Swag\PayPal\Migration\Migration1692001928VaultToken::class)] class Migration1692001928VaultTokenTest extends TestCase { use DatabaseTransactionBehaviour; diff --git a/tests/OrdersApi/Builder/APMOrderBuilderTest.php b/tests/OrdersApi/Builder/APMOrderBuilderTest.php index 1cef9bdc9..091bbb594 100644 --- a/tests/OrdersApi/Builder/APMOrderBuilderTest.php +++ b/tests/OrdersApi/Builder/APMOrderBuilderTest.php @@ -78,9 +78,8 @@ class APMOrderBuilderTest extends TestCase /** * @param class-string $orderBuilderClass * @param class-string $structClass - * - * @dataProvider dataProviderAPM */ + #[DataProvider('dataProviderAPM')] public function testGetOrder(string $orderBuilderClass, array $requestData, string $structClass, array $expectedStructData): void { $orderBuilder = $this->createOrderBuilder($orderBuilderClass); @@ -116,9 +115,8 @@ public function testGetOrder(string $orderBuilderClass, array $requestData, stri /** * @param class-string $orderBuilderClass - * - * @dataProvider dataProviderAPM */ + #[DataProvider('dataProviderAPM')] public function testGetOrderNoBillingAddress(string $orderBuilderClass, array $requestData): void { $orderBuilder = $this->createOrderBuilder($orderBuilderClass); @@ -138,9 +136,8 @@ public function testGetOrderNoBillingAddress(string $orderBuilderClass, array $r /** * @param class-string $orderBuilderClass - * - * @dataProvider dataProviderAPM */ + #[DataProvider('dataProviderAPM')] public function testGetOrderNoShippingAddress(string $orderBuilderClass, array $requestData): void { $orderBuilder = $this->createOrderBuilder($orderBuilderClass); @@ -160,9 +157,8 @@ public function testGetOrderNoShippingAddress(string $orderBuilderClass, array $ /** * @param class-string $orderBuilderClass - * - * @dataProvider dataProviderAPM */ + #[DataProvider('dataProviderAPM')] public function testGetOrderPrefix(string $orderBuilderClass, array $requestData): void { $paymentTransaction = $this->createPaymentTransactionStruct(ConstantsForTesting::VALID_ORDER_ID); diff --git a/tests/Pos/Mock/Repositories/RepoTrait.php b/tests/Pos/Mock/Repositories/RepoTrait.php index 5d19c967a..41c42c896 100644 --- a/tests/Pos/Mock/Repositories/RepoTrait.php +++ b/tests/Pos/Mock/Repositories/RepoTrait.php @@ -73,7 +73,7 @@ protected function updateCollection(array $data, Context $context): EntityWritte $entity->setUniqueIdentifier($this->getUniqueIdentifier($entity)); if ($this->entityCollection->has($entity->getUniqueIdentifier())) { - $entity = $this->entityCollection->get($entity->getUniqueIdentifier()) ?? $entity; + $entity = $this->entityCollection->get($entity->getUniqueIdentifier()); $entity->assign($entry); } diff --git a/tests/Pos/Run/RunTaskTest.php b/tests/Pos/Run/RunTaskTest.php index ea6ae0c56..eeb1f43c6 100644 --- a/tests/Pos/Run/RunTaskTest.php +++ b/tests/Pos/Run/RunTaskTest.php @@ -71,10 +71,9 @@ public static function dataProviderRunTaskName(): array } /** - * @dataProvider dataProviderRunTaskName - * * @param class-string $taskName */ + #[DataProvider('dataProviderRunTaskName')] public function testNames(string $taskName, string $expectedName): void { /** @var AbstractTask&MockObject $task */ @@ -120,10 +119,9 @@ public static function dataProviderExecution(): array } /** - * @dataProvider dataProviderExecution - * * @param class-string $taskName */ + #[DataProvider('dataProviderExecution')] public function testExecution(string $taskName, array $serviceCalls): void { $context = Context::createDefaultContext(); diff --git a/tests/ShopwarePluginClassTest.php b/tests/ShopwarePluginClassTest.php index 039e9c873..3d54589f9 100644 --- a/tests/ShopwarePluginClassTest.php +++ b/tests/ShopwarePluginClassTest.php @@ -7,6 +7,7 @@ * file that was distributed with this source code. */ +use PHPUnit\Framework\Attributes\Depends; use PHPUnit\Framework\TestCase; use Shopware\Core\Framework\Log\Package; use Shopware\Core\Framework\Plugin; @@ -25,9 +26,7 @@ public function testHasComposerJson(): void static::assertFileExists(__DIR__ . '/../composer.json'); } - /** - * @depends testHasComposerJson - */ + #[Depends('testHasComposerJson')] public function testClassExists(): void { $composer = json_decode((string) file_get_contents(__DIR__ . '/../composer.json'), true); @@ -43,9 +42,7 @@ public function testClassExists(): void static::assertContains(Plugin::class, $parents, '`' . $class . '` should extend ' . Plugin::class); } - /** - * @depends testClassExists - */ + #[Depends('testClassExists')] public function testPluginIsLoaded(): void { $composer = json_decode((string) file_get_contents(__DIR__ . '/../composer.json'), true); diff --git a/tests/TestBootstrapper.php b/tests/TestBootstrapper.php index a003bcdaa..339f4aa37 100644 --- a/tests/TestBootstrapper.php +++ b/tests/TestBootstrapper.php @@ -133,7 +133,7 @@ public function getClassLoader(): ClassLoader if (\is_string($paths)) { $paths = [$paths]; } - $mappedPaths = $this->mapPsrPaths($paths, realpath(dirname($pathToComposerJson))); + $mappedPaths = $this->mapPsrPaths($paths, dirname($pathToComposerJson)); $this->classLoader->addPsr4($namespace, $mappedPaths); if ($this->classLoader->isClassMapAuthoritative()) { @@ -145,7 +145,7 @@ public function getClassLoader(): ClassLoader if (\is_string($paths)) { $paths = [$paths]; } - $mappedPaths = $this->mapPsrPaths($paths, realpath(dirname($pathToComposerJson))); + $mappedPaths = $this->mapPsrPaths($paths, dirname($pathToComposerJson)); $this->classLoader->add($namespace, $mappedPaths); if ($this->classLoader->isClassMapAuthoritative()) { @@ -157,6 +157,10 @@ public function getClassLoader(): ClassLoader return $classLoader; } + /** + * @param list $psr + * @return list + */ private function mapPsrPaths(array $psr, string $pluginRootPath): array { $mappedPaths = []; diff --git a/tests/Util/Availability/AvailabilityServiceTest.php b/tests/Util/Availability/AvailabilityServiceTest.php index 5f5a78390..df0d4a204 100644 --- a/tests/Util/Availability/AvailabilityServiceTest.php +++ b/tests/Util/Availability/AvailabilityServiceTest.php @@ -65,10 +65,9 @@ protected function setUp(): void } /** - * @dataProvider dataProviderPaymentMethod - * * @param class-string $methodDataClass */ + #[DataProvider('dataProviderPaymentMethod')] public function testIsPaymentMethodAvailable(string $methodDataClass, bool $shouldBeAvailable): void { $salesChannelContext = $this->createSalesChannelContext(); @@ -82,10 +81,9 @@ public function testIsPaymentMethodAvailable(string $methodDataClass, bool $shou } /** - * @dataProvider dataProviderPaymentMethod - * * @param class-string $methodDataClass */ + #[DataProvider('dataProviderPaymentMethod')] public function testFilterPaymentMethods(string $methodDataClass, bool $shouldBeAvailable): void { $salesChannelContext = $this->createSalesChannelContext(); @@ -99,10 +97,9 @@ public function testFilterPaymentMethods(string $methodDataClass, bool $shouldBe } /** - * @dataProvider dataProviderPaymentMethod - * * @param class-string $methodDataClass */ + #[DataProvider('dataProviderPaymentMethod')] public function testFilterPaymentMethodByOrder(string $methodDataClass, bool $shouldBeAvailable): void { $salesChannelContext = $this->createSalesChannelContext();