From 048d75b09bf8f613c9b0ee01c699d8a2a8bb32fb Mon Sep 17 00:00:00 2001 From: Ibes Date: Mon, 7 Oct 2024 15:03:30 +0200 Subject: [PATCH 01/15] Php 8.1 + Sylius 1.12 ready with tests --- composer.json | 2 + src/Resources/config/api_resources/Order.xml | 122 ++--- src/Security/GiftCardVoter.php | 9 +- tests/Application/Model/Order.php | 12 +- tests/Application/Model/OrderItem.php | 5 - .../Application/config/api_platform/Order.xml | 427 ++++++++++++++++++ tests/Application/config/bundles.php | 4 +- tests/Application/package.json | 3 +- .../ManagingGiftCardConfigurationsContext.php | 27 +- .../Admin/ManagingGiftCardsBalanceContext.php | 2 +- .../Api/Admin/ManagingGiftCardsContext.php | 16 +- tests/Behat/Context/Api/Shop/CartContext.php | 25 +- .../Api/Shop/ManagingGiftCardsContext.php | 24 +- tests/Behat/Resources/api.xml | 8 - tests/Behat/Resources/api/clients.xml | 32 -- tests/Behat/Resources/context/api.xml | 12 +- tests/Behat/Resources/services.xml | 1 - .../Resources/suites/api/buying_gift_card.yml | 2 +- .../Resources/suites/ui/buying_gift_card.yml | 2 +- tests/Unit/Model/OrderItemTraitTest.php | 35 -- 20 files changed, 576 insertions(+), 194 deletions(-) create mode 100644 tests/Application/config/api_platform/Order.xml delete mode 100644 tests/Behat/Resources/api.xml delete mode 100644 tests/Behat/Resources/api/clients.xml delete mode 100644 tests/Unit/Model/OrderItemTraitTest.php diff --git a/composer.json b/composer.json index 05832011..b1e3f5c6 100644 --- a/composer.json +++ b/composer.json @@ -59,6 +59,8 @@ "require-dev": { "babdev/pagerfanta-bundle": "^3.8", "behat/behat": "^3.14", + "dmore/behat-chrome-extension": "^1.4", + "dmore/chrome-mink-driver": "^2.9", "doctrine/doctrine-bundle": "^2.7", "infection/infection": "^0.27.10", "jms/serializer-bundle": "^4.2", diff --git a/src/Resources/config/api_resources/Order.xml b/src/Resources/config/api_resources/Order.xml index 08b8cd2e..fc0ddeec 100644 --- a/src/Resources/config/api_resources/Order.xml +++ b/src/Resources/config/api_resources/Order.xml @@ -1,22 +1,30 @@ + + - - - admin:order:read - - - sylius GET - admin/orders + /admin/orders + + admin:order:read + @@ -24,11 +32,18 @@ /shop/orders input Sylius\Bundle\ApiBundle\Command\Cart\PickupCart + + + shop:order:read + shop:cart:read + + shop:order:create - Pickups a new cart. Provided locale code has to be one of available for a particular channel. + Pickups a new cart + @@ -46,6 +61,9 @@ GET /admin/orders/{tokenValue} + + admin:order:read + @@ -71,7 +89,12 @@ PATCH /admin/orders/{tokenValue}/cancel false - sylius.api.order_state_machine_transition_applicator:cancel + Sylius\Bundle\ApiBundle\Applicator\OrderStateMachineTransitionApplicatorInterface::cancel + + + admin:order:read + + admin:order:update @@ -81,12 +104,14 @@ - PATCH + POST /shop/orders/{tokenValue}/items input Setono\SyliusGiftCardPlugin\Api\Command\AddItemToCart - shop:cart:read + + shop:cart:read + shop:cart:add_item @@ -96,22 +121,6 @@ - - PATCH - /shop/orders/{tokenValue}/address - input - Sylius\Bundle\ApiBundle\Command\Checkout\AddressOrder - - shop:cart:address - - - shop:cart:read - - - Addresses cart to given location, logged in Customer does not have to provide an email - - - PATCH @@ -124,7 +133,10 @@ shop:cart:select_shipping_method - shop:cart:read + + shop:order:read + shop:cart:read + Selects shipping methods for particular shipment @@ -158,7 +170,10 @@ shop:cart:select_payment_method - shop:cart:read + + shop:order:read + shop:cart:read + Selects payment methods for particular payment @@ -219,7 +234,7 @@ GET - sylius.api.get_configuration_action + Sylius\Bundle\ApiBundle\Controller\Payment\GetPaymentConfiguration /shop/orders/{tokenValue}/payments/{paymentId}/configuration Retrieve payment method configuration @@ -257,7 +272,10 @@ shop:cart:complete - shop:cart:read + + shop:order:read + shop:cart:read + Completes checkout @@ -267,7 +285,6 @@ DELETE /shop/orders/{tokenValue}/items/{itemId} - input Sylius\Bundle\ApiBundle\Controller\DeleteOrderItemAction false @@ -300,6 +317,9 @@ /shop/orders/{tokenValue}/items/{orderItemId} input Sylius\Bundle\ApiBundle\Command\Cart\ChangeItemQuantityInCart + + shop:cart:read + shop:cart:change_quantity @@ -326,24 +346,22 @@ - - PATCH - /shop/orders/{tokenValue}/apply-coupon - input - Sylius\Bundle\ApiBundle\Command\Cart\ApplyCouponToCart - - shop:cart:apply_coupon - - - Applies coupon to cart - - - PUT /shop/orders/{tokenValue} + input + Sylius\Bundle\ApiBundle\Command\Checkout\UpdateCart - admin:cart:update + shop:cart:update + + + + shop:order:read + shop:cart:read + + + + Addresses cart to given location, logged in Customer does not have to provide an email. Applies coupon to cart. @@ -369,16 +387,6 @@ /shop/orders/{tokenValue}/adjustments - - GET - /shop/orders/{tokenValue}/payments/{payments}/methods - - - - GET - /shop/orders/{tokenValue}/shipments/{shipments}/methods - - GET /shop/orders/{tokenValue}/items/{items}/adjustments @@ -407,6 +415,8 @@ + + diff --git a/src/Security/GiftCardVoter.php b/src/Security/GiftCardVoter.php index 2ae72cb4..cc3d293d 100644 --- a/src/Security/GiftCardVoter.php +++ b/src/Security/GiftCardVoter.php @@ -17,7 +17,7 @@ final class GiftCardVoter extends Voter { public const READ = 'read'; - protected function supports($attribute, $subject): bool + protected function supports(string $attribute, mixed $subject): bool { if (self::READ !== $attribute) { return false; @@ -30,11 +30,7 @@ protected function supports($attribute, $subject): bool return true; } - /** - * @param string $attribute - * @param GiftCardInterface $subject - */ - protected function voteOnAttribute($attribute, $subject, TokenInterface $token): bool + protected function voteOnAttribute(string $attribute, mixed $subject, TokenInterface $token): bool { /** @var UserInterface|ShopUserInterface|AdminUserInterface|null $user */ $user = $token->getUser(); @@ -47,6 +43,7 @@ protected function voteOnAttribute($attribute, $subject, TokenInterface $token): return true; } Assert::isInstanceOf($user, ShopUserInterface::class); + Assert::isInstanceOf($subject, GiftCardInterface::class); if (self::READ === $attribute) { return $this->canRead($subject, $user); diff --git a/tests/Application/Model/Order.php b/tests/Application/Model/Order.php index 3a482a03..70250382 100644 --- a/tests/Application/Model/Order.php +++ b/tests/Application/Model/Order.php @@ -5,8 +5,8 @@ namespace Setono\SyliusGiftCardPlugin\Tests\Application\Model; use Doctrine\ORM\Mapping as ORM; -use Setono\SyliusGiftCardPlugin\Model\OrderInterface as SetonoSyliusGiftCardOrderInterface; -use Setono\SyliusGiftCardPlugin\Model\OrderTrait as SetonoSyliusGiftCardOrderTrait; +use Setono\SyliusGiftCardPlugin\Model\OrderInterface as SetonoSyliusGiftCardPluginOrderInterface; +use Setono\SyliusGiftCardPlugin\Model\OrderTrait as SetonoSyliusGiftCardPluginOrderTrait; use Sylius\Component\Core\Model\Order as BaseOrder; /** @@ -14,15 +14,15 @@ * * @ORM\Table(name="sylius_order") */ -class Order extends BaseOrder implements SetonoSyliusGiftCardOrderInterface +class Order extends BaseOrder implements SetonoSyliusGiftCardPluginOrderInterface { - use SetonoSyliusGiftCardOrderTrait { - SetonoSyliusGiftCardOrderTrait::__construct as private __SetonoSyliusGiftCardOrderTraitConstruct; + use SetonoSyliusGiftCardPluginOrderTrait { + SetonoSyliusGiftCardPluginOrderTrait::__construct as private __giftCardTraitConstruct; } public function __construct() { - $this->__SetonoSyliusGiftCardOrderTraitConstruct(); + $this->__giftCardTraitConstruct(); parent::__construct(); } diff --git a/tests/Application/Model/OrderItem.php b/tests/Application/Model/OrderItem.php index 6c27b5d4..936f6694 100644 --- a/tests/Application/Model/OrderItem.php +++ b/tests/Application/Model/OrderItem.php @@ -5,18 +5,13 @@ namespace Setono\SyliusGiftCardPlugin\Tests\Application\Model; use Doctrine\ORM\Mapping as ORM; -use Setono\SyliusGiftCardPlugin\Model\OrderItemTrait; -use Setono\SyliusGiftCardPlugin\Model\ProductInterface; use Sylius\Component\Core\Model\OrderItem as BaseOrderItem; /** * @ORM\Entity * * @ORM\Table(name="sylius_order_item") - * - * @method ProductInterface|null getProduct() */ class OrderItem extends BaseOrderItem { - use OrderItemTrait; } diff --git a/tests/Application/config/api_platform/Order.xml b/tests/Application/config/api_platform/Order.xml new file mode 100644 index 00000000..fc0ddeec --- /dev/null +++ b/tests/Application/config/api_platform/Order.xml @@ -0,0 +1,427 @@ + + + + + + + sylius + + + + GET + /admin/orders + + admin:order:read + + + + + POST + /shop/orders + input + Sylius\Bundle\ApiBundle\Command\Cart\PickupCart + + + shop:order:read + shop:cart:read + + + + shop:order:create + + + Pickups a new cart + + + + + GET + /shop/orders + + + shop:order:read + + + + + + + + GET + /admin/orders/{tokenValue} + + admin:order:read + + + + + GET + /shop/orders/{tokenValue} + + shop:cart:read + + + + + DELETE + /shop/orders/{tokenValue} + + Deletes cart + + + shop:order:read + + + + + PATCH + /admin/orders/{tokenValue}/cancel + false + Sylius\Bundle\ApiBundle\Applicator\OrderStateMachineTransitionApplicatorInterface::cancel + + + admin:order:read + + + + admin:order:update + + + Cancels Order + + + + + POST + /shop/orders/{tokenValue}/items + input + Setono\SyliusGiftCardPlugin\Api\Command\AddItemToCart + + + shop:cart:read + + + + shop:cart:add_item + + + Adds Item to cart + + + + + PATCH + + sylius + + /shop/orders/{tokenValue}/shipments/{shipmentId} + input + Sylius\Bundle\ApiBundle\Command\Checkout\ChooseShippingMethod + + shop:cart:select_shipping_method + + + + shop:order:read + shop:cart:read + + + + Selects shipping methods for particular shipment + + + tokenValue + path + true + + string + + + + shipmentId + path + true + + string + + + + + + + + PATCH + /shop/orders/{tokenValue}/payments/{paymentId} + input + Sylius\Bundle\ApiBundle\Command\Checkout\ChoosePaymentMethod + + shop:cart:select_payment_method + + + + shop:order:read + shop:cart:read + + + + Selects payment methods for particular payment + + + tokenValue + path + true + + string + + + + paymentId + path + true + + string + + + + + + + + PATCH + /shop/account/orders/{tokenValue}/payments/{paymentId} + input + Sylius\Bundle\ApiBundle\Command\Account\ChangePaymentMethod + + shop:order:account:change_payment_method + + + shop:order:account:read + + + Change the payment method as logged shop user + + + tokenValue + path + true + + string + + + + paymentId + path + true + + string + + + + + + + + GET + Sylius\Bundle\ApiBundle\Controller\Payment\GetPaymentConfiguration + /shop/orders/{tokenValue}/payments/{paymentId}/configuration + + Retrieve payment method configuration + + + tokenValue + path + true + + string + + + + paymentId + path + true + + string + + + + + + + + PATCH + /shop/orders/{tokenValue}/complete + + sylius + sylius_checkout_complete + + input + Sylius\Bundle\ApiBundle\Command\Checkout\CompleteOrder + + shop:cart:complete + + + + shop:order:read + shop:cart:read + + + + Completes checkout + + + + + DELETE + /shop/orders/{tokenValue}/items/{itemId} + Sylius\Bundle\ApiBundle\Controller\DeleteOrderItemAction + false + + shop:cart:remove_item + + + + + tokenValue + path + true + + string + + + + itemId + path + true + + string + + + + + + + + PATCH + /shop/orders/{tokenValue}/items/{orderItemId} + input + Sylius\Bundle\ApiBundle\Command\Cart\ChangeItemQuantityInCart + + shop:cart:read + + + shop:cart:change_quantity + + + Changes quantity of order item + + + tokenValue + path + true + + string + + + + orderItemId + path + true + + string + + + + + + + + PUT + /shop/orders/{tokenValue} + input + Sylius\Bundle\ApiBundle\Command\Checkout\UpdateCart + + shop:cart:update + + + + shop:order:read + shop:cart:read + + + + Addresses cart to given location, logged in Customer does not have to provide an email. Applies coupon to cart. + + + + + + + GET + /shop/orders/{tokenValue}/items + + + + GET + /admin/orders/{tokenValue}/shipments + + + + GET + /admin/orders/{tokenValue}/payments + + + + GET + /shop/orders/{tokenValue}/adjustments + + + + GET + /shop/orders/{tokenValue}/items/{items}/adjustments + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tests/Application/config/bundles.php b/tests/Application/config/bundles.php index fdf32a28..a60ea358 100644 --- a/tests/Application/config/bundles.php +++ b/tests/Application/config/bundles.php @@ -36,8 +36,6 @@ Sylius\Bundle\ApiBundle\SyliusApiBundle::class => ['all' => true], // End: In test app, those 3 needs to be loaded before our plugin or the Api Resource override won't work - Setono\SyliusGiftCardPlugin\SetonoSyliusGiftCardPlugin::class => ['all' => true], - Sylius\Bundle\GridBundle\SyliusGridBundle::class => ['all' => true], winzou\Bundle\StateMachineBundle\winzouStateMachineBundle::class => ['all' => true], Sonata\BlockBundle\SonataBlockBundle::class => ['all' => true], Bazinga\Bundle\HateoasBundle\BazingaHateoasBundle::class => ['all' => true], @@ -64,4 +62,6 @@ SyliusLabs\Polyfill\Symfony\Security\Bundle\SyliusLabsPolyfillSymfonySecurityBundle::class => ['all' => true], Symfony\WebpackEncoreBundle\WebpackEncoreBundle::class => ['all' => true], Sylius\Calendar\SyliusCalendarBundle::class => ['all' => true], + Setono\SyliusGiftCardPlugin\SetonoSyliusGiftCardPlugin::class => ['all' => true], + Sylius\Bundle\GridBundle\SyliusGridBundle::class => ['all' => true], ]; diff --git a/tests/Application/package.json b/tests/Application/package.json index 8f62c4c7..8036f0c7 100644 --- a/tests/Application/package.json +++ b/tests/Application/package.json @@ -26,5 +26,6 @@ "url": "git+https://github.com/Sylius/Sylius.git" }, "author": "Paweł Jędrzejewski", - "license": "MIT" + "license": "MIT", + "packageManager": "yarn@1.22.22" } diff --git a/tests/Behat/Context/Api/Admin/ManagingGiftCardConfigurationsContext.php b/tests/Behat/Context/Api/Admin/ManagingGiftCardConfigurationsContext.php index 2ef92e00..827a22e9 100644 --- a/tests/Behat/Context/Api/Admin/ManagingGiftCardConfigurationsContext.php +++ b/tests/Behat/Context/Api/Admin/ManagingGiftCardConfigurationsContext.php @@ -7,7 +7,7 @@ use ApiPlatform\Core\Api\IriConverterInterface; use Behat\Behat\Context\Context; use Sylius\Behat\Client\ApiClientInterface; -use Sylius\Behat\Client\Request; +use Sylius\Behat\Client\RequestFactoryInterface; use Sylius\Behat\Client\ResponseCheckerInterface; use Sylius\Component\Core\Model\ChannelInterface; use Sylius\Component\Locale\Model\Locale; @@ -22,14 +22,18 @@ final class ManagingGiftCardConfigurationsContext implements Context private IriConverterInterface $iriConverter; + private RequestFactoryInterface $requestFactory; + public function __construct( ApiClientInterface $client, ResponseCheckerInterface $responseChecker, IriConverterInterface $iriConverter, + RequestFactoryInterface $requestFactory, ) { $this->client = $client; $this->responseChecker = $responseChecker; $this->iriConverter = $iriConverter; + $this->requestFactory = $requestFactory; } /** @@ -37,7 +41,7 @@ public function __construct( */ public function iBrowseGiftCardConfigurations(): void { - $this->client->index(); + $this->client->index('gift-card-configuration'); } /** @@ -45,7 +49,7 @@ public function iBrowseGiftCardConfigurations(): void */ public function iWantToCreateGiftCardConfiguration(): void { - $this->client->buildCreateRequest(); + $this->client->buildCreateRequest('gift-card-configurations'); } /** @@ -53,7 +57,7 @@ public function iWantToCreateGiftCardConfiguration(): void */ public function iWantToUpdateGiftCardConfiguration(string $code): void { - $this->client->buildUpdateRequest($code); + $this->client->buildUpdateRequest('gift-card-configurations', $code); } /** @@ -64,7 +68,7 @@ public function iAssociateGiftCardConfigurationToChannelAndLocale( ChannelInterface $channel, string $localeCode, ): void { - $request = Request::customItemAction( + $request = $this->requestFactory->customItemAction( 'admin', 'gift-card-configurations', $code, @@ -101,7 +105,7 @@ public function iSaveMyChanges(): void */ public function iDeleteGiftCardConfiguration(string $code): void { - $this->client->delete($code); + $this->client->delete('gift-card-configurations', $code); } /** @@ -109,7 +113,7 @@ public function iDeleteGiftCardConfiguration(string $code): void */ public function iShouldSeeGiftCardConfiguration(string $code): void { - $response = $this->client->show($code); + $response = $this->client->show('gift-card-configurations', $code); Assert::same($this->responseChecker->getValue($response, 'code'), $code); } @@ -119,7 +123,7 @@ public function iShouldSeeGiftCardConfiguration(string $code): void */ public function iShouldNotSeeGiftCardConfiguration(string $code): void { - $response = $this->client->index(); + $response = $this->client->index('gift-card-configurations'); Assert::false( $this->responseChecker->hasItemWithValue($response, 'code', $code), @@ -206,10 +210,11 @@ public function itShouldNotBeDefaultConfiguration(): void public function itShouldHave(ChannelInterface $channel, string $localeCode): void { $response = $this->client->getLastResponse(); - $channelConfigurations = $this->responseChecker->getValue($response, 'channelConfigurations'); - Assert::same($channelConfigurations[0]['channel'], $this->iriConverter->getIriFromItem($channel)); - Assert::same($channelConfigurations[0]['locale'], $this->iriConverter->getIriFromResourceClass(Locale::class) . '/' . $localeCode); + Assert::isArray($channelConfigurations); + Assert::isArray($channelConfigurations[0]); + Assert::same($channelConfigurations[0]['channel'], $this->iriConverter->getIriFromItemInSection($channel, 'admin')); + Assert::same($channelConfigurations[0]['locale'], $this->iriConverter->getItemIriFromResourceClass(Locale::class, ['code' => $localeCode], null, 'admin')); } /** diff --git a/tests/Behat/Context/Api/Admin/ManagingGiftCardsBalanceContext.php b/tests/Behat/Context/Api/Admin/ManagingGiftCardsBalanceContext.php index dfe97e19..0fde9bf8 100644 --- a/tests/Behat/Context/Api/Admin/ManagingGiftCardsBalanceContext.php +++ b/tests/Behat/Context/Api/Admin/ManagingGiftCardsBalanceContext.php @@ -29,7 +29,7 @@ public function __construct( */ public function iBrowseGiftCardsBalance(): void { - $this->client->index(); + $this->client->index('gift-cards/balance'); } /** diff --git a/tests/Behat/Context/Api/Admin/ManagingGiftCardsContext.php b/tests/Behat/Context/Api/Admin/ManagingGiftCardsContext.php index 4139c661..d0bf6708 100644 --- a/tests/Behat/Context/Api/Admin/ManagingGiftCardsContext.php +++ b/tests/Behat/Context/Api/Admin/ManagingGiftCardsContext.php @@ -37,7 +37,7 @@ public function __construct( */ public function iBrowseGiftCards(): void { - $this->client->index(); + $this->client->index('gift-cards'); } /** @@ -45,7 +45,7 @@ public function iBrowseGiftCards(): void */ public function iWantToCreateGiftCard(): void { - $this->client->buildCreateRequest(); + $this->client->buildCreateRequest('gift-cards'); } /** @@ -61,7 +61,7 @@ public function iAddIt(): void */ public function iOpenGiftCardPage(string $code): void { - $this->client->show($code); + $this->client->show('gift-cards', $code); } /** @@ -69,7 +69,7 @@ public function iOpenGiftCardPage(string $code): void */ public function iWantToEditGiftCard(string $code): void { - $this->client->buildUpdateRequest($code); + $this->client->buildUpdateRequest('gift-cards', $code); } /** @@ -85,7 +85,7 @@ public function iSaveMyChanges(): void */ public function iDeleteGiftCard(string $code): void { - $this->client->delete($code); + $this->client->delete('gift-cards', $code); } /** @@ -94,9 +94,10 @@ public function iDeleteGiftCard(string $code): void */ public function iShouldSeeGiftCardPricedAtForCustomer(string $code, int $price, string $customerEmail = null): void { - $response = $this->client->show($code); + $response = $this->client->show('gift-cards', $code); $giftCardPrice = $this->responseChecker->getValue($response, 'amount'); + Assert::integer($giftCardPrice); Assert::same($price, $giftCardPrice); if (null !== $customerEmail) { @@ -113,6 +114,7 @@ public function giftCardShouldHaveAPIOrigin(): void $response = $this->client->getLastResponse(); $origin = $this->responseChecker->getValue($response, 'origin'); + Assert::string($origin); Assert::same(GiftCardInterface::ORIGIN_API, $origin); } @@ -121,7 +123,7 @@ public function giftCardShouldHaveAPIOrigin(): void */ public function iShouldNotSeeGiftCard(string $code): void { - $response = $this->client->index(); + $response = $this->client->index('gift-cards'); Assert::false( $this->responseChecker->hasItemWithValue($response, 'code', $code), diff --git a/tests/Behat/Context/Api/Shop/CartContext.php b/tests/Behat/Context/Api/Shop/CartContext.php index f4f9f05d..d7454346 100644 --- a/tests/Behat/Context/Api/Shop/CartContext.php +++ b/tests/Behat/Context/Api/Shop/CartContext.php @@ -8,7 +8,7 @@ use Behat\Behat\Context\Context; use Setono\SyliusGiftCardPlugin\Model\ProductInterface; use Sylius\Behat\Client\ApiClientInterface; -use Sylius\Behat\Client\Request; +use Sylius\Behat\Client\RequestFactoryInterface; use Sylius\Behat\Client\ResponseCheckerInterface; use Sylius\Behat\Service\SharedStorageInterface; use Sylius\Component\Product\Resolver\ProductVariantResolverInterface; @@ -26,18 +26,26 @@ final class CartContext implements Context private IriConverterInterface $iriConverter; + private RequestFactoryInterface $requestFactory; + + private string $apiUrlPrefix; + public function __construct( ApiClientInterface $cartsClient, ResponseCheckerInterface $responseChecker, SharedStorageInterface $sharedStorage, ProductVariantResolverInterface $productVariantResolver, IriConverterInterface $iriConverter, + RequestFactoryInterface $requestFactory, + string $apiUrlPrefix, ) { $this->cartsClient = $cartsClient; $this->responseChecker = $responseChecker; $this->sharedStorage = $sharedStorage; $this->productVariantResolver = $productVariantResolver; $this->iriConverter = $iriConverter; + $this->requestFactory = $requestFactory; + $this->apiUrlPrefix = $apiUrlPrefix; } /** @@ -47,7 +55,7 @@ public function iAddProductWithAmountAndMessage(ProductInterface $product, int $ { $tokenValue = $tokenValue ?? $this->pickupCart(); - $request = Request::customItemAction('shop', 'orders', $tokenValue, HttpRequest::METHOD_PATCH, 'items'); + $request = $this->requestFactory->customItemAction('shop', 'orders', $tokenValue, HttpRequest::METHOD_POST, 'items'); $request->updateContent([ 'productVariant' => $this->productVariantResolver->getVariant($product)->getCode(), @@ -59,12 +67,17 @@ public function iAddProductWithAmountAndMessage(ProductInterface $product, int $ $this->cartsClient->executeCustomRequest($request); } - private function pickupCart(): string + private function pickupCart(?string $localeCode = null): string { - $this->cartsClient->buildCreateRequest(); - $this->cartsClient->addRequestData('localeCode', null); + $request = $this->requestFactory->custom( + sprintf('%s/shop/orders', $this->apiUrlPrefix), + HttpRequest::METHOD_POST, + ['HTTP_ACCEPT_LANGUAGE' => $localeCode ?? ''], + ); + + $this->cartsClient->executeCustomRequest($request); - $tokenValue = $this->responseChecker->getValue($this->cartsClient->create(), 'tokenValue'); + $tokenValue = $this->responseChecker->getValue($this->cartsClient->getLastResponse(), 'tokenValue'); $this->sharedStorage->set('cart_token', $tokenValue); diff --git a/tests/Behat/Context/Api/Shop/ManagingGiftCardsContext.php b/tests/Behat/Context/Api/Shop/ManagingGiftCardsContext.php index ee4f8777..728c6894 100644 --- a/tests/Behat/Context/Api/Shop/ManagingGiftCardsContext.php +++ b/tests/Behat/Context/Api/Shop/ManagingGiftCardsContext.php @@ -6,7 +6,7 @@ use Behat\Behat\Context\Context; use Sylius\Behat\Client\ApiClientInterface; -use Sylius\Behat\Client\Request; +use Sylius\Behat\Client\RequestFactoryInterface; use Sylius\Behat\Client\ResponseCheckerInterface; use Sylius\Behat\Service\SharedStorageInterface; use Sylius\Component\Currency\Model\CurrencyInterface; @@ -21,14 +21,18 @@ final class ManagingGiftCardsContext implements Context private SharedStorageInterface $sharedStorage; + private RequestFactoryInterface $requestFactory; + public function __construct( ApiClientInterface $client, ResponseCheckerInterface $responseChecker, SharedStorageInterface $sharedStorage, + RequestFactoryInterface $requestFactory, ) { $this->client = $client; $this->responseChecker = $responseChecker; $this->sharedStorage = $sharedStorage; + $this->requestFactory = $requestFactory; } /** @@ -36,7 +40,7 @@ public function __construct( */ public function iBrowseGiftCards(): void { - $this->client->index(); + $this->client->index('gift-cards'); } /** @@ -44,7 +48,7 @@ public function iBrowseGiftCards(): void */ public function iOpenGiftCardPage(string $code): void { - $this->client->show($code); + $this->client->show('gift-cards', $code); } /** @@ -68,7 +72,7 @@ public function iRemoveGiftCardFromOrder(string $code): void */ public function giftCardsListShouldContain(string $code): void { - $response = $this->client->index(); + $response = $this->client->index('gift-cards'); Assert::notEmpty($this->responseChecker->getCollectionItemsWithValue($response, 'code', $code)); } @@ -78,7 +82,7 @@ public function giftCardsListShouldContain(string $code): void */ public function giftCardsListShouldNotContain(string $code): void { - $response = $this->client->index(); + $response = $this->client->index('gift-cards'); Assert::isEmpty($this->responseChecker->getCollectionItemsWithValue($response, 'code', $code)); } @@ -112,7 +116,7 @@ public function itShouldHaveCurrency(CurrencyInterface $currency): void */ public function theGiftCardShouldBeDisabled(string $code): void { - $this->client->show($code); + $this->client->show('gift-cards', $code); Assert::same($this->responseChecker->getValue($this->client->getLastResponse(), 'enabled'), false); } @@ -122,29 +126,27 @@ public function theGiftCardShouldBeDisabled(string $code): void */ public function theGiftCardShouldBeEnabled(string $code): void { - $this->client->show($code); + $this->client->show('gift-cards', $code); Assert::same($this->responseChecker->getValue($this->client->getLastResponse(), 'enabled'), true); } private function applyGiftCardToOrder(string $giftCardCode): void { - $request = Request::customItemAction( + $request = $this->requestFactory->customItemAction( 'shop', 'gift-cards', $giftCardCode, HTTPRequest::METHOD_PATCH, 'add-to-order', ); - $request->setContent(['orderTokenValue' => $this->sharedStorage->get('cart_token')]); - $this->client->executeCustomRequest($request); } private function removeGiftCardFromOrder(string $giftCardCode): void { - $request = Request::customItemAction( + $request = $this->requestFactory->customItemAction( 'shop', 'gift-cards', $giftCardCode, diff --git a/tests/Behat/Resources/api.xml b/tests/Behat/Resources/api.xml deleted file mode 100644 index 1a7616ae..00000000 --- a/tests/Behat/Resources/api.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - diff --git a/tests/Behat/Resources/api/clients.xml b/tests/Behat/Resources/api/clients.xml deleted file mode 100644 index bf39b963..00000000 --- a/tests/Behat/Resources/api/clients.xml +++ /dev/null @@ -1,32 +0,0 @@ - - - - - - - gift-card-configurations - admin - - - - gift-cards - admin - - - - gift-cards/balance - admin - - - - - gift-cards - shop - - - diff --git a/tests/Behat/Resources/context/api.xml b/tests/Behat/Resources/context/api.xml index c288acde..3a848455 100644 --- a/tests/Behat/Resources/context/api.xml +++ b/tests/Behat/Resources/context/api.xml @@ -8,21 +8,22 @@ - + + - + - + @@ -34,13 +35,16 @@ + + %sylius.security.new_api_route% - + + diff --git a/tests/Behat/Resources/services.xml b/tests/Behat/Resources/services.xml index 4ada45d2..1e04458f 100644 --- a/tests/Behat/Resources/services.xml +++ b/tests/Behat/Resources/services.xml @@ -3,7 +3,6 @@ - diff --git a/tests/Behat/Resources/suites/api/buying_gift_card.yml b/tests/Behat/Resources/suites/api/buying_gift_card.yml index 3bf6cbc1..ec331fbf 100644 --- a/tests/Behat/Resources/suites/api/buying_gift_card.yml +++ b/tests/Behat/Resources/suites/api/buying_gift_card.yml @@ -3,7 +3,7 @@ default: api_buying_gift_card: contexts: - sylius.behat.context.hook.doctrine_orm - - sylius.behat.context.hook.email_spool + - sylius.behat.context.hook.mailer - sylius.behat.context.transform.lexical - sylius.behat.context.transform.product diff --git a/tests/Behat/Resources/suites/ui/buying_gift_card.yml b/tests/Behat/Resources/suites/ui/buying_gift_card.yml index 688fe450..1cdf73d1 100644 --- a/tests/Behat/Resources/suites/ui/buying_gift_card.yml +++ b/tests/Behat/Resources/suites/ui/buying_gift_card.yml @@ -3,7 +3,7 @@ default: ui_buying_gift_card: contexts: - sylius.behat.context.hook.doctrine_orm - - sylius.behat.context.hook.email_spool + - sylius.behat.context.hook.mailer - sylius.behat.context.transform.lexical - sylius.behat.context.transform.product diff --git a/tests/Unit/Model/OrderItemTraitTest.php b/tests/Unit/Model/OrderItemTraitTest.php deleted file mode 100644 index 336e314f..00000000 --- a/tests/Unit/Model/OrderItemTraitTest.php +++ /dev/null @@ -1,35 +0,0 @@ -setProduct($product); - $firstOrderItem->setVariant($variant); - - $variant->setProduct($product); - $secondOrderItem->setVariant($variant); - - $this->assertTrue($firstOrderItem->equals($secondOrderItem)); - - $product->setGiftCard(true); - $this->assertFalse($firstOrderItem->equals($secondOrderItem)); - } -} From 358e187b57789541158b288cc7bd728507c32971 Mon Sep 17 00:00:00 2001 From: Ibes Date: Mon, 7 Oct 2024 15:08:41 +0200 Subject: [PATCH 02/15] Remove OrderItemTrait + documentation --- README.md | 25 ------------------------- src/Model/OrderItemTrait.php | 15 --------------- 2 files changed, 40 deletions(-) delete mode 100644 src/Model/OrderItemTrait.php diff --git a/README.md b/README.md index 89ed61ab..d341ad84 100644 --- a/README.md +++ b/README.md @@ -150,31 +150,6 @@ class Order extends BaseOrder implements SetonoSyliusGiftCardPluginOrderInterfac } ``` -**Extend `OrderItem`** - -```php -getProduct()->isGiftCard(); - } -} From 131355e9bd09875b13ff643200c2f84114e9567f Mon Sep 17 00:00:00 2001 From: Ibes Date: Mon, 7 Oct 2024 15:42:12 +0200 Subject: [PATCH 03/15] Remove unnecessary api_platform file to copy --- README.md | 26 -- src/Resources/config/api_platform.yaml | 3 + src/Resources/config/api_resources/Order.xml | 427 ------------------ src/Resources/config/api_resources/Order.yaml | 13 + .../config/api_platform/.gitignore | 0 .../Application/config/api_platform/Order.xml | 427 ------------------ 6 files changed, 16 insertions(+), 880 deletions(-) create mode 100644 src/Resources/config/api_platform.yaml delete mode 100644 src/Resources/config/api_resources/Order.xml create mode 100644 src/Resources/config/api_resources/Order.yaml delete mode 100644 tests/Application/config/api_platform/.gitignore delete mode 100644 tests/Application/config/api_platform/Order.xml diff --git a/README.md b/README.md index d341ad84..dd969b78 100644 --- a/README.md +++ b/README.md @@ -248,32 +248,6 @@ sylius_product: model: App\Entity\Product\Product ``` -### Copy Api Resources - -Resources declaration that need to be copied are: -* [Order.xml](src/Resources/config/api_resources/Order.xml) - -If you already have them overriden, just change the following routes: - -**[Order.xml](src/Resources/config/api_resources/Order.xml)** -```xml - - PATCH - /shop/orders/{tokenValue}/items - input - Setono\SyliusGiftCardPlugin\Api\Command\AddItemToCart - - shop:cart:read - - - shop:cart:add_item - - - Adds Item to cart - - -``` - ### Update your database: ```bash diff --git a/src/Resources/config/api_platform.yaml b/src/Resources/config/api_platform.yaml new file mode 100644 index 00000000..2c6cd328 --- /dev/null +++ b/src/Resources/config/api_platform.yaml @@ -0,0 +1,3 @@ +api_platform: + mappings: + paths: ['%kernel.project_dir%/vendor/setono/sylius-gift-card-plugin/src/Resources/config/api_resources'] diff --git a/src/Resources/config/api_resources/Order.xml b/src/Resources/config/api_resources/Order.xml deleted file mode 100644 index fc0ddeec..00000000 --- a/src/Resources/config/api_resources/Order.xml +++ /dev/null @@ -1,427 +0,0 @@ - - - - - - - sylius - - - - GET - /admin/orders - - admin:order:read - - - - - POST - /shop/orders - input - Sylius\Bundle\ApiBundle\Command\Cart\PickupCart - - - shop:order:read - shop:cart:read - - - - shop:order:create - - - Pickups a new cart - - - - - GET - /shop/orders - - - shop:order:read - - - - - - - - GET - /admin/orders/{tokenValue} - - admin:order:read - - - - - GET - /shop/orders/{tokenValue} - - shop:cart:read - - - - - DELETE - /shop/orders/{tokenValue} - - Deletes cart - - - shop:order:read - - - - - PATCH - /admin/orders/{tokenValue}/cancel - false - Sylius\Bundle\ApiBundle\Applicator\OrderStateMachineTransitionApplicatorInterface::cancel - - - admin:order:read - - - - admin:order:update - - - Cancels Order - - - - - POST - /shop/orders/{tokenValue}/items - input - Setono\SyliusGiftCardPlugin\Api\Command\AddItemToCart - - - shop:cart:read - - - - shop:cart:add_item - - - Adds Item to cart - - - - - PATCH - - sylius - - /shop/orders/{tokenValue}/shipments/{shipmentId} - input - Sylius\Bundle\ApiBundle\Command\Checkout\ChooseShippingMethod - - shop:cart:select_shipping_method - - - - shop:order:read - shop:cart:read - - - - Selects shipping methods for particular shipment - - - tokenValue - path - true - - string - - - - shipmentId - path - true - - string - - - - - - - - PATCH - /shop/orders/{tokenValue}/payments/{paymentId} - input - Sylius\Bundle\ApiBundle\Command\Checkout\ChoosePaymentMethod - - shop:cart:select_payment_method - - - - shop:order:read - shop:cart:read - - - - Selects payment methods for particular payment - - - tokenValue - path - true - - string - - - - paymentId - path - true - - string - - - - - - - - PATCH - /shop/account/orders/{tokenValue}/payments/{paymentId} - input - Sylius\Bundle\ApiBundle\Command\Account\ChangePaymentMethod - - shop:order:account:change_payment_method - - - shop:order:account:read - - - Change the payment method as logged shop user - - - tokenValue - path - true - - string - - - - paymentId - path - true - - string - - - - - - - - GET - Sylius\Bundle\ApiBundle\Controller\Payment\GetPaymentConfiguration - /shop/orders/{tokenValue}/payments/{paymentId}/configuration - - Retrieve payment method configuration - - - tokenValue - path - true - - string - - - - paymentId - path - true - - string - - - - - - - - PATCH - /shop/orders/{tokenValue}/complete - - sylius - sylius_checkout_complete - - input - Sylius\Bundle\ApiBundle\Command\Checkout\CompleteOrder - - shop:cart:complete - - - - shop:order:read - shop:cart:read - - - - Completes checkout - - - - - DELETE - /shop/orders/{tokenValue}/items/{itemId} - Sylius\Bundle\ApiBundle\Controller\DeleteOrderItemAction - false - - shop:cart:remove_item - - - - - tokenValue - path - true - - string - - - - itemId - path - true - - string - - - - - - - - PATCH - /shop/orders/{tokenValue}/items/{orderItemId} - input - Sylius\Bundle\ApiBundle\Command\Cart\ChangeItemQuantityInCart - - shop:cart:read - - - shop:cart:change_quantity - - - Changes quantity of order item - - - tokenValue - path - true - - string - - - - orderItemId - path - true - - string - - - - - - - - PUT - /shop/orders/{tokenValue} - input - Sylius\Bundle\ApiBundle\Command\Checkout\UpdateCart - - shop:cart:update - - - - shop:order:read - shop:cart:read - - - - Addresses cart to given location, logged in Customer does not have to provide an email. Applies coupon to cart. - - - - - - - GET - /shop/orders/{tokenValue}/items - - - - GET - /admin/orders/{tokenValue}/shipments - - - - GET - /admin/orders/{tokenValue}/payments - - - - GET - /shop/orders/{tokenValue}/adjustments - - - - GET - /shop/orders/{tokenValue}/items/{items}/adjustments - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/Resources/config/api_resources/Order.yaml b/src/Resources/config/api_resources/Order.yaml new file mode 100644 index 00000000..23fa6fdc --- /dev/null +++ b/src/Resources/config/api_resources/Order.yaml @@ -0,0 +1,13 @@ +'%sylius.model.order.class%': + itemOperations: + shop_add_item: + method: POST + path: /shop/orders/{tokenValue}/items + messenger: input + input: Setono\SyliusGiftCardPlugin\Api\Command\AddItemToCart + normalization_context: + groups: ['shop:cart:read'] + denormalization_context: + groups: ['shop:cart:add_item'] + openapi_context: + summary: 'Adds Item to cart' diff --git a/tests/Application/config/api_platform/.gitignore b/tests/Application/config/api_platform/.gitignore deleted file mode 100644 index e69de29b..00000000 diff --git a/tests/Application/config/api_platform/Order.xml b/tests/Application/config/api_platform/Order.xml deleted file mode 100644 index fc0ddeec..00000000 --- a/tests/Application/config/api_platform/Order.xml +++ /dev/null @@ -1,427 +0,0 @@ - - - - - - - sylius - - - - GET - /admin/orders - - admin:order:read - - - - - POST - /shop/orders - input - Sylius\Bundle\ApiBundle\Command\Cart\PickupCart - - - shop:order:read - shop:cart:read - - - - shop:order:create - - - Pickups a new cart - - - - - GET - /shop/orders - - - shop:order:read - - - - - - - - GET - /admin/orders/{tokenValue} - - admin:order:read - - - - - GET - /shop/orders/{tokenValue} - - shop:cart:read - - - - - DELETE - /shop/orders/{tokenValue} - - Deletes cart - - - shop:order:read - - - - - PATCH - /admin/orders/{tokenValue}/cancel - false - Sylius\Bundle\ApiBundle\Applicator\OrderStateMachineTransitionApplicatorInterface::cancel - - - admin:order:read - - - - admin:order:update - - - Cancels Order - - - - - POST - /shop/orders/{tokenValue}/items - input - Setono\SyliusGiftCardPlugin\Api\Command\AddItemToCart - - - shop:cart:read - - - - shop:cart:add_item - - - Adds Item to cart - - - - - PATCH - - sylius - - /shop/orders/{tokenValue}/shipments/{shipmentId} - input - Sylius\Bundle\ApiBundle\Command\Checkout\ChooseShippingMethod - - shop:cart:select_shipping_method - - - - shop:order:read - shop:cart:read - - - - Selects shipping methods for particular shipment - - - tokenValue - path - true - - string - - - - shipmentId - path - true - - string - - - - - - - - PATCH - /shop/orders/{tokenValue}/payments/{paymentId} - input - Sylius\Bundle\ApiBundle\Command\Checkout\ChoosePaymentMethod - - shop:cart:select_payment_method - - - - shop:order:read - shop:cart:read - - - - Selects payment methods for particular payment - - - tokenValue - path - true - - string - - - - paymentId - path - true - - string - - - - - - - - PATCH - /shop/account/orders/{tokenValue}/payments/{paymentId} - input - Sylius\Bundle\ApiBundle\Command\Account\ChangePaymentMethod - - shop:order:account:change_payment_method - - - shop:order:account:read - - - Change the payment method as logged shop user - - - tokenValue - path - true - - string - - - - paymentId - path - true - - string - - - - - - - - GET - Sylius\Bundle\ApiBundle\Controller\Payment\GetPaymentConfiguration - /shop/orders/{tokenValue}/payments/{paymentId}/configuration - - Retrieve payment method configuration - - - tokenValue - path - true - - string - - - - paymentId - path - true - - string - - - - - - - - PATCH - /shop/orders/{tokenValue}/complete - - sylius - sylius_checkout_complete - - input - Sylius\Bundle\ApiBundle\Command\Checkout\CompleteOrder - - shop:cart:complete - - - - shop:order:read - shop:cart:read - - - - Completes checkout - - - - - DELETE - /shop/orders/{tokenValue}/items/{itemId} - Sylius\Bundle\ApiBundle\Controller\DeleteOrderItemAction - false - - shop:cart:remove_item - - - - - tokenValue - path - true - - string - - - - itemId - path - true - - string - - - - - - - - PATCH - /shop/orders/{tokenValue}/items/{orderItemId} - input - Sylius\Bundle\ApiBundle\Command\Cart\ChangeItemQuantityInCart - - shop:cart:read - - - shop:cart:change_quantity - - - Changes quantity of order item - - - tokenValue - path - true - - string - - - - orderItemId - path - true - - string - - - - - - - - PUT - /shop/orders/{tokenValue} - input - Sylius\Bundle\ApiBundle\Command\Checkout\UpdateCart - - shop:cart:update - - - - shop:order:read - shop:cart:read - - - - Addresses cart to given location, logged in Customer does not have to provide an email. Applies coupon to cart. - - - - - - - GET - /shop/orders/{tokenValue}/items - - - - GET - /admin/orders/{tokenValue}/shipments - - - - GET - /admin/orders/{tokenValue}/payments - - - - GET - /shop/orders/{tokenValue}/adjustments - - - - GET - /shop/orders/{tokenValue}/items/{items}/adjustments - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - From 0874a98a4d2a33c2d02bef585d3ad547d476c4af Mon Sep 17 00:00:00 2001 From: Ibes Date: Mon, 7 Oct 2024 17:54:24 +0200 Subject: [PATCH 04/15] PHP 8.1 compatible with rector.php --- composer.json | 1 + rector.php | 25 +++ src/Api/Command/AddGiftCardToOrder.php | 5 +- src/Api/Command/AddItemToCart.php | 9 +- .../AssociateConfigurationToChannel.php | 8 +- .../Command/CreateGiftCardConfiguration.php | 32 +--- src/Api/Command/RemoveGiftCardFromOrder.php | 5 +- .../AddGiftCardToOrderHandler.php | 16 +- .../CommandHandler/AddItemToCartHandler.php | 32 +--- ...AssociateConfigurationToChannelHandler.php | 24 +-- .../CreateGiftCardConfigurationHandler.php | 12 +- .../RemoveGiftCardFromOrderHandler.php | 16 +- .../Action/DownloadGiftCardPdfAction.php | 12 +- .../Action/GiftCardBalanceAction.php | 5 +- .../Action/ResendGiftCardEmailAction.php | 11 +- ...UploadGiftCardConfigurationImageAction.php | 21 +-- .../DataPersister/GiftCardDataPersister.php | 5 +- .../GiftCardsByLoggedInUserExtension.php | 5 +- src/Applicator/GiftCardApplicator.php | 17 +- .../Action/AddGiftCardToOrderAction.php | 25 +-- .../Admin/GenerateEncodedExamplePdfAction.php | 20 +- .../Action/DownloadGiftCardPdfAction.php | 24 +-- .../Action/GiftCardBalanceAction.php | 12 +- .../Action/RemoveGiftCardFromOrderAction.php | 15 +- .../Action/ResendGiftCardEmailAction.php | 21 +-- .../Action/SearchGiftCardAction.php | 12 +- src/EmailManager/GiftCardEmailManager.php | 33 +--- ...DefaultGiftCardConfigurationSubscriber.php | 5 +- ...dEmailWithGiftCardToCustomerSubscriber.php | 8 +- src/Exception/ChannelMismatchException.php | 4 +- src/Exception/GiftCardNotFoundException.php | 6 +- src/Exception/UnexpectedTypeException.php | 5 +- src/Factory/GiftCardConfigurationFactory.php | 20 +- .../GiftCardConfigurationExampleFactory.php | 26 +-- .../Factory/GiftCardExampleFactory.php | 44 ++--- .../GiftCardToCodeDataTransformer.php | 14 +- src/Form/Extension/AddToCartTypeExtension.php | 16 +- src/Form/Type/AddGiftCardToOrderType.php | 8 +- .../Type/AddToCartGiftCardInformationType.php | 24 +-- .../Type/CustomerAutocompleteChoiceType.php | 5 +- src/Form/Type/DatePeriodType.php | 9 +- src/Form/Type/GiftCardConfigurationType.php | 27 +-- src/Form/Type/GiftCardSearchType.php | 8 +- src/Form/Type/GiftCardType.php | 11 +- src/Generator/GiftCardCodeGenerator.php | 13 +- src/Grid/FieldTypes/StringFieldType.php | 13 +- src/Model/GiftCard.php | 16 +- src/Model/GiftCardBalance.php | 5 +- src/Model/GiftCardConfiguration.php | 8 +- src/Model/GiftCardInterface.php | 7 +- src/Modifier/OrderGiftCardAmountModifier.php | 11 +- src/Operator/OrderGiftCardOperator.php | 24 +-- src/Order/AddToCartCommand.php | 16 +- src/Order/Factory/AddToCartCommandFactory.php | 13 +- .../Factory/GiftCardInformationFactory.php | 6 +- src/Order/GiftCardInformation.php | 8 +- src/OrderProcessor/OrderGiftCardProcessor.php | 16 +- .../GiftCardConfigurationProvider.php | 32 +--- src/Renderer/PdfRenderer.php | 43 +---- src/Resolver/CustomerChannelResolver.php | 20 +- src/Resolver/LocaleResolver.php | 22 +-- src/Resolver/RedirectUrlResolver.php | 5 +- src/Security/GiftCardVoter.php | 9 +- .../GiftCardConfigurationNormalizer.php | 20 +- .../Normalizer/GiftCardNormalizer.php | 8 +- src/Twig/Extension/PdfRuntime.php | 12 +- .../Constraints/DatePeriodValidator.php | 5 +- ...iftCardConfigurationMustExistValidator.php | 7 +- .../HasBackgroundImageValidator.php | 6 +- .../Pdf/ValidOrientationValidator.php | 5 +- .../Pdf/ValidPageSizeValidator.php | 5 +- tests/Application/config/bootstrap.php | 2 +- tests/Application/config/bundles.php | 172 ++++++++++++------ tests/Application/public/index.php | 2 +- .../ManagingGiftCardConfigurationsContext.php | 20 +- .../Admin/ManagingGiftCardsBalanceContext.php | 12 +- .../Api/Admin/ManagingGiftCardsContext.php | 18 +- tests/Behat/Context/Api/Shop/CartContext.php | 34 +--- .../Api/Shop/ManagingGiftCardsContext.php | 20 +- .../Setup/GiftCardConfigurationContext.php | 12 +- tests/Behat/Context/Setup/GiftCardContext.php | 26 +-- .../GiftCardConfigurationContext.php | 5 +- .../Context/Transform/GiftCardContext.php | 6 +- .../Ui/Admin/ManagingGiftCardsContext.php | 9 +- tests/Behat/Context/Ui/Shop/CartContext.php | 8 +- .../Behat/Context/Ui/Shop/CheckoutContext.php | 24 +-- ...ilWithGiftCardToCustomerSubscriberTest.php | 7 +- tests/Unit/Factory/GiftCardFactoryTest.php | 6 +- tests/Unit/Model/GiftCardTest.php | 11 +- 89 files changed, 386 insertions(+), 1026 deletions(-) create mode 100644 rector.php diff --git a/composer.json b/composer.json index b1e3f5c6..aa5f479d 100644 --- a/composer.json +++ b/composer.json @@ -77,6 +77,7 @@ "setono/code-quality-pack": "^2.7", "setono/sylius-behat-pack": "^0.2.2", "sylius/sylius": "~1.12.13", + "sylius/sylius-rector": "^2.0", "symfony/debug-bundle": "^5.4 || ^6.4", "symfony/dotenv": "^5.4 || ^6.4", "symfony/intl": "^5.4 || ^6.4", diff --git a/rector.php b/rector.php new file mode 100644 index 00000000..a7acd5fa --- /dev/null +++ b/rector.php @@ -0,0 +1,25 @@ +importNames(); + $rectorConfig->import(__DIR__ . '/vendor/sylius/sylius-rector/config/config.php'); + $rectorConfig->paths([ + __DIR__ . '/src', + __DIR__ . '/tests', + ]); + + $rectorConfig->skip([ + __DIR__ . '/tests/Application/var' + ]); + + $rectorConfig->sets([ + LevelSetList::UP_TO_PHP_81, // Adapt this to your PHP version + SetList::CODE_QUALITY, + ]); +}; diff --git a/src/Api/Command/AddGiftCardToOrder.php b/src/Api/Command/AddGiftCardToOrder.php index 43dd5a29..6bfdec6a 100644 --- a/src/Api/Command/AddGiftCardToOrder.php +++ b/src/Api/Command/AddGiftCardToOrder.php @@ -8,11 +8,8 @@ class AddGiftCardToOrder implements GiftCardCodeAwareInterface { public ?string $giftCardCode = null; - public string $orderTokenValue; - - public function __construct(string $orderTokenValue) + public function __construct(public string $orderTokenValue) { - $this->orderTokenValue = $orderTokenValue; } public function getGiftCardCode(): ?string diff --git a/src/Api/Command/AddItemToCart.php b/src/Api/Command/AddItemToCart.php index fdf8735e..aa55c9f8 100644 --- a/src/Api/Command/AddItemToCart.php +++ b/src/Api/Command/AddItemToCart.php @@ -8,16 +8,9 @@ class AddItemToCart extends BaseAddItemToCart { - protected ?int $amount; - - protected ?string $customMessage; - - public function __construct(string $productVariantCode, int $quantity, int $amount = null, string $customMessage = null) + public function __construct(string $productVariantCode, int $quantity, protected ?int $amount = null, protected ?string $customMessage = null) { parent::__construct($productVariantCode, $quantity); - - $this->amount = $amount; - $this->customMessage = $customMessage; } public function getAmount(): ?int diff --git a/src/Api/Command/AssociateConfigurationToChannel.php b/src/Api/Command/AssociateConfigurationToChannel.php index 92032cde..a00ee08d 100644 --- a/src/Api/Command/AssociateConfigurationToChannel.php +++ b/src/Api/Command/AssociateConfigurationToChannel.php @@ -8,14 +8,8 @@ class AssociateConfigurationToChannel implements ConfigurationCodeAwareInterface { public ?string $configurationCode = null; - public string $localeCode; - - public string $channelCode; - - public function __construct(string $localeCode, string $channelCode) + public function __construct(public string $localeCode, public string $channelCode) { - $this->localeCode = $localeCode; - $this->channelCode = $channelCode; } public function getConfigurationCode(): ?string diff --git a/src/Api/Command/CreateGiftCardConfiguration.php b/src/Api/Command/CreateGiftCardConfiguration.php index bc4907dc..37451a8d 100644 --- a/src/Api/Command/CreateGiftCardConfiguration.php +++ b/src/Api/Command/CreateGiftCardConfiguration.php @@ -6,35 +6,7 @@ class CreateGiftCardConfiguration { - public string $code; - - public bool $default = false; - - public bool $enabled = true; - - public ?string $defaultValidityPeriod = null; - - public ?string $pageSize = null; - - public ?string $orientation = null; - - public ?string $template = null; - - public function __construct( - string $code, - bool $default = false, - bool $enabled = true, - ?string $defaultValidityPeriod = null, - ?string $pageSize = null, - ?string $orientation = null, - ?string $template = null, - ) { - $this->code = $code; - $this->default = $default; - $this->enabled = $enabled; - $this->defaultValidityPeriod = $defaultValidityPeriod; - $this->pageSize = $pageSize; - $this->orientation = $orientation; - $this->template = $template; + public function __construct(public string $code, public bool $default = false, public bool $enabled = true, public ?string $defaultValidityPeriod = null, public ?string $pageSize = null, public ?string $orientation = null, public ?string $template = null) + { } } diff --git a/src/Api/Command/RemoveGiftCardFromOrder.php b/src/Api/Command/RemoveGiftCardFromOrder.php index 739b3e3a..0c1c1f21 100644 --- a/src/Api/Command/RemoveGiftCardFromOrder.php +++ b/src/Api/Command/RemoveGiftCardFromOrder.php @@ -8,11 +8,8 @@ class RemoveGiftCardFromOrder implements GiftCardCodeAwareInterface { public ?string $giftCardCode = null; - public string $orderTokenValue; - - public function __construct(string $orderTokenValue) + public function __construct(public string $orderTokenValue) { - $this->orderTokenValue = $orderTokenValue; } public function getGiftCardCode(): ?string diff --git a/src/Api/CommandHandler/AddGiftCardToOrderHandler.php b/src/Api/CommandHandler/AddGiftCardToOrderHandler.php index 6fca53ef..16bc47ef 100644 --- a/src/Api/CommandHandler/AddGiftCardToOrderHandler.php +++ b/src/Api/CommandHandler/AddGiftCardToOrderHandler.php @@ -14,20 +14,8 @@ final class AddGiftCardToOrderHandler { - private GiftCardRepositoryInterface $giftCardRepository; - - private OrderRepositoryInterface $orderRepository; - - private GiftCardApplicatorInterface $giftCardApplicator; - - public function __construct( - GiftCardRepositoryInterface $giftCardRepository, - OrderRepositoryInterface $orderRepository, - GiftCardApplicatorInterface $giftCardApplicator, - ) { - $this->giftCardRepository = $giftCardRepository; - $this->orderRepository = $orderRepository; - $this->giftCardApplicator = $giftCardApplicator; + public function __construct(private readonly GiftCardRepositoryInterface $giftCardRepository, private readonly OrderRepositoryInterface $orderRepository, private readonly GiftCardApplicatorInterface $giftCardApplicator) + { } public function __invoke(AddGiftCardToOrder $command): GiftCardInterface diff --git a/src/Api/CommandHandler/AddItemToCartHandler.php b/src/Api/CommandHandler/AddItemToCartHandler.php index 54535be5..22652031 100644 --- a/src/Api/CommandHandler/AddItemToCartHandler.php +++ b/src/Api/CommandHandler/AddItemToCartHandler.php @@ -22,36 +22,8 @@ final class AddItemToCartHandler { - private OrderRepositoryInterface $orderRepository; - - private ProductVariantRepositoryInterface $productVariantRepository; - - private OrderModifierInterface $orderModifier; - - private CartItemFactoryInterface $cartItemFactory; - - private OrderItemQuantityModifierInterface $orderItemQuantityModifier; - - private GiftCardFactoryInterface $giftCardFactory; - - private EntityManagerInterface $giftCardManager; - - public function __construct( - OrderRepositoryInterface $orderRepository, - ProductVariantRepositoryInterface $productVariantRepository, - OrderModifierInterface $orderModifier, - CartItemFactoryInterface $cartItemFactory, - OrderItemQuantityModifierInterface $orderItemQuantityModifier, - GiftCardFactoryInterface $giftCardFactory, - EntityManagerInterface $giftCardManager, - ) { - $this->orderRepository = $orderRepository; - $this->productVariantRepository = $productVariantRepository; - $this->orderModifier = $orderModifier; - $this->cartItemFactory = $cartItemFactory; - $this->orderItemQuantityModifier = $orderItemQuantityModifier; - $this->giftCardFactory = $giftCardFactory; - $this->giftCardManager = $giftCardManager; + public function __construct(private readonly OrderRepositoryInterface $orderRepository, private readonly ProductVariantRepositoryInterface $productVariantRepository, private readonly OrderModifierInterface $orderModifier, private readonly CartItemFactoryInterface $cartItemFactory, private readonly OrderItemQuantityModifierInterface $orderItemQuantityModifier, private readonly GiftCardFactoryInterface $giftCardFactory, private readonly EntityManagerInterface $giftCardManager) + { } public function __invoke(SyliusAddItemToCart $addItemToCart): OrderInterface diff --git a/src/Api/CommandHandler/AssociateConfigurationToChannelHandler.php b/src/Api/CommandHandler/AssociateConfigurationToChannelHandler.php index f8418c22..7788a73a 100644 --- a/src/Api/CommandHandler/AssociateConfigurationToChannelHandler.php +++ b/src/Api/CommandHandler/AssociateConfigurationToChannelHandler.php @@ -15,28 +15,8 @@ final class AssociateConfigurationToChannelHandler { - private RepositoryInterface $giftCardConfigurationRepository; - - private ChannelRepositoryInterface $channelRepository; - - private RepositoryInterface $localeRepository; - - private RepositoryInterface $giftCardChannelConfigurationRepository; - - private FactoryInterface $giftCardChannelConfigurationFactory; - - public function __construct( - RepositoryInterface $giftCardConfigurationRepository, - ChannelRepositoryInterface $channelRepository, - RepositoryInterface $localeRepository, - RepositoryInterface $giftCardChannelConfigurationRepository, - FactoryInterface $giftCardChannelConfigurationFactory, - ) { - $this->giftCardConfigurationRepository = $giftCardConfigurationRepository; - $this->channelRepository = $channelRepository; - $this->localeRepository = $localeRepository; - $this->giftCardChannelConfigurationRepository = $giftCardChannelConfigurationRepository; - $this->giftCardChannelConfigurationFactory = $giftCardChannelConfigurationFactory; + public function __construct(private readonly RepositoryInterface $giftCardConfigurationRepository, private readonly ChannelRepositoryInterface $channelRepository, private readonly RepositoryInterface $localeRepository, private readonly RepositoryInterface $giftCardChannelConfigurationRepository, private readonly FactoryInterface $giftCardChannelConfigurationFactory) + { } public function __invoke(AssociateConfigurationToChannel $command): GiftCardConfigurationInterface diff --git a/src/Api/CommandHandler/CreateGiftCardConfigurationHandler.php b/src/Api/CommandHandler/CreateGiftCardConfigurationHandler.php index 47fb3e63..4cae7792 100644 --- a/src/Api/CommandHandler/CreateGiftCardConfigurationHandler.php +++ b/src/Api/CommandHandler/CreateGiftCardConfigurationHandler.php @@ -11,16 +11,8 @@ final class CreateGiftCardConfigurationHandler { - private GiftCardConfigurationFactoryInterface $giftCardConfigurationFactory; - - private ObjectManager $giftCardConfigurationManager; - - public function __construct( - GiftCardConfigurationFactoryInterface $giftCardConfigurationFactory, - ObjectManager $giftCardConfigurationManager, - ) { - $this->giftCardConfigurationFactory = $giftCardConfigurationFactory; - $this->giftCardConfigurationManager = $giftCardConfigurationManager; + public function __construct(private readonly GiftCardConfigurationFactoryInterface $giftCardConfigurationFactory, private readonly ObjectManager $giftCardConfigurationManager) + { } public function __invoke(CreateGiftCardConfiguration $command): GiftCardConfigurationInterface diff --git a/src/Api/CommandHandler/RemoveGiftCardFromOrderHandler.php b/src/Api/CommandHandler/RemoveGiftCardFromOrderHandler.php index 8487fa23..267420b8 100644 --- a/src/Api/CommandHandler/RemoveGiftCardFromOrderHandler.php +++ b/src/Api/CommandHandler/RemoveGiftCardFromOrderHandler.php @@ -14,20 +14,8 @@ final class RemoveGiftCardFromOrderHandler { - private GiftCardRepositoryInterface $giftCardRepository; - - private OrderRepositoryInterface $orderRepository; - - private GiftCardApplicatorInterface $giftCardApplicator; - - public function __construct( - GiftCardRepositoryInterface $giftCardRepository, - OrderRepositoryInterface $orderRepository, - GiftCardApplicatorInterface $giftCardApplicator, - ) { - $this->giftCardRepository = $giftCardRepository; - $this->orderRepository = $orderRepository; - $this->giftCardApplicator = $giftCardApplicator; + public function __construct(private readonly GiftCardRepositoryInterface $giftCardRepository, private readonly OrderRepositoryInterface $orderRepository, private readonly GiftCardApplicatorInterface $giftCardApplicator) + { } public function __invoke(RemoveGiftCardFromOrder $command): GiftCardInterface diff --git a/src/Api/Controller/Action/DownloadGiftCardPdfAction.php b/src/Api/Controller/Action/DownloadGiftCardPdfAction.php index 8f7ced89..886b9458 100644 --- a/src/Api/Controller/Action/DownloadGiftCardPdfAction.php +++ b/src/Api/Controller/Action/DownloadGiftCardPdfAction.php @@ -13,16 +13,8 @@ final class DownloadGiftCardPdfAction { - private GiftCardConfigurationProviderInterface $configurationProvider; - - private PdfRendererInterface $pdfRenderer; - - public function __construct( - GiftCardConfigurationProviderInterface $configurationProvider, - PdfRendererInterface $giftCardPDFRenderer, - ) { - $this->configurationProvider = $configurationProvider; - $this->pdfRenderer = $giftCardPDFRenderer; + public function __construct(private readonly GiftCardConfigurationProviderInterface $configurationProvider, private readonly PdfRendererInterface $pdfRenderer) + { } public function __invoke(GiftCardInterface $data): Response diff --git a/src/Api/Controller/Action/GiftCardBalanceAction.php b/src/Api/Controller/Action/GiftCardBalanceAction.php index 7b89460c..0480e20d 100644 --- a/src/Api/Controller/Action/GiftCardBalanceAction.php +++ b/src/Api/Controller/Action/GiftCardBalanceAction.php @@ -9,11 +9,8 @@ final class GiftCardBalanceAction { - private GiftCardRepositoryInterface $giftCardRepository; - - public function __construct(GiftCardRepositoryInterface $giftCardRepository) + public function __construct(private readonly GiftCardRepositoryInterface $giftCardRepository) { - $this->giftCardRepository = $giftCardRepository; } public function __invoke(): GiftCardBalanceCollection diff --git a/src/Api/Controller/Action/ResendGiftCardEmailAction.php b/src/Api/Controller/Action/ResendGiftCardEmailAction.php index fbbc7643..523bccab 100644 --- a/src/Api/Controller/Action/ResendGiftCardEmailAction.php +++ b/src/Api/Controller/Action/ResendGiftCardEmailAction.php @@ -6,23 +6,22 @@ use Setono\SyliusGiftCardPlugin\EmailManager\GiftCardEmailManagerInterface; use Setono\SyliusGiftCardPlugin\Model\GiftCardInterface; +use Sylius\Component\Core\Model\CustomerInterface; +use Sylius\Component\Core\Model\OrderInterface; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpKernel\Exception\BadRequestHttpException; final class ResendGiftCardEmailAction { - private GiftCardEmailManagerInterface $giftCardEmailManager; - - public function __construct(GiftCardEmailManagerInterface $giftCardEmailManager) + public function __construct(private readonly GiftCardEmailManagerInterface $giftCardEmailManager) { - $this->giftCardEmailManager = $giftCardEmailManager; } public function __invoke(GiftCardInterface $data): Response { - if (($order = $data->getOrder()) !== null) { + if (($order = $data->getOrder()) instanceof OrderInterface) { $this->giftCardEmailManager->sendEmailWithGiftCardsFromOrder($order, [$data]); - } elseif (($customer = $data->getCustomer()) !== null) { + } elseif (($customer = $data->getCustomer()) instanceof CustomerInterface) { $this->giftCardEmailManager->sendEmailToCustomerWithGiftCard($customer, $data); } else { throw new BadRequestHttpException(); diff --git a/src/Api/Controller/Action/UploadGiftCardConfigurationImageAction.php b/src/Api/Controller/Action/UploadGiftCardConfigurationImageAction.php index 79c47634..1f064f2f 100644 --- a/src/Api/Controller/Action/UploadGiftCardConfigurationImageAction.php +++ b/src/Api/Controller/Action/UploadGiftCardConfigurationImageAction.php @@ -17,28 +17,11 @@ final class UploadGiftCardConfigurationImageAction { - private FactoryInterface $giftCardConfigurationImageFactory; - - private RepositoryInterface $giftCardConfigurationImageRepository; - - private ImageUploaderInterface $imageUploader; - - /** @var LegacyIriConverterInterface|IriConverterInterface */ - private $iriConverter; - /** * @param LegacyIriConverterInterface|IriConverterInterface $iriConverter */ - public function __construct( - FactoryInterface $giftCardConfigurationImageFactory, - RepositoryInterface $giftCardConfigurationImageRepository, - ImageUploaderInterface $imageUploader, - $iriConverter, - ) { - $this->giftCardConfigurationImageFactory = $giftCardConfigurationImageFactory; - $this->giftCardConfigurationImageRepository = $giftCardConfigurationImageRepository; - $this->imageUploader = $imageUploader; - $this->iriConverter = $iriConverter; + public function __construct(private readonly FactoryInterface $giftCardConfigurationImageFactory, private readonly RepositoryInterface $giftCardConfigurationImageRepository, private readonly ImageUploaderInterface $imageUploader, private $iriConverter) + { } public function __invoke(Request $request): GiftCardConfigurationImageInterface diff --git a/src/Api/DataPersister/GiftCardDataPersister.php b/src/Api/DataPersister/GiftCardDataPersister.php index 1512447e..097270dd 100644 --- a/src/Api/DataPersister/GiftCardDataPersister.php +++ b/src/Api/DataPersister/GiftCardDataPersister.php @@ -10,11 +10,8 @@ final class GiftCardDataPersister implements ContextAwareDataPersisterInterface { - private ContextAwareDataPersisterInterface $decoratedDataPersister; - - public function __construct(ContextAwareDataPersisterInterface $decoratedDataPersister) + public function __construct(private readonly ContextAwareDataPersisterInterface $decoratedDataPersister) { - $this->decoratedDataPersister = $decoratedDataPersister; } /** diff --git a/src/Api/Doctrine/QueryCollectionExtension/GiftCardsByLoggedInUserExtension.php b/src/Api/Doctrine/QueryCollectionExtension/GiftCardsByLoggedInUserExtension.php index 41b62e32..49757493 100644 --- a/src/Api/Doctrine/QueryCollectionExtension/GiftCardsByLoggedInUserExtension.php +++ b/src/Api/Doctrine/QueryCollectionExtension/GiftCardsByLoggedInUserExtension.php @@ -17,11 +17,8 @@ final class GiftCardsByLoggedInUserExtension implements ContextAwareQueryCollectionExtensionInterface { - private UserContextInterface $userContext; - - public function __construct(UserContextInterface $userContext) + public function __construct(private readonly UserContextInterface $userContext) { - $this->userContext = $userContext; } public function applyToCollection( diff --git a/src/Applicator/GiftCardApplicator.php b/src/Applicator/GiftCardApplicator.php index b6770512..5424f8d9 100644 --- a/src/Applicator/GiftCardApplicator.php +++ b/src/Applicator/GiftCardApplicator.php @@ -10,20 +10,13 @@ use Setono\SyliusGiftCardPlugin\Model\GiftCardInterface; use Setono\SyliusGiftCardPlugin\Model\OrderInterface; use Setono\SyliusGiftCardPlugin\Repository\GiftCardRepositoryInterface; +use Sylius\Component\Channel\Model\ChannelInterface; use Sylius\Component\Order\Processor\OrderProcessorInterface; final class GiftCardApplicator implements GiftCardApplicatorInterface { - private GiftCardRepositoryInterface $giftCardRepository; - - private OrderProcessorInterface $orderProcessor; - - public function __construct( - GiftCardRepositoryInterface $giftCardRepository, - OrderProcessorInterface $orderProcessor, - ) { - $this->giftCardRepository = $giftCardRepository; - $this->orderProcessor = $orderProcessor; + public function __construct(private readonly GiftCardRepositoryInterface $giftCardRepository, private readonly OrderProcessorInterface $orderProcessor) + { } /** @@ -44,7 +37,7 @@ public function apply(OrderInterface $order, $giftCard): void } $orderChannel = $order->getChannel(); - if (null === $orderChannel) { + if (!$orderChannel instanceof ChannelInterface) { throw new RuntimeException('The channel on the order cannot be null'); } @@ -80,7 +73,7 @@ private function getGiftCard(string $giftCardCode): GiftCardInterface { $giftCard = $this->giftCardRepository->findOneByCode($giftCardCode); - if (null === $giftCard) { + if (!$giftCard instanceof GiftCardInterface) { throw new GiftCardNotFoundException($giftCardCode); } diff --git a/src/Controller/Action/AddGiftCardToOrderAction.php b/src/Controller/Action/AddGiftCardToOrderAction.php index c6d8f6fd..b353b49d 100644 --- a/src/Controller/Action/AddGiftCardToOrderAction.php +++ b/src/Controller/Action/AddGiftCardToOrderAction.php @@ -24,29 +24,14 @@ final class AddGiftCardToOrderAction { use ORMManagerTrait; - private FormFactoryInterface $formFactory; - - private CartContextInterface $cartContext; - - private GiftCardApplicatorInterface $giftCardApplicator; - - private RedirectUrlResolverInterface $redirectRouteResolver; - - private Environment $twig; - public function __construct( - FormFactoryInterface $formFactory, - CartContextInterface $cartContext, - GiftCardApplicatorInterface $giftCardApplicator, - RedirectUrlResolverInterface $redirectRouteResolver, - Environment $twig, + private FormFactoryInterface $formFactory, + private CartContextInterface $cartContext, + private GiftCardApplicatorInterface $giftCardApplicator, + private RedirectUrlResolverInterface $redirectRouteResolver, + private Environment $twig, ManagerRegistry $managerRegistry, ) { - $this->formFactory = $formFactory; - $this->cartContext = $cartContext; - $this->giftCardApplicator = $giftCardApplicator; - $this->redirectRouteResolver = $redirectRouteResolver; - $this->twig = $twig; $this->managerRegistry = $managerRegistry; } diff --git a/src/Controller/Action/Admin/GenerateEncodedExamplePdfAction.php b/src/Controller/Action/Admin/GenerateEncodedExamplePdfAction.php index 80d95580..f8efbcfe 100644 --- a/src/Controller/Action/Admin/GenerateEncodedExamplePdfAction.php +++ b/src/Controller/Action/Admin/GenerateEncodedExamplePdfAction.php @@ -16,24 +16,8 @@ final class GenerateEncodedExamplePdfAction { - private GiftCardFactoryInterface $giftCardFactory; - - private GiftCardConfigurationRepositoryInterface $giftCardConfigurationRepository; - - private PdfRendererInterface $pdfRenderer; - - private FormFactoryInterface $formFactory; - - public function __construct( - GiftCardFactoryInterface $giftCardFactory, - GiftCardConfigurationRepositoryInterface $giftCardConfigurationRepository, - PdfRendererInterface $giftCardPDFRenderer, - FormFactoryInterface $formFactory, - ) { - $this->giftCardFactory = $giftCardFactory; - $this->giftCardConfigurationRepository = $giftCardConfigurationRepository; - $this->pdfRenderer = $giftCardPDFRenderer; - $this->formFactory = $formFactory; + public function __construct(private readonly GiftCardFactoryInterface $giftCardFactory, private readonly GiftCardConfigurationRepositoryInterface $giftCardConfigurationRepository, private readonly PdfRendererInterface $pdfRenderer, private readonly FormFactoryInterface $formFactory) + { } public function __invoke(Request $request, int $id): Response diff --git a/src/Controller/Action/DownloadGiftCardPdfAction.php b/src/Controller/Action/DownloadGiftCardPdfAction.php index 9646be7f..16492bf6 100644 --- a/src/Controller/Action/DownloadGiftCardPdfAction.php +++ b/src/Controller/Action/DownloadGiftCardPdfAction.php @@ -20,28 +20,8 @@ final class DownloadGiftCardPdfAction { - private GiftCardRepositoryInterface $giftCardRepository; - - private AuthorizationCheckerInterface $authChecker; - - private GiftCardConfigurationProviderInterface $configurationProvider; - - private PdfRendererInterface $PDFRenderer; - - private UrlGeneratorInterface $urlGenerator; - - public function __construct( - GiftCardRepositoryInterface $giftCardRepository, - AuthorizationCheckerInterface $authChecker, - GiftCardConfigurationProviderInterface $configurationProvider, - PdfRendererInterface $giftCardPDFRenderer, - UrlGeneratorInterface $urlGenerator, - ) { - $this->giftCardRepository = $giftCardRepository; - $this->authChecker = $authChecker; - $this->configurationProvider = $configurationProvider; - $this->PDFRenderer = $giftCardPDFRenderer; - $this->urlGenerator = $urlGenerator; + public function __construct(private readonly GiftCardRepositoryInterface $giftCardRepository, private readonly AuthorizationCheckerInterface $authChecker, private readonly GiftCardConfigurationProviderInterface $configurationProvider, private readonly PdfRendererInterface $PDFRenderer, private readonly UrlGeneratorInterface $urlGenerator) + { } public function __invoke(Request $request, int $id): Response diff --git a/src/Controller/Action/GiftCardBalanceAction.php b/src/Controller/Action/GiftCardBalanceAction.php index 828cd210..457b18ee 100644 --- a/src/Controller/Action/GiftCardBalanceAction.php +++ b/src/Controller/Action/GiftCardBalanceAction.php @@ -15,16 +15,8 @@ */ final class GiftCardBalanceAction { - private GiftCardRepositoryInterface $giftCardRepository; - - private Environment $twig; - - public function __construct( - GiftCardRepositoryInterface $giftCardRepository, - Environment $twig, - ) { - $this->giftCardRepository = $giftCardRepository; - $this->twig = $twig; + public function __construct(private readonly GiftCardRepositoryInterface $giftCardRepository, private readonly Environment $twig) + { } public function __invoke(Request $request): Response diff --git a/src/Controller/Action/RemoveGiftCardFromOrderAction.php b/src/Controller/Action/RemoveGiftCardFromOrderAction.php index c0cc8e25..d344065e 100644 --- a/src/Controller/Action/RemoveGiftCardFromOrderAction.php +++ b/src/Controller/Action/RemoveGiftCardFromOrderAction.php @@ -21,21 +21,12 @@ final class RemoveGiftCardFromOrderAction { use ORMManagerTrait; - private CartContextInterface $cartContext; - - private GiftCardApplicatorInterface $giftCardApplicator; - - private RedirectUrlResolverInterface $redirectRouteResolver; - public function __construct( - CartContextInterface $cartContext, - GiftCardApplicatorInterface $giftCardApplicator, - RedirectUrlResolverInterface $redirectRouteResolver, + private CartContextInterface $cartContext, + private GiftCardApplicatorInterface $giftCardApplicator, + private RedirectUrlResolverInterface $redirectRouteResolver, ManagerRegistry $managerRegistry, ) { - $this->cartContext = $cartContext; - $this->giftCardApplicator = $giftCardApplicator; - $this->redirectRouteResolver = $redirectRouteResolver; $this->managerRegistry = $managerRegistry; } diff --git a/src/Controller/Action/ResendGiftCardEmailAction.php b/src/Controller/Action/ResendGiftCardEmailAction.php index e8533710..4620be2b 100644 --- a/src/Controller/Action/ResendGiftCardEmailAction.php +++ b/src/Controller/Action/ResendGiftCardEmailAction.php @@ -19,20 +19,8 @@ final class ResendGiftCardEmailAction { - private GiftCardEmailManagerInterface $giftCardEmailManager; - - private GiftCardRepositoryInterface $giftCardRepository; - - private UrlGeneratorInterface $router; - - public function __construct( - GiftCardEmailManagerInterface $giftCardEmailManager, - GiftCardRepositoryInterface $giftCardRepository, - UrlGeneratorInterface $router, - ) { - $this->giftCardEmailManager = $giftCardEmailManager; - $this->giftCardRepository = $giftCardRepository; - $this->router = $router; + public function __construct(private readonly GiftCardEmailManagerInterface $giftCardEmailManager, private readonly GiftCardRepositoryInterface $giftCardRepository, private readonly UrlGeneratorInterface $router) + { } public function __invoke(Request $request, int $id): Response @@ -86,10 +74,7 @@ private function getRedirectUrl(Request $request): string return $this->router->generate('setono_sylius_gift_card_admin_gift_card_index'); } - /** - * @param mixed $message - */ - private function addFlash(Request $request, string $type, $message): void + private function addFlash(Request $request, string $type, mixed $message): void { $session = $request->getSession(); if ($session instanceof Session) { diff --git a/src/Controller/Action/SearchGiftCardAction.php b/src/Controller/Action/SearchGiftCardAction.php index c4b542ab..579da7db 100644 --- a/src/Controller/Action/SearchGiftCardAction.php +++ b/src/Controller/Action/SearchGiftCardAction.php @@ -12,16 +12,8 @@ final class SearchGiftCardAction { - private FormFactoryInterface $formFactory; - - private Environment $twig; - - public function __construct( - FormFactoryInterface $formFactory, - Environment $twig, - ) { - $this->formFactory = $formFactory; - $this->twig = $twig; + public function __construct(private readonly FormFactoryInterface $formFactory, private readonly Environment $twig) + { } public function __invoke(Request $request): Response diff --git a/src/EmailManager/GiftCardEmailManager.php b/src/EmailManager/GiftCardEmailManager.php index 2bafce64..905931fe 100644 --- a/src/EmailManager/GiftCardEmailManager.php +++ b/src/EmailManager/GiftCardEmailManager.php @@ -9,6 +9,7 @@ use Setono\SyliusGiftCardPlugin\Renderer\PdfRendererInterface; use Setono\SyliusGiftCardPlugin\Resolver\CustomerChannelResolverInterface; use Setono\SyliusGiftCardPlugin\Resolver\LocaleResolverInterface; +use Sylius\Component\Channel\Model\ChannelInterface; use Sylius\Component\Core\Model\CustomerInterface; use Sylius\Component\Core\Model\OrderInterface; use Sylius\Component\Mailer\Sender\SenderInterface; @@ -17,32 +18,8 @@ final class GiftCardEmailManager implements GiftCardEmailManagerInterface { - private SenderInterface $sender; - - private LocaleAwareInterface $translator; - - private CustomerChannelResolverInterface $customerChannelResolver; - - private LocaleResolverInterface $localeResolver; - - private PdfRendererInterface $pdfRenderer; - - private string $cacheDir; - - public function __construct( - SenderInterface $sender, - LocaleAwareInterface $translator, - CustomerChannelResolverInterface $customerChannelResolver, - LocaleResolverInterface $customerLocaleResolver, - PdfRendererInterface $pdfRenderer, - string $cacheDir, - ) { - $this->sender = $sender; - $this->translator = $translator; - $this->customerChannelResolver = $customerChannelResolver; - $this->localeResolver = $customerLocaleResolver; - $this->pdfRenderer = $pdfRenderer; - $this->cacheDir = $cacheDir; + public function __construct(private readonly SenderInterface $sender, private readonly LocaleAwareInterface $translator, private readonly CustomerChannelResolverInterface $customerChannelResolver, private readonly LocaleResolverInterface $localeResolver, private readonly PdfRendererInterface $pdfRenderer, private readonly string $cacheDir) + { } public function sendEmailToCustomerWithGiftCard(CustomerInterface $customer, GiftCardInterface $giftCard): void @@ -75,7 +52,7 @@ public function sendEmailToCustomerWithGiftCard(CustomerInterface $customer, Gif public function sendEmailWithGiftCardsFromOrder(OrderInterface $order, array $giftCards): void { $customer = $order->getCustomer(); - if (null === $customer) { + if (!$customer instanceof \Sylius\Component\Customer\Model\CustomerInterface) { return; } @@ -85,7 +62,7 @@ public function sendEmailWithGiftCardsFromOrder(OrderInterface $order, array $gi } $channel = $order->getChannel(); - if (null === $channel) { + if (!$channel instanceof ChannelInterface) { return; } diff --git a/src/EventSubscriber/DefaultGiftCardConfigurationSubscriber.php b/src/EventSubscriber/DefaultGiftCardConfigurationSubscriber.php index f6a8ac3f..91f72e16 100644 --- a/src/EventSubscriber/DefaultGiftCardConfigurationSubscriber.php +++ b/src/EventSubscriber/DefaultGiftCardConfigurationSubscriber.php @@ -15,11 +15,8 @@ */ final class DefaultGiftCardConfigurationSubscriber implements EventSubscriberInterface { - private GiftCardConfigurationRepositoryInterface $giftCardConfigurationRepository; - - public function __construct(GiftCardConfigurationRepositoryInterface $giftCardConfigurationRepository) + public function __construct(private readonly GiftCardConfigurationRepositoryInterface $giftCardConfigurationRepository) { - $this->giftCardConfigurationRepository = $giftCardConfigurationRepository; } public static function getSubscribedEvents(): array diff --git a/src/EventSubscriber/SendEmailWithGiftCardToCustomerSubscriber.php b/src/EventSubscriber/SendEmailWithGiftCardToCustomerSubscriber.php index 7a6c37d4..23ff3297 100644 --- a/src/EventSubscriber/SendEmailWithGiftCardToCustomerSubscriber.php +++ b/src/EventSubscriber/SendEmailWithGiftCardToCustomerSubscriber.php @@ -7,6 +7,7 @@ use Setono\SyliusGiftCardPlugin\EmailManager\GiftCardEmailManagerInterface; use Setono\SyliusGiftCardPlugin\Model\GiftCardInterface; use Sylius\Bundle\ResourceBundle\Event\ResourceControllerEvent; +use Sylius\Component\Core\Model\CustomerInterface; use Sylius\Component\Resource\Exception\UnexpectedTypeException; use Symfony\Component\EventDispatcher\EventSubscriberInterface; @@ -16,11 +17,8 @@ */ final class SendEmailWithGiftCardToCustomerSubscriber implements EventSubscriberInterface { - private GiftCardEmailManagerInterface $giftCardEmailManager; - - public function __construct(GiftCardEmailManagerInterface $giftCardEmailManager) + public function __construct(private readonly GiftCardEmailManagerInterface $giftCardEmailManager) { - $this->giftCardEmailManager = $giftCardEmailManager; } public static function getSubscribedEvents(): array @@ -38,7 +36,7 @@ public function postCreate(ResourceControllerEvent $event): void } $customer = $giftCard->getCustomer(); - if (null === $customer) { + if (!$customer instanceof CustomerInterface) { return; } diff --git a/src/Exception/ChannelMismatchException.php b/src/Exception/ChannelMismatchException.php index 385bc17d..4d97e91a 100644 --- a/src/Exception/ChannelMismatchException.php +++ b/src/Exception/ChannelMismatchException.php @@ -10,9 +10,9 @@ final class ChannelMismatchException extends InvalidArgumentException implements ExceptionInterface { - private ChannelInterface $actualChannel; + private readonly ChannelInterface $actualChannel; - private ChannelInterface $expectedChannel; + private readonly ChannelInterface $expectedChannel; public function __construct(ChannelInterface $actualChannel, ChannelInterface $expectedChannel) { diff --git a/src/Exception/GiftCardNotFoundException.php b/src/Exception/GiftCardNotFoundException.php index 1f7b73ec..0f96dd75 100644 --- a/src/Exception/GiftCardNotFoundException.php +++ b/src/Exception/GiftCardNotFoundException.php @@ -9,12 +9,8 @@ final class GiftCardNotFoundException extends InvalidArgumentException implements ExceptionInterface { - private string $giftCard; - - public function __construct(string $giftCard) + public function __construct(private readonly string $giftCard) { - $this->giftCard = $giftCard; - parent::__construct(sprintf('The gift card with code "%s" was not found', $this->giftCard)); } diff --git a/src/Exception/UnexpectedTypeException.php b/src/Exception/UnexpectedTypeException.php index 812ca0c4..58df04fa 100644 --- a/src/Exception/UnexpectedTypeException.php +++ b/src/Exception/UnexpectedTypeException.php @@ -4,10 +4,7 @@ namespace Setono\SyliusGiftCardPlugin\Exception; -use function get_class; -use function gettype; use InvalidArgumentException; -use function is_object; use function sprintf; final class UnexpectedTypeException extends InvalidArgumentException implements ExceptionInterface @@ -17,6 +14,6 @@ final class UnexpectedTypeException extends InvalidArgumentException implements */ public function __construct($value, string ...$expectedTypes) { - parent::__construct(sprintf('Expected argument of type "%s", "%s" given', implode(', ', $expectedTypes), is_object($value) ? get_class($value) : gettype($value))); + parent::__construct(sprintf('Expected argument of type "%s", "%s" given', implode(', ', $expectedTypes), get_debug_type($value))); } } diff --git a/src/Factory/GiftCardConfigurationFactory.php b/src/Factory/GiftCardConfigurationFactory.php index f51fc279..689dc941 100644 --- a/src/Factory/GiftCardConfigurationFactory.php +++ b/src/Factory/GiftCardConfigurationFactory.php @@ -10,24 +10,8 @@ final class GiftCardConfigurationFactory implements GiftCardConfigurationFactoryInterface { - private FactoryInterface $decoratedFactory; - - private DefaultGiftCardTemplateContentProviderInterface $defaultGiftCardTemplateContentProvider; - - private string $defaultOrientation; - - private string $defaultPageSize; - - public function __construct( - FactoryInterface $decoratedFactory, - DefaultGiftCardTemplateContentProviderInterface $defaultGiftCardTemplateContentProvider, - string $defaultOrientation, - string $defaultPageSize, - ) { - $this->decoratedFactory = $decoratedFactory; - $this->defaultGiftCardTemplateContentProvider = $defaultGiftCardTemplateContentProvider; - $this->defaultOrientation = $defaultOrientation; - $this->defaultPageSize = $defaultPageSize; + public function __construct(private readonly FactoryInterface $decoratedFactory, private readonly DefaultGiftCardTemplateContentProviderInterface $defaultGiftCardTemplateContentProvider, private readonly string $defaultOrientation, private readonly string $defaultPageSize) + { } public function createNew(): GiftCardConfigurationInterface diff --git a/src/Fixture/Factory/GiftCardConfigurationExampleFactory.php b/src/Fixture/Factory/GiftCardConfigurationExampleFactory.php index 1fb08a61..eeecb0c4 100644 --- a/src/Fixture/Factory/GiftCardConfigurationExampleFactory.php +++ b/src/Fixture/Factory/GiftCardConfigurationExampleFactory.php @@ -18,31 +18,15 @@ class GiftCardConfigurationExampleFactory extends AbstractExampleFactory implements ExampleFactoryInterface { - protected RepositoryInterface $giftCardConfigurationRepository; - - protected GiftCardConfigurationFactoryInterface $giftCardConfigurationFactory; - - private FactoryInterface $imageFactory; - - private ImageUploaderInterface $imageUploader; - - private FileLocatorInterface $fileLocator; - protected OptionsResolver $optionsResolver; public function __construct( - RepositoryInterface $giftCardConfigurationRepository, - GiftCardConfigurationFactoryInterface $giftCardConfigurationFactory, - FactoryInterface $imageFactory, - ImageUploaderInterface $imageUploader, - FileLocatorInterface $fileLocator, + protected RepositoryInterface $giftCardConfigurationRepository, + protected GiftCardConfigurationFactoryInterface $giftCardConfigurationFactory, + private readonly FactoryInterface $imageFactory, + private readonly ImageUploaderInterface $imageUploader, + private readonly FileLocatorInterface $fileLocator, ) { - $this->giftCardConfigurationRepository = $giftCardConfigurationRepository; - $this->giftCardConfigurationFactory = $giftCardConfigurationFactory; - $this->imageFactory = $imageFactory; - $this->imageUploader = $imageUploader; - $this->fileLocator = $fileLocator; - $this->optionsResolver = new OptionsResolver(); $this->configureOptions($this->optionsResolver); diff --git a/src/Fixture/Factory/GiftCardExampleFactory.php b/src/Fixture/Factory/GiftCardExampleFactory.php index 795dbf59..f878eb0d 100644 --- a/src/Fixture/Factory/GiftCardExampleFactory.php +++ b/src/Fixture/Factory/GiftCardExampleFactory.php @@ -4,6 +4,8 @@ namespace Setono\SyliusGiftCardPlugin\Fixture\Factory; +use Faker\Factory; +use Faker\Generator; use Setono\SyliusGiftCardPlugin\Generator\GiftCardCodeGeneratorInterface; use Setono\SyliusGiftCardPlugin\Model\GiftCardInterface; use Setono\SyliusGiftCardPlugin\Repository\GiftCardRepositoryInterface; @@ -22,34 +24,18 @@ class GiftCardExampleFactory extends AbstractExampleFactory implements ExampleFactoryInterface { - protected GiftCardRepositoryInterface $giftCardRepository; - - protected FactoryInterface $giftCardFactory; - - protected GiftCardCodeGeneratorInterface $giftCardCodeGenerator; - - protected ChannelRepositoryInterface $channelRepository; - - protected RepositoryInterface $currencyRepository; - - protected \Faker\Generator $faker; + protected Generator $faker; protected OptionsResolver $optionsResolver; public function __construct( - GiftCardRepositoryInterface $giftCardRepository, - FactoryInterface $giftCardFactory, - GiftCardCodeGeneratorInterface $giftCardCodeGenerator, - ChannelRepositoryInterface $channelRepository, - RepositoryInterface $currencyRepository, + protected GiftCardRepositoryInterface $giftCardRepository, + protected FactoryInterface $giftCardFactory, + protected GiftCardCodeGeneratorInterface $giftCardCodeGenerator, + protected ChannelRepositoryInterface $channelRepository, + protected RepositoryInterface $currencyRepository, ) { - $this->giftCardRepository = $giftCardRepository; - $this->giftCardFactory = $giftCardFactory; - $this->giftCardCodeGenerator = $giftCardCodeGenerator; - $this->channelRepository = $channelRepository; - $this->currencyRepository = $currencyRepository; - - $this->faker = \Faker\Factory::create(); + $this->faker = Factory::create(); $this->optionsResolver = new OptionsResolver(); $this->configureOptions($this->optionsResolver); @@ -90,9 +76,7 @@ protected function createGiftCard(array $options): GiftCardInterface protected function configureOptions(OptionsResolver $resolver): void { $resolver - ->setDefault('code', function (Options $options): string { - return $this->giftCardCodeGenerator->generate(); - }) + ->setDefault('code', fn (Options $options): string => $this->giftCardCodeGenerator->generate()) ->setDefault('channel', LazyOption::randomOne($this->channelRepository)) ->setAllowedTypes('channel', ['null', 'string', ChannelInterface::class]) @@ -144,13 +128,9 @@ protected function configureOptions(OptionsResolver $resolver): void return $currency; }) - ->setDefault('amount', function (Options $options): int { - return $this->faker->randomElement([10, 20, 30, 40, 50, 75, 100, 150, 200, 250, 300, 400, 500]); - }) + ->setDefault('amount', fn (Options $options): int => $this->faker->randomElement([10, 20, 30, 40, 50, 75, 100, 150, 200, 250, 300, 400, 500])) ->setAllowedTypes('amount', ['float', 'int']) - ->setNormalizer('amount', function (Options $options, float $amount): int { - return (int) round($amount * 100); - }) + ->setNormalizer('amount', fn (Options $options, float $amount): int => (int) round($amount * 100)) ->setDefault('enabled', true) ->setAllowedTypes('enabled', 'bool') diff --git a/src/Form/DataTransformer/GiftCardToCodeDataTransformer.php b/src/Form/DataTransformer/GiftCardToCodeDataTransformer.php index 932312b8..a109f1d1 100644 --- a/src/Form/DataTransformer/GiftCardToCodeDataTransformer.php +++ b/src/Form/DataTransformer/GiftCardToCodeDataTransformer.php @@ -13,16 +13,8 @@ final class GiftCardToCodeDataTransformer implements DataTransformerInterface { - private GiftCardRepositoryInterface $giftCardRepository; - - private ChannelContextInterface $channelContext; - - public function __construct( - GiftCardRepositoryInterface $giftCardRepository, - ChannelContextInterface $channelContext, - ) { - $this->giftCardRepository = $giftCardRepository; - $this->channelContext = $channelContext; + public function __construct(private readonly GiftCardRepositoryInterface $giftCardRepository, private readonly ChannelContextInterface $channelContext) + { } /** @@ -54,7 +46,7 @@ public function reverseTransform($value): ?GiftCardInterface $this->channelContext->getChannel(), ); - if (null !== $giftCard) { + if ($giftCard instanceof GiftCardInterface) { return $giftCard; } diff --git a/src/Form/Extension/AddToCartTypeExtension.php b/src/Form/Extension/AddToCartTypeExtension.php index cfaebe80..fb7b10b5 100644 --- a/src/Form/Extension/AddToCartTypeExtension.php +++ b/src/Form/Extension/AddToCartTypeExtension.php @@ -19,16 +19,8 @@ final class AddToCartTypeExtension extends AbstractTypeExtension { - private GiftCardFactoryInterface $giftCardFactory; - - private EntityManagerInterface $giftCardManager; - - public function __construct( - GiftCardFactoryInterface $giftCardFactory, - EntityManagerInterface $giftCardManager, - ) { - $this->giftCardFactory = $giftCardFactory; - $this->giftCardManager = $giftCardManager; + public function __construct(private readonly GiftCardFactoryInterface $giftCardFactory, private readonly EntityManagerInterface $giftCardManager) + { } public static function getExtendedTypes(): iterable @@ -40,9 +32,9 @@ public static function getExtendedTypes(): iterable public function buildForm(FormBuilderInterface $builder, array $options): void { - $builder->addEventListener(FormEvents::PRE_SET_DATA, [$this, 'reworkFormForGiftCard']); + $builder->addEventListener(FormEvents::PRE_SET_DATA, $this->reworkFormForGiftCard(...)); - $builder->addEventListener(FormEvents::POST_SUBMIT, [$this, 'populateCartItem']); + $builder->addEventListener(FormEvents::POST_SUBMIT, $this->populateCartItem(...)); } public function reworkFormForGiftCard(FormEvent $event): void diff --git a/src/Form/Type/AddGiftCardToOrderType.php b/src/Form/Type/AddGiftCardToOrderType.php index 3e514d6f..52ef60fb 100644 --- a/src/Form/Type/AddGiftCardToOrderType.php +++ b/src/Form/Type/AddGiftCardToOrderType.php @@ -16,14 +16,8 @@ */ final class AddGiftCardToOrderType extends AbstractType { - private DataTransformerInterface $giftCardToCodeDataTransformer; - - private array $validationGroups; - - public function __construct(DataTransformerInterface $giftCardToCodeDataTransformer, array $validationGroups) + public function __construct(private readonly DataTransformerInterface $giftCardToCodeDataTransformer, private readonly array $validationGroups) { - $this->giftCardToCodeDataTransformer = $giftCardToCodeDataTransformer; - $this->validationGroups = $validationGroups; } public function buildForm(FormBuilderInterface $builder, array $options): void diff --git a/src/Form/Type/AddToCartGiftCardInformationType.php b/src/Form/Type/AddToCartGiftCardInformationType.php index 79291439..a7d75b8a 100644 --- a/src/Form/Type/AddToCartGiftCardInformationType.php +++ b/src/Form/Type/AddToCartGiftCardInformationType.php @@ -21,28 +21,8 @@ final class AddToCartGiftCardInformationType extends AbstractType { - private string $dataClass; - - private array $validationGroups; - - private CurrencyContextInterface $currencyContext; - - private ProductVariantResolverInterface $productVariantResolver; - - private ChannelContextInterface $channelContext; - - public function __construct( - string $dataClass, - array $validationGroups, - CurrencyContextInterface $currencyContext, - ProductVariantResolverInterface $productVariantResolver, - ChannelContextInterface $channelContext, - ) { - $this->dataClass = $dataClass; - $this->validationGroups = $validationGroups; - $this->currencyContext = $currencyContext; - $this->productVariantResolver = $productVariantResolver; - $this->channelContext = $channelContext; + public function __construct(private readonly string $dataClass, private readonly array $validationGroups, private readonly CurrencyContextInterface $currencyContext, private readonly ProductVariantResolverInterface $productVariantResolver, private readonly ChannelContextInterface $channelContext) + { } public function buildForm(FormBuilderInterface $builder, array $options): void diff --git a/src/Form/Type/CustomerAutocompleteChoiceType.php b/src/Form/Type/CustomerAutocompleteChoiceType.php index 25dd5d51..d2231fb6 100644 --- a/src/Form/Type/CustomerAutocompleteChoiceType.php +++ b/src/Form/Type/CustomerAutocompleteChoiceType.php @@ -13,11 +13,8 @@ final class CustomerAutocompleteChoiceType extends AbstractType { - private UrlGeneratorInterface $urlGenerator; - - public function __construct(UrlGeneratorInterface $urlGenerator) + public function __construct(private readonly UrlGeneratorInterface $urlGenerator) { - $this->urlGenerator = $urlGenerator; } public function configureOptions(OptionsResolver $resolver): void diff --git a/src/Form/Type/DatePeriodType.php b/src/Form/Type/DatePeriodType.php index cf9dc367..6099f0de 100644 --- a/src/Form/Type/DatePeriodType.php +++ b/src/Form/Type/DatePeriodType.php @@ -12,11 +12,8 @@ final class DatePeriodType extends AbstractType { - private DatePeriodUnitProviderInterface $datePeriodUnitProvider; - - public function __construct(DatePeriodUnitProviderInterface $datePeriodUnitProvider) + public function __construct(private readonly DatePeriodUnitProviderInterface $datePeriodUnitProvider) { - $this->datePeriodUnitProvider = $datePeriodUnitProvider; } public function buildForm(FormBuilderInterface $builder, array $options): void @@ -27,9 +24,7 @@ public function buildForm(FormBuilderInterface $builder, array $options): void $builder->add('unit', ChoiceType::class, [ 'label' => 'setono_sylius_gift_card.form.date_period.unit', 'choices' => $this->datePeriodUnitProvider->getPeriodUnits(), - 'choice_label' => function (string $choice): string { - return \sprintf('setono_sylius_gift_card.form.date_period.unit_%s', $choice); - }, + 'choice_label' => fn (string $choice): string => \sprintf('setono_sylius_gift_card.form.date_period.unit_%s', $choice), ]); } } diff --git a/src/Form/Type/GiftCardConfigurationType.php b/src/Form/Type/GiftCardConfigurationType.php index bc58f366..84d8fe45 100644 --- a/src/Form/Type/GiftCardConfigurationType.php +++ b/src/Form/Type/GiftCardConfigurationType.php @@ -15,15 +15,6 @@ final class GiftCardConfigurationType extends AbstractResourceType { - /** @var list */ - private array $availableOrientations; - - /** @var list */ - private array $availablePageSizes; - - /** @var list */ - private array $preferredPageSizes; - /** * @param list $availableOrientations * @param list $availablePageSizes @@ -31,17 +22,13 @@ final class GiftCardConfigurationType extends AbstractResourceType * @param list $validationGroups */ public function __construct( - array $availableOrientations, - array $availablePageSizes, - array $preferredPageSizes, + private readonly array $availableOrientations, + private readonly array $availablePageSizes, + private readonly array $preferredPageSizes, string $dataClass, array $validationGroups = [], ) { parent::__construct($dataClass, $validationGroups); - - $this->availableOrientations = $availableOrientations; - $this->availablePageSizes = $availablePageSizes; - $this->preferredPageSizes = $preferredPageSizes; } public function buildForm(FormBuilderInterface $builder, array $options): void @@ -78,17 +65,13 @@ public function buildForm(FormBuilderInterface $builder, array $options): void 'preferred_choices' => $this->preferredPageSizes, 'label' => 'setono_sylius_gift_card.form.gift_card_configuration.page_size', 'choice_translation_domain' => false, - 'choice_label' => function (string $value) { - return $value; - }, + 'choice_label' => fn (string $value) => $value, ]); $builder->add('orientation', ChoiceType::class, [ 'choices' => $this->availableOrientations, 'label' => 'setono_sylius_gift_card.form.gift_card_configuration.orientation', 'choice_translation_domain' => false, - 'choice_label' => function (string $value) { - return $value; - }, + 'choice_label' => fn (string $value) => $value, ]); $builder->add('template', TextareaType::class, [ 'label' => 'setono_sylius_gift_card.form.gift_card_configuration.template', diff --git a/src/Form/Type/GiftCardSearchType.php b/src/Form/Type/GiftCardSearchType.php index a4c84ee4..247c2f00 100644 --- a/src/Form/Type/GiftCardSearchType.php +++ b/src/Form/Type/GiftCardSearchType.php @@ -13,14 +13,8 @@ final class GiftCardSearchType extends AbstractType { - private DataTransformerInterface $giftCardToCodeDataTransformer; - - private array $validationGroups; - - public function __construct(DataTransformerInterface $giftCardToCodeDataTransformer, array $validationGroups) + public function __construct(private readonly DataTransformerInterface $giftCardToCodeDataTransformer, private readonly array $validationGroups) { - $this->giftCardToCodeDataTransformer = $giftCardToCodeDataTransformer; - $this->validationGroups = $validationGroups; } public function buildForm(FormBuilderInterface $builder, array $options): void diff --git a/src/Form/Type/GiftCardType.php b/src/Form/Type/GiftCardType.php index 9557acfa..bac9e459 100644 --- a/src/Form/Type/GiftCardType.php +++ b/src/Form/Type/GiftCardType.php @@ -23,23 +23,16 @@ final class GiftCardType extends AbstractResourceType { - private RepositoryInterface $currencyRepository; - - private GiftCardCodeGeneratorInterface $giftCardCodeGenerator; - /** * @param list $validationGroups */ public function __construct( string $dataClass, - RepositoryInterface $currencyRepository, - GiftCardCodeGeneratorInterface $giftCardCodeGenerator, + private readonly RepositoryInterface $currencyRepository, + private readonly GiftCardCodeGeneratorInterface $giftCardCodeGenerator, array $validationGroups = [], ) { parent::__construct($dataClass, $validationGroups); - - $this->currencyRepository = $currencyRepository; - $this->giftCardCodeGenerator = $giftCardCodeGenerator; } public function buildForm(FormBuilderInterface $builder, array $options): void diff --git a/src/Generator/GiftCardCodeGenerator.php b/src/Generator/GiftCardCodeGenerator.php index 8ec1baaf..61df4f85 100644 --- a/src/Generator/GiftCardCodeGenerator.php +++ b/src/Generator/GiftCardCodeGenerator.php @@ -5,24 +5,21 @@ namespace Setono\SyliusGiftCardPlugin\Generator; use function preg_replace; +use Setono\SyliusGiftCardPlugin\Model\GiftCardInterface; use Setono\SyliusGiftCardPlugin\Repository\GiftCardRepositoryInterface; use Webmozart\Assert\Assert; final class GiftCardCodeGenerator implements GiftCardCodeGeneratorInterface { - private GiftCardRepositoryInterface $giftCardRepository; - /** @var positive-int */ - private int $codeLength; + private readonly int $codeLength; /** * @param positive-int $codeLength */ - public function __construct(GiftCardRepositoryInterface $giftCardRepository, int $codeLength) + public function __construct(private readonly GiftCardRepositoryInterface $giftCardRepository, int $codeLength) { Assert::greaterThan($codeLength, 0); - - $this->giftCardRepository = $giftCardRepository; $this->codeLength = $codeLength; } @@ -34,7 +31,7 @@ public function generate(): string /** @psalm-suppress ArgumentTypeCoercion */ $code = bin2hex(random_bytes($this->codeLength)); $code = preg_replace('/[01]/', '', $code); // remove hard to read characters - $code = mb_strtoupper(mb_substr($code, 0, $this->codeLength)); + $code = mb_strtoupper(mb_substr((string) $code, 0, $this->codeLength)); } while (mb_strlen($code) !== $this->codeLength || $this->exists($code)); return $code; @@ -42,6 +39,6 @@ public function generate(): string private function exists(string $code): bool { - return null !== $this->giftCardRepository->findOneByCode($code); + return $this->giftCardRepository->findOneByCode($code) instanceof GiftCardInterface; } } diff --git a/src/Grid/FieldTypes/StringFieldType.php b/src/Grid/FieldTypes/StringFieldType.php index 56876464..2a07b7c8 100644 --- a/src/Grid/FieldTypes/StringFieldType.php +++ b/src/Grid/FieldTypes/StringFieldType.php @@ -14,11 +14,8 @@ final class StringFieldType implements FieldTypeInterface { - private PropertyAccessorInterface $propertyAccessor; - - public function __construct(PropertyAccessorInterface $propertyAccessor) + public function __construct(private readonly PropertyAccessorInterface $propertyAccessor) { - $this->propertyAccessor = $propertyAccessor; } public function render(Field $field, $data, array $options): string @@ -30,8 +27,8 @@ public function render(Field $field, $data, array $options): string /** @var mixed $value */ $value = $this->propertyAccessor->getValue($data, $field->getPath()); - Assert::true(self::isStringable($value)); - } catch (Throwable $e) { + Assert::true($this->isStringable($value)); + } catch (Throwable) { return ''; } @@ -43,11 +40,9 @@ public function configureOptions(OptionsResolver $resolver): void } /** - * @param mixed $value - * * @psalm-assert-if-true null|scalar|object $value */ - private static function isStringable($value): bool + private function isStringable(mixed $value): bool { return $value === null || is_scalar($value) || (is_object($value) && method_exists($value, '__toString')); } diff --git a/src/Model/GiftCard.php b/src/Model/GiftCard.php index 9bbf37b2..2491a171 100644 --- a/src/Model/GiftCard.php +++ b/src/Model/GiftCard.php @@ -77,7 +77,7 @@ public function getId(): ?int public function isDeletable(): bool { - return null === $this->orderItemUnit; + return !$this->orderItemUnit instanceof OrderItemUnitInterface; } public function getOrderItemUnit(): ?OrderItemUnitInterface @@ -99,7 +99,7 @@ public function setOrderItemUnit(OrderItemUnitInterface $orderItemUnit): void public function getOrder(): ?OrderInterface { $orderItemUnit = $this->getOrderItemUnit(); - if (null === $orderItemUnit) { + if (!$orderItemUnit instanceof OrderItemUnitInterface) { return null; } @@ -216,7 +216,7 @@ public function setChannel(ChannelInterface $channel): void public function getCustomerIdentification(): ?array { $customer = $this->getCustomer(); - if (null === $customer) { + if (!$customer instanceof CustomerInterface) { return null; } @@ -229,7 +229,7 @@ public function getCustomerIdentification(): ?array public function getOrderIdentification(): ?array { $order = $this->getOrder(); - if (null === $order) { + if (!$order instanceof OrderInterface) { return null; } @@ -250,7 +250,7 @@ public function getOrderIdentification(): ?array public function getChannelCode(): ?string { $channel = $this->getChannel(); - if (null === $channel) { + if (!$channel instanceof ChannelInterface) { return null; } @@ -259,7 +259,7 @@ public function getChannelCode(): ?string public function hasOrderOrCustomer(): bool { - return null !== $this->getCustomer() || null !== $this->getOrder(); + return $this->getCustomer() instanceof CustomerInterface || $this->getOrder() instanceof OrderInterface; } public function getCustomMessage(): ?string @@ -294,12 +294,12 @@ public function setExpiresAt(?DateTimeInterface $expiresAt): void public function isExpired(DateTimeInterface $date = null): bool { - if (null === $date) { + if (!$date instanceof DateTimeInterface) { $date = new DateTime(); } $giftCardValidUntil = $this->getExpiresAt(); - if (null === $giftCardValidUntil) { + if (!$giftCardValidUntil instanceof DateTimeInterface) { return false; } diff --git a/src/Model/GiftCardBalance.php b/src/Model/GiftCardBalance.php index 083ae4ce..48781019 100644 --- a/src/Model/GiftCardBalance.php +++ b/src/Model/GiftCardBalance.php @@ -6,15 +6,12 @@ final class GiftCardBalance { - private string $currencyCode; - private int $count = 0; private int $total = 0; - public function __construct(string $currencyCode) + public function __construct(private readonly string $currencyCode) { - $this->currencyCode = $currencyCode; } public function add(int $amount): void diff --git a/src/Model/GiftCardConfiguration.php b/src/Model/GiftCardConfiguration.php index 48bb2322..04a7fb10 100644 --- a/src/Model/GiftCardConfiguration.php +++ b/src/Model/GiftCardConfiguration.php @@ -69,9 +69,7 @@ public function getImages(): Collection public function getImagesByType(string $type): Collection { - return $this->images->filter(function (ImageInterface $image) use ($type): bool { - return $image->getType() === $type; - }); + return $this->images->filter(fn (ImageInterface $image): bool => $image->getType() === $type); } public function hasImages(): bool @@ -116,11 +114,11 @@ public function getBackgroundImage(): ?GiftCardConfigurationImageInterface public function setBackgroundImage(?GiftCardConfigurationImageInterface $image): void { $actualImage = $this->getBackgroundImage(); - if (null !== $actualImage) { + if ($actualImage instanceof GiftCardConfigurationImageInterface) { $this->removeImage($actualImage); } - if (null === $image) { + if (!$image instanceof GiftCardConfigurationImageInterface) { return; } diff --git a/src/Model/GiftCardInterface.php b/src/Model/GiftCardInterface.php index 770dde2e..26ead5d5 100644 --- a/src/Model/GiftCardInterface.php +++ b/src/Model/GiftCardInterface.php @@ -4,6 +4,7 @@ namespace Setono\SyliusGiftCardPlugin\Model; +use DateTimeInterface; use Doctrine\Common\Collections\Collection; use Sylius\Component\Core\Model\ChannelInterface; use Sylius\Component\Core\Model\CustomerInterface; @@ -123,11 +124,11 @@ public function setOrigin(?string $origin): void; public function getOrigin(): ?string; - public function getExpiresAt(): ?\DateTimeInterface; + public function getExpiresAt(): ?DateTimeInterface; - public function setExpiresAt(?\DateTimeInterface $expiresAt): void; + public function setExpiresAt(?DateTimeInterface $expiresAt): void; - public function isExpired(\DateTimeInterface $date = null): bool; + public function isExpired(DateTimeInterface $date = null): bool; public function getSendNotificationEmail(): bool; diff --git a/src/Modifier/OrderGiftCardAmountModifier.php b/src/Modifier/OrderGiftCardAmountModifier.php index c7a2ff53..1d630e17 100644 --- a/src/Modifier/OrderGiftCardAmountModifier.php +++ b/src/Modifier/OrderGiftCardAmountModifier.php @@ -16,17 +16,14 @@ */ final class OrderGiftCardAmountModifier implements OrderGiftCardAmountModifierInterface { - private ObjectManager $giftCardManager; - - public function __construct(ObjectManager $giftCardManager) + public function __construct(private readonly ObjectManager $giftCardManager) { - $this->giftCardManager = $giftCardManager; } public function decrement(OrderInterface $order): void { foreach ($order->getAdjustments(AdjustmentInterface::ORDER_GIFT_CARD_ADJUSTMENT) as $adjustment) { - $giftCard = self::getGiftCard($order, (string) $adjustment->getOriginCode()); + $giftCard = $this->getGiftCard($order, (string) $adjustment->getOriginCode()); $amount = abs($adjustment->getAmount()); @@ -48,7 +45,7 @@ public function decrement(OrderInterface $order): void public function increment(OrderInterface $order): void { foreach ($order->getAdjustments(AdjustmentInterface::ORDER_GIFT_CARD_ADJUSTMENT) as $adjustment) { - $giftCard = self::getGiftCard($order, (string) $adjustment->getOriginCode()); + $giftCard = $this->getGiftCard($order, (string) $adjustment->getOriginCode()); $giftCard->setAmount($giftCard->getAmount() + abs($adjustment->getAmount())); @@ -60,7 +57,7 @@ public function increment(OrderInterface $order): void $this->giftCardManager->flush(); } - private static function getGiftCard(OrderInterface $order, string $code): GiftCardInterface + private function getGiftCard(OrderInterface $order, string $code): GiftCardInterface { foreach ($order->getGiftCards() as $giftCard) { if ($giftCard->getCode() === $code) { diff --git a/src/Operator/OrderGiftCardOperator.php b/src/Operator/OrderGiftCardOperator.php index 5cdc3a2e..21403808 100644 --- a/src/Operator/OrderGiftCardOperator.php +++ b/src/Operator/OrderGiftCardOperator.php @@ -21,21 +21,13 @@ */ final class OrderGiftCardOperator implements OrderGiftCardOperatorInterface { - private EntityManagerInterface $giftCardManager; - - private GiftCardEmailManagerInterface $giftCardOrderEmailManager; - - public function __construct( - EntityManagerInterface $giftCardManager, - GiftCardEmailManagerInterface $giftCardOrderEmailManager, - ) { - $this->giftCardManager = $giftCardManager; - $this->giftCardOrderEmailManager = $giftCardOrderEmailManager; + public function __construct(private readonly EntityManagerInterface $giftCardManager, private readonly GiftCardEmailManagerInterface $giftCardOrderEmailManager) + { } public function associateToCustomer(OrderInterface $order): void { - $items = self::getOrderItemsThatAreGiftCards($order); + $items = $this->getOrderItemsThatAreGiftCards($order); if (count($items) === 0) { return; @@ -62,7 +54,7 @@ public function enable(OrderInterface $order): void { $giftCards = $this->getGiftCards($order); - if (count($giftCards) === 0) { + if ($giftCards === []) { return; } @@ -81,7 +73,7 @@ public function disable(OrderInterface $order): void { $giftCards = $this->getGiftCards($order); - if (count($giftCards) === 0) { + if ($giftCards === []) { return; } @@ -96,7 +88,7 @@ public function send(OrderInterface $order): void { $giftCards = $this->getGiftCards($order); - if (count($giftCards) === 0) { + if ($giftCards === []) { return; } @@ -112,7 +104,7 @@ private function getGiftCards(OrderInterface $order): array { $giftCards = []; - $items = self::getOrderItemsThatAreGiftCards($order); + $items = $this->getOrderItemsThatAreGiftCards($order); foreach ($items as $item) { /** @var OrderItemUnitInterface $unit */ foreach ($item->getUnits() as $unit) { @@ -131,7 +123,7 @@ private function getGiftCards(OrderInterface $order): array /** * @return Collection */ - private static function getOrderItemsThatAreGiftCards(OrderInterface $order): Collection + private function getOrderItemsThatAreGiftCards(OrderInterface $order): Collection { return $order->getItems()->filter(static function (OrderItemInterface $item): bool { /** @var ProductInterface|null $product */ diff --git a/src/Order/AddToCartCommand.php b/src/Order/AddToCartCommand.php index 6a815e46..27553bfc 100644 --- a/src/Order/AddToCartCommand.php +++ b/src/Order/AddToCartCommand.php @@ -9,20 +9,8 @@ class AddToCartCommand implements AddToCartCommandInterface { - protected OrderInterface $cart; - - protected OrderItemInterface $cartItem; - - protected GiftCardInformationInterface $giftCardInformation; - - public function __construct( - OrderInterface $cart, - OrderItemInterface $cartItem, - GiftCardInformationInterface $giftCardInformation, - ) { - $this->cart = $cart; - $this->cartItem = $cartItem; - $this->giftCardInformation = $giftCardInformation; + public function __construct(protected OrderInterface $cart, protected OrderItemInterface $cartItem, protected GiftCardInformationInterface $giftCardInformation) + { } public function getCart(): OrderInterface diff --git a/src/Order/Factory/AddToCartCommandFactory.php b/src/Order/Factory/AddToCartCommandFactory.php index b257073b..3e8c13b4 100644 --- a/src/Order/Factory/AddToCartCommandFactory.php +++ b/src/Order/Factory/AddToCartCommandFactory.php @@ -11,20 +11,11 @@ final class AddToCartCommandFactory implements AddToCartCommandFactoryInterface { - /** @var class-string */ - private string $className; - - private GiftCardInformationFactoryInterface $giftCardInformationFactory; - /** * @param class-string $className */ - public function __construct( - string $className, - GiftCardInformationFactoryInterface $giftCardInformationFactory, - ) { - $this->className = $className; - $this->giftCardInformationFactory = $giftCardInformationFactory; + public function __construct(private readonly string $className, private readonly GiftCardInformationFactoryInterface $giftCardInformationFactory) + { } public function createWithCartAndCartItem(OrderInterface $cart, OrderItemInterface $cartItem): AddToCartCommandInterface diff --git a/src/Order/Factory/GiftCardInformationFactory.php b/src/Order/Factory/GiftCardInformationFactory.php index 5275433b..af48bc52 100644 --- a/src/Order/Factory/GiftCardInformationFactory.php +++ b/src/Order/Factory/GiftCardInformationFactory.php @@ -9,15 +9,11 @@ final class GiftCardInformationFactory implements GiftCardInformationFactoryInterface { - /** @var class-string */ - private string $className; - /** * @param class-string $className */ - public function __construct(string $className) + public function __construct(private readonly string $className) { - $this->className = $className; } public function createNew(OrderItemInterface $orderItem): GiftCardInformationInterface diff --git a/src/Order/GiftCardInformation.php b/src/Order/GiftCardInformation.php index 5d260746..cfa43115 100644 --- a/src/Order/GiftCardInformation.php +++ b/src/Order/GiftCardInformation.php @@ -6,14 +6,8 @@ class GiftCardInformation implements GiftCardInformationInterface { - protected int $amount; - - protected ?string $customMessage; - - public function __construct(int $amount, string $customMessage = null) + public function __construct(protected int $amount, protected ?string $customMessage = null) { - $this->amount = $amount; - $this->customMessage = $customMessage; } public function getAmount(): int diff --git a/src/OrderProcessor/OrderGiftCardProcessor.php b/src/OrderProcessor/OrderGiftCardProcessor.php index f31ff588..626f9a41 100644 --- a/src/OrderProcessor/OrderGiftCardProcessor.php +++ b/src/OrderProcessor/OrderGiftCardProcessor.php @@ -15,20 +15,8 @@ final class OrderGiftCardProcessor implements OrderProcessorInterface { - private TranslatorInterface $translator; - - private AdjustmentFactoryInterface $adjustmentFactory; - - private OrderEligibleTotalProviderInterface $orderEligibleTotalProvider; - - public function __construct( - TranslatorInterface $translator, - AdjustmentFactoryInterface $adjustmentFactory, - OrderEligibleTotalProviderInterface $orderEligibleTotalProvider, - ) { - $this->translator = $translator; - $this->adjustmentFactory = $adjustmentFactory; - $this->orderEligibleTotalProvider = $orderEligibleTotalProvider; + public function __construct(private readonly TranslatorInterface $translator, private readonly AdjustmentFactoryInterface $adjustmentFactory, private readonly OrderEligibleTotalProviderInterface $orderEligibleTotalProvider) + { } /** diff --git a/src/Provider/GiftCardConfigurationProvider.php b/src/Provider/GiftCardConfigurationProvider.php index d0c71d85..63ad379f 100644 --- a/src/Provider/GiftCardConfigurationProvider.php +++ b/src/Provider/GiftCardConfigurationProvider.php @@ -23,37 +23,25 @@ final class GiftCardConfigurationProvider implements GiftCardConfigurationProvid { use ORMManagerTrait; - private GiftCardConfigurationRepositoryInterface $giftCardConfigurationRepository; - - private GiftCardConfigurationFactoryInterface $giftCardConfigurationFactory; - - private LocaleContextInterface $localeContext; - - private RepositoryInterface $localeRepository; - public function __construct( - GiftCardConfigurationRepositoryInterface $giftCardConfigurationRepository, - GiftCardConfigurationFactoryInterface $giftCardConfigurationFactory, - LocaleContextInterface $localeContext, - RepositoryInterface $localeRepository, + private GiftCardConfigurationRepositoryInterface $giftCardConfigurationRepository, + private GiftCardConfigurationFactoryInterface $giftCardConfigurationFactory, + private LocaleContextInterface $localeContext, + private RepositoryInterface $localeRepository, ManagerRegistry $managerRegistry, ) { - $this->giftCardConfigurationRepository = $giftCardConfigurationRepository; - $this->giftCardConfigurationFactory = $giftCardConfigurationFactory; - $this->localeContext = $localeContext; - $this->localeRepository = $localeRepository; $this->managerRegistry = $managerRegistry; } public function getConfiguration(BaseChannelInterface $channel, LocaleInterface $locale): GiftCardConfigurationInterface { $configuration = $this->giftCardConfigurationRepository->findOneByChannelAndLocale($channel, $locale); - if (null !== $configuration) { + if ($configuration instanceof GiftCardConfigurationInterface) { return $configuration; } $configuration = $this->giftCardConfigurationRepository->findDefault(); - if (null !== $configuration) { + if ($configuration instanceof GiftCardConfigurationInterface) { return $configuration; } @@ -77,16 +65,12 @@ public function getConfigurationForGiftCard(GiftCardInterface $giftCard): GiftCa try { $order = $giftCard->getOrder(); - if ($order instanceof OrderInterface) { - $localeCode = $order->getLocaleCode(); - } else { - $localeCode = $this->localeContext->getLocaleCode(); - } + $localeCode = $order instanceof OrderInterface ? $order->getLocaleCode() : $this->localeContext->getLocaleCode(); $locale = $this->localeRepository->findOneBy(['code' => $localeCode]); if (!$locale instanceof LocaleInterface) { throw new LocaleNotFoundException(); } - } catch (LocaleNotFoundException $exception) { + } catch (LocaleNotFoundException) { $locale = $channel->getDefaultLocale(); } diff --git a/src/Renderer/PdfRenderer.php b/src/Renderer/PdfRenderer.php index 06e6b7cf..e92a0be2 100644 --- a/src/Renderer/PdfRenderer.php +++ b/src/Renderer/PdfRenderer.php @@ -11,6 +11,7 @@ use Setono\SyliusGiftCardPlugin\Provider\PdfRenderingOptionsProviderInterface; use Sylius\Component\Channel\Context\ChannelContextInterface; use Sylius\Component\Channel\Model\ChannelInterface; +use Sylius\Component\Core\Model\OrderInterface; use Sylius\Component\Locale\Context\LocaleContextInterface; use Symfony\Component\Serializer\Normalizer\NormalizerInterface; use Twig\Environment; @@ -18,36 +19,8 @@ final class PdfRenderer implements PdfRendererInterface { - private Environment $twig; - - private GiftCardConfigurationProviderInterface $configurationProvider; - - private ChannelContextInterface $channelContext; - - private LocaleContextInterface $localeContext; - - private GeneratorInterface $snappy; - - private PdfRenderingOptionsProviderInterface $renderingOptionsProvider; - - private NormalizerInterface $normalizer; - - public function __construct( - Environment $twig, - GiftCardConfigurationProviderInterface $configurationProvider, - ChannelContextInterface $channelContext, - LocaleContextInterface $localeContext, - GeneratorInterface $snappy, - PdfRenderingOptionsProviderInterface $renderingOptionsProvider, - NormalizerInterface $normalizer, - ) { - $this->twig = $twig; - $this->configurationProvider = $configurationProvider; - $this->channelContext = $channelContext; - $this->localeContext = $localeContext; - $this->snappy = $snappy; - $this->renderingOptionsProvider = $renderingOptionsProvider; - $this->normalizer = $normalizer; + public function __construct(private readonly Environment $twig, private readonly GiftCardConfigurationProviderInterface $configurationProvider, private readonly ChannelContextInterface $channelContext, private readonly LocaleContextInterface $localeContext, private readonly GeneratorInterface $snappy, private readonly PdfRenderingOptionsProviderInterface $renderingOptionsProvider, private readonly NormalizerInterface $normalizer) + { } public function render( @@ -56,20 +29,20 @@ public function render( ChannelInterface $channel = null, string $localeCode = null, ): PdfResponse { - if (null === $channel) { + if (!$channel instanceof ChannelInterface) { $order = $giftCard->getOrder(); - if (null !== $order) { + if ($order instanceof OrderInterface) { $channel = $order->getChannel(); } - if (null === $channel) { + if (!$channel instanceof ChannelInterface) { $channel = $this->channelContext->getChannel(); } } if (null === $localeCode) { $order = $giftCard->getOrder(); - if (null !== $order) { + if ($order instanceof OrderInterface) { $localeCode = $order->getLocaleCode(); } @@ -78,7 +51,7 @@ public function render( } } - if (null === $giftCardConfiguration) { + if (!$giftCardConfiguration instanceof GiftCardConfigurationInterface) { $giftCardConfiguration = $this->configurationProvider->getConfigurationForGiftCard($giftCard); } diff --git a/src/Resolver/CustomerChannelResolver.php b/src/Resolver/CustomerChannelResolver.php index 559135ce..7b347aab 100644 --- a/src/Resolver/CustomerChannelResolver.php +++ b/src/Resolver/CustomerChannelResolver.php @@ -4,6 +4,8 @@ namespace Setono\SyliusGiftCardPlugin\Resolver; +use RuntimeException; +use Setono\SyliusGiftCardPlugin\Model\OrderInterface; use Setono\SyliusGiftCardPlugin\Repository\OrderRepositoryInterface; use Sylius\Component\Channel\Repository\ChannelRepositoryInterface; use Sylius\Component\Core\Model\ChannelInterface; @@ -11,24 +13,16 @@ final class CustomerChannelResolver implements CustomerChannelResolverInterface { - private OrderRepositoryInterface $orderRepository; - - private ChannelRepositoryInterface $channelRepository; - - public function __construct( - OrderRepositoryInterface $orderRepository, - ChannelRepositoryInterface $channelRepository, - ) { - $this->orderRepository = $orderRepository; - $this->channelRepository = $channelRepository; + public function __construct(private readonly OrderRepositoryInterface $orderRepository, private readonly ChannelRepositoryInterface $channelRepository) + { } public function resolve(CustomerInterface $customer): ChannelInterface { $latestOrder = $this->orderRepository->findLatestByCustomer($customer); - if (null !== $latestOrder) { + if ($latestOrder instanceof OrderInterface) { $channel = $latestOrder->getChannel(); - if (null !== $channel) { + if ($channel instanceof \Sylius\Component\Channel\Model\ChannelInterface) { return $channel; } } @@ -39,7 +33,7 @@ public function resolve(CustomerInterface $customer): ChannelInterface ]); if (null === $channel) { - throw new \RuntimeException('There are no enabled channels'); + throw new RuntimeException('There are no enabled channels'); } return $channel; diff --git a/src/Resolver/LocaleResolver.php b/src/Resolver/LocaleResolver.php index 602c6949..95992623 100644 --- a/src/Resolver/LocaleResolver.php +++ b/src/Resolver/LocaleResolver.php @@ -4,30 +4,24 @@ namespace Setono\SyliusGiftCardPlugin\Resolver; +use RuntimeException; use Setono\SyliusGiftCardPlugin\Repository\OrderRepositoryInterface; use Sylius\Component\Channel\Repository\ChannelRepositoryInterface; use Sylius\Component\Core\Model\ChannelInterface; use Sylius\Component\Core\Model\CustomerInterface; use Sylius\Component\Core\Model\OrderInterface; +use Sylius\Component\Locale\Model\LocaleInterface; final class LocaleResolver implements LocaleResolverInterface { - private OrderRepositoryInterface $orderRepository; - - private ChannelRepositoryInterface $channelRepository; - - public function __construct( - OrderRepositoryInterface $orderRepository, - ChannelRepositoryInterface $channelRepository, - ) { - $this->orderRepository = $orderRepository; - $this->channelRepository = $channelRepository; + public function __construct(private readonly OrderRepositoryInterface $orderRepository, private readonly ChannelRepositoryInterface $channelRepository) + { } public function resolveFromCustomer(CustomerInterface $customer): string { $latestOrder = $this->orderRepository->findLatestByCustomer($customer); - if (null !== $latestOrder) { + if ($latestOrder instanceof \Setono\SyliusGiftCardPlugin\Model\OrderInterface) { return $this->resolveFromOrder($latestOrder); } @@ -42,7 +36,7 @@ public function resolveFromOrder(OrderInterface $order): string } $channel = $order->getChannel(); - if (null !== $channel) { + if ($channel instanceof \Sylius\Component\Channel\Model\ChannelInterface) { return $this->resolveFromChannel($channel); } @@ -71,13 +65,13 @@ private function resolve(): string } } - throw new \RuntimeException('Could not resolve a locale'); + throw new RuntimeException('Could not resolve a locale'); } private function _resolveFromChannel(ChannelInterface $channel): ?string { $locale = $channel->getDefaultLocale(); - if (null !== $locale) { + if ($locale instanceof LocaleInterface) { $localeCode = $locale->getCode(); if (null !== $localeCode) { return $localeCode; diff --git a/src/Resolver/RedirectUrlResolver.php b/src/Resolver/RedirectUrlResolver.php index a478b70c..35f73215 100644 --- a/src/Resolver/RedirectUrlResolver.php +++ b/src/Resolver/RedirectUrlResolver.php @@ -11,11 +11,8 @@ final class RedirectUrlResolver implements RedirectUrlResolverInterface { - private UrlGeneratorInterface $router; - - public function __construct(UrlGeneratorInterface $router) + public function __construct(private readonly UrlGeneratorInterface $router) { - $this->router = $router; } public function getUrlToRedirectTo(Request $request, string $defaultRoute): string diff --git a/src/Security/GiftCardVoter.php b/src/Security/GiftCardVoter.php index cc3d293d..1f0aee9b 100644 --- a/src/Security/GiftCardVoter.php +++ b/src/Security/GiftCardVoter.php @@ -7,6 +7,7 @@ use LogicException; use Setono\SyliusGiftCardPlugin\Model\GiftCardInterface; use Sylius\Component\Core\Model\AdminUserInterface; +use Sylius\Component\Core\Model\CustomerInterface; use Sylius\Component\Core\Model\ShopUserInterface; use Sylius\Component\User\Model\UserInterface; use Symfony\Component\Security\Core\Authentication\Token\TokenInterface; @@ -23,11 +24,7 @@ protected function supports(string $attribute, mixed $subject): bool return false; } - if (!$subject instanceof GiftCardInterface) { - return false; - } - - return true; + return $subject instanceof GiftCardInterface; } protected function voteOnAttribute(string $attribute, mixed $subject, TokenInterface $token): bool @@ -55,7 +52,7 @@ protected function voteOnAttribute(string $attribute, mixed $subject, TokenInter private function canRead(GiftCardInterface $giftCard, ShopUserInterface $user): bool { // Anonymous gift cards can be seen by everyone - if (null === $giftCard->getCustomer()) { + if (!$giftCard->getCustomer() instanceof CustomerInterface) { return true; } diff --git a/src/Serializer/Normalizer/GiftCardConfigurationNormalizer.php b/src/Serializer/Normalizer/GiftCardConfigurationNormalizer.php index 042630ba..27591c27 100644 --- a/src/Serializer/Normalizer/GiftCardConfigurationNormalizer.php +++ b/src/Serializer/Normalizer/GiftCardConfigurationNormalizer.php @@ -6,7 +6,9 @@ use ArrayObject; use Setono\SyliusGiftCardPlugin\Exception\UnexpectedTypeException; +use Setono\SyliusGiftCardPlugin\Model\GiftCardConfigurationImageInterface; use Setono\SyliusGiftCardPlugin\Model\GiftCardConfigurationInterface; +use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\RequestStack; use Symfony\Component\Serializer\Normalizer\ContextAwareNormalizerInterface; use Symfony\Component\Serializer\Normalizer\ObjectNormalizer; @@ -14,19 +16,13 @@ final class GiftCardConfigurationNormalizer implements ContextAwareNormalizerInterface { - private ObjectNormalizer $objectNormalizer; - - private RequestStack $requestStack; - - private string $publicMediaDirectory; + private readonly string $publicMediaDirectory; public function __construct( - ObjectNormalizer $objectNormalizer, - RequestStack $requestStack, + private readonly ObjectNormalizer $objectNormalizer, + private readonly RequestStack $requestStack, string $publicMediaDirectory, ) { - $this->objectNormalizer = $objectNormalizer; - $this->requestStack = $requestStack; $this->publicMediaDirectory = trim($publicMediaDirectory, '/'); } @@ -50,17 +46,17 @@ public function normalize($object, $format = null, array $context = []): array $data['image'] = ''; $request = $this->requestStack->getMainRequest(); - if (null !== $request) { + if ($request instanceof Request) { $data['image'] = $request->getSchemeAndHttpHost() . '/bundles/setonosyliusgiftcardplugin/setono-logo.png'; } $image = $object->getBackgroundImage(); - if (null === $image) { + if (!$image instanceof GiftCardConfigurationImageInterface) { return $data; } $path = $image->getPath(); - if (null !== $path && null !== $request) { + if (null !== $path && $request instanceof Request) { $data['image'] = sprintf('%s/%s/%s', $request->getSchemeAndHttpHost(), $this->publicMediaDirectory, $path); } diff --git a/src/Serializer/Normalizer/GiftCardNormalizer.php b/src/Serializer/Normalizer/GiftCardNormalizer.php index 403eb7d6..8192a53b 100644 --- a/src/Serializer/Normalizer/GiftCardNormalizer.php +++ b/src/Serializer/Normalizer/GiftCardNormalizer.php @@ -14,14 +14,8 @@ final class GiftCardNormalizer implements ContextAwareNormalizerInterface { - private ObjectNormalizer $objectNormalizer; - - private MoneyFormatterInterface $moneyFormatter; - - public function __construct(ObjectNormalizer $objectNormalizer, MoneyFormatterInterface $moneyFormatter) + public function __construct(private readonly ObjectNormalizer $objectNormalizer, private readonly MoneyFormatterInterface $moneyFormatter) { - $this->objectNormalizer = $objectNormalizer; - $this->moneyFormatter = $moneyFormatter; } /** diff --git a/src/Twig/Extension/PdfRuntime.php b/src/Twig/Extension/PdfRuntime.php index 689b339f..c487ac65 100644 --- a/src/Twig/Extension/PdfRuntime.php +++ b/src/Twig/Extension/PdfRuntime.php @@ -11,16 +11,8 @@ final class PdfRuntime implements RuntimeExtensionInterface { - private PdfRendererInterface $PDFRenderer; - - private GiftCardFactoryInterface $giftCardFactory; - - public function __construct( - PdfRendererInterface $giftCardPDFRenderer, - GiftCardFactoryInterface $giftCardFactory, - ) { - $this->PDFRenderer = $giftCardPDFRenderer; - $this->giftCardFactory = $giftCardFactory; + public function __construct(private readonly PdfRendererInterface $PDFRenderer, private readonly GiftCardFactoryInterface $giftCardFactory) + { } public function getBase64EncodedExamplePdfContent(GiftCardConfigurationInterface $giftCardChannelConfiguration): string diff --git a/src/Validator/Constraints/DatePeriodValidator.php b/src/Validator/Constraints/DatePeriodValidator.php index f8fa38df..c2a77aad 100644 --- a/src/Validator/Constraints/DatePeriodValidator.php +++ b/src/Validator/Constraints/DatePeriodValidator.php @@ -12,11 +12,8 @@ final class DatePeriodValidator extends ConstraintValidator { - private DatePeriodUnitProviderInterface $datePeriodUnitProvider; - - public function __construct(DatePeriodUnitProviderInterface $datePeriodUnitProvider) + public function __construct(private readonly DatePeriodUnitProviderInterface $datePeriodUnitProvider) { - $this->datePeriodUnitProvider = $datePeriodUnitProvider; } /** diff --git a/src/Validator/Constraints/DefaultGiftCardConfigurationMustExistValidator.php b/src/Validator/Constraints/DefaultGiftCardConfigurationMustExistValidator.php index d2344661..74e43331 100644 --- a/src/Validator/Constraints/DefaultGiftCardConfigurationMustExistValidator.php +++ b/src/Validator/Constraints/DefaultGiftCardConfigurationMustExistValidator.php @@ -12,11 +12,8 @@ final class DefaultGiftCardConfigurationMustExistValidator extends ConstraintValidator { - private GiftCardConfigurationRepositoryInterface $giftCardConfigurationRepository; - - public function __construct(GiftCardConfigurationRepositoryInterface $giftCardConfigurationRepository) + public function __construct(private readonly GiftCardConfigurationRepositoryInterface $giftCardConfigurationRepository) { - $this->giftCardConfigurationRepository = $giftCardConfigurationRepository; } /** @@ -37,7 +34,7 @@ public function validate($value, Constraint $constraint): void } $defaultGiftCardConfiguration = $this->giftCardConfigurationRepository->findDefault(); - if (null === $defaultGiftCardConfiguration || $defaultGiftCardConfiguration->getId() === $value->getId()) { + if (!$defaultGiftCardConfiguration instanceof GiftCardConfigurationInterface || $defaultGiftCardConfiguration->getId() === $value->getId()) { $this->context->buildViolation($constraint->message) ->atPath('default') ->addViolation() diff --git a/src/Validator/Constraints/HasBackgroundImageValidator.php b/src/Validator/Constraints/HasBackgroundImageValidator.php index 1efd72a7..28d2076c 100644 --- a/src/Validator/Constraints/HasBackgroundImageValidator.php +++ b/src/Validator/Constraints/HasBackgroundImageValidator.php @@ -4,7 +4,9 @@ namespace Setono\SyliusGiftCardPlugin\Validator\Constraints; +use Setono\SyliusGiftCardPlugin\Model\GiftCardConfigurationImageInterface; use Setono\SyliusGiftCardPlugin\Model\GiftCardConfigurationInterface; +use SplFileInfo; use Symfony\Component\Validator\Constraint; use Symfony\Component\Validator\ConstraintValidator; use Symfony\Component\Validator\Exception\UnexpectedTypeException; @@ -26,11 +28,11 @@ public function validate($value, Constraint $constraint): void $backgroundImage = $value->getBackgroundImage(); - if (null === $backgroundImage) { + if (!$backgroundImage instanceof GiftCardConfigurationImageInterface) { return; } - if (null === $backgroundImage->getFile() && null === $backgroundImage->getPath()) { + if (!$backgroundImage->getFile() instanceof SplFileInfo && null === $backgroundImage->getPath()) { $this->context->buildViolation($constraint->message) ->addViolation(); } diff --git a/src/Validator/Constraints/Pdf/ValidOrientationValidator.php b/src/Validator/Constraints/Pdf/ValidOrientationValidator.php index 4c1d3a73..b8d5557b 100644 --- a/src/Validator/Constraints/Pdf/ValidOrientationValidator.php +++ b/src/Validator/Constraints/Pdf/ValidOrientationValidator.php @@ -10,11 +10,8 @@ final class ValidOrientationValidator extends ConstraintValidator { - private array $availableOrientations; - - public function __construct(array $availableOrientations) + public function __construct(private readonly array $availableOrientations) { - $this->availableOrientations = $availableOrientations; } /** diff --git a/src/Validator/Constraints/Pdf/ValidPageSizeValidator.php b/src/Validator/Constraints/Pdf/ValidPageSizeValidator.php index 9258961b..c55cab69 100644 --- a/src/Validator/Constraints/Pdf/ValidPageSizeValidator.php +++ b/src/Validator/Constraints/Pdf/ValidPageSizeValidator.php @@ -10,11 +10,8 @@ final class ValidPageSizeValidator extends ConstraintValidator { - private array $availablePageSizes; - - public function __construct(array $availableOrientations) + public function __construct(private readonly array $availablePageSizes) { - $this->availablePageSizes = $availableOrientations; } /** diff --git a/tests/Application/config/bootstrap.php b/tests/Application/config/bootstrap.php index 2291ab42..68015e64 100644 --- a/tests/Application/config/bootstrap.php +++ b/tests/Application/config/bootstrap.php @@ -19,5 +19,5 @@ } $_SERVER['APP_ENV'] = $_ENV['APP_ENV'] = ($_SERVER['APP_ENV'] ?? $_ENV['APP_ENV'] ?? null) ?: 'dev'; -$_SERVER['APP_DEBUG'] = $_SERVER['APP_DEBUG'] ?? $_ENV['APP_DEBUG'] ?? 'prod' !== $_SERVER['APP_ENV']; +$_SERVER['APP_DEBUG'] ??= $_ENV['APP_DEBUG'] ?? 'prod' !== $_SERVER['APP_ENV']; $_SERVER['APP_DEBUG'] = $_ENV['APP_DEBUG'] = (int) $_SERVER['APP_DEBUG'] || filter_var($_SERVER['APP_DEBUG'], \FILTER_VALIDATE_BOOLEAN) ? '1' : '0'; diff --git a/tests/Application/config/bundles.php b/tests/Application/config/bundles.php index a60ea358..526f9d10 100644 --- a/tests/Application/config/bundles.php +++ b/tests/Application/config/bundles.php @@ -2,66 +2,124 @@ declare(strict_types=1); +use ApiPlatform\Core\Bridge\Symfony\Bundle\ApiPlatformBundle; +use BabDev\PagerfantaBundle\BabDevPagerfantaBundle; +use Bazinga\Bundle\HateoasBundle\BazingaHateoasBundle; +use Doctrine\Bundle\DoctrineBundle\DoctrineBundle; +use Doctrine\Bundle\MigrationsBundle\DoctrineMigrationsBundle; +use FOS\RestBundle\FOSRestBundle; +use FriendsOfBehat\SymfonyExtension\Bundle\FriendsOfBehatSymfonyExtensionBundle; +use JMS\SerializerBundle\JMSSerializerBundle; +use Knp\Bundle\GaufretteBundle\KnpGaufretteBundle; +use Knp\Bundle\MenuBundle\KnpMenuBundle; +use Knp\Bundle\SnappyBundle\KnpSnappyBundle; +use League\FlysystemBundle\FlysystemBundle; +use Lexik\Bundle\JWTAuthenticationBundle\LexikJWTAuthenticationBundle; +use Liip\ImagineBundle\LiipImagineBundle; +use Payum\Bundle\PayumBundle\PayumBundle; +use Setono\SyliusGiftCardPlugin\SetonoSyliusGiftCardPlugin; +use Sonata\BlockBundle\SonataBlockBundle; +use Stof\DoctrineExtensionsBundle\StofDoctrineExtensionsBundle; +use Sylius\Bundle\AddressingBundle\SyliusAddressingBundle; +use Sylius\Bundle\AdminBundle\SyliusAdminBundle; +use Sylius\Bundle\ApiBundle\SyliusApiBundle; +use Sylius\Bundle\AttributeBundle\SyliusAttributeBundle; +use Sylius\Bundle\ChannelBundle\SyliusChannelBundle; +use Sylius\Bundle\CoreBundle\SyliusCoreBundle; +use Sylius\Bundle\CurrencyBundle\SyliusCurrencyBundle; +use Sylius\Bundle\CustomerBundle\SyliusCustomerBundle; +use Sylius\Bundle\FixturesBundle\SyliusFixturesBundle; +use Sylius\Bundle\GridBundle\SyliusGridBundle; +use Sylius\Bundle\InventoryBundle\SyliusInventoryBundle; +use Sylius\Bundle\LocaleBundle\SyliusLocaleBundle; +use Sylius\Bundle\MailerBundle\SyliusMailerBundle; +use Sylius\Bundle\MoneyBundle\SyliusMoneyBundle; +use Sylius\Bundle\OrderBundle\SyliusOrderBundle; +use Sylius\Bundle\PaymentBundle\SyliusPaymentBundle; +use Sylius\Bundle\PayumBundle\SyliusPayumBundle; +use Sylius\Bundle\ProductBundle\SyliusProductBundle; +use Sylius\Bundle\PromotionBundle\SyliusPromotionBundle; +use Sylius\Bundle\ResourceBundle\SyliusResourceBundle; +use Sylius\Bundle\ReviewBundle\SyliusReviewBundle; +use Sylius\Bundle\ShippingBundle\SyliusShippingBundle; +use Sylius\Bundle\ShopBundle\SyliusShopBundle; +use Sylius\Bundle\TaxationBundle\SyliusTaxationBundle; +use Sylius\Bundle\TaxonomyBundle\SyliusTaxonomyBundle; +use Sylius\Bundle\ThemeBundle\SyliusThemeBundle; +use Sylius\Bundle\UiBundle\SyliusUiBundle; +use Sylius\Bundle\UserBundle\SyliusUserBundle; +use Sylius\Calendar\SyliusCalendarBundle; +use SyliusLabs\DoctrineMigrationsExtraBundle\SyliusLabsDoctrineMigrationsExtraBundle; +use SyliusLabs\Polyfill\Symfony\Security\Bundle\SyliusLabsPolyfillSymfonySecurityBundle; +use Symfony\Bundle\DebugBundle\DebugBundle; +use Symfony\Bundle\FrameworkBundle\FrameworkBundle; +use Symfony\Bundle\MonologBundle\MonologBundle; +use Symfony\Bundle\SecurityBundle\SecurityBundle; +use Symfony\Bundle\TwigBundle\TwigBundle; +use Symfony\Bundle\WebProfilerBundle\WebProfilerBundle; +use Symfony\WebpackEncoreBundle\WebpackEncoreBundle; +use winzou\Bundle\StateMachineBundle\winzouStateMachineBundle; + return [ - Symfony\Bundle\FrameworkBundle\FrameworkBundle::class => ['all' => true], - Symfony\Bundle\MonologBundle\MonologBundle::class => ['all' => true], - Symfony\Bundle\SecurityBundle\SecurityBundle::class => ['all' => true], - Symfony\Bundle\TwigBundle\TwigBundle::class => ['all' => true], - Doctrine\Bundle\DoctrineBundle\DoctrineBundle::class => ['all' => true], - Sylius\Bundle\OrderBundle\SyliusOrderBundle::class => ['all' => true], - Sylius\Bundle\MoneyBundle\SyliusMoneyBundle::class => ['all' => true], - Sylius\Bundle\CurrencyBundle\SyliusCurrencyBundle::class => ['all' => true], - Sylius\Bundle\LocaleBundle\SyliusLocaleBundle::class => ['all' => true], - Sylius\Bundle\ProductBundle\SyliusProductBundle::class => ['all' => true], - Sylius\Bundle\ChannelBundle\SyliusChannelBundle::class => ['all' => true], - Sylius\Bundle\AttributeBundle\SyliusAttributeBundle::class => ['all' => true], - Sylius\Bundle\TaxationBundle\SyliusTaxationBundle::class => ['all' => true], - Sylius\Bundle\ShippingBundle\SyliusShippingBundle::class => ['all' => true], - Sylius\Bundle\PaymentBundle\SyliusPaymentBundle::class => ['all' => true], - Sylius\Bundle\MailerBundle\SyliusMailerBundle::class => ['all' => true], - Sylius\Bundle\PromotionBundle\SyliusPromotionBundle::class => ['all' => true], - Sylius\Bundle\AddressingBundle\SyliusAddressingBundle::class => ['all' => true], - Sylius\Bundle\InventoryBundle\SyliusInventoryBundle::class => ['all' => true], - Sylius\Bundle\TaxonomyBundle\SyliusTaxonomyBundle::class => ['all' => true], - Sylius\Bundle\UserBundle\SyliusUserBundle::class => ['all' => true], - Sylius\Bundle\CustomerBundle\SyliusCustomerBundle::class => ['all' => true], - Sylius\Bundle\UiBundle\SyliusUiBundle::class => ['all' => true], - Sylius\Bundle\ReviewBundle\SyliusReviewBundle::class => ['all' => true], - Sylius\Bundle\CoreBundle\SyliusCoreBundle::class => ['all' => true], - Sylius\Bundle\ResourceBundle\SyliusResourceBundle::class => ['all' => true], + FrameworkBundle::class => ['all' => true], + MonologBundle::class => ['all' => true], + SecurityBundle::class => ['all' => true], + TwigBundle::class => ['all' => true], + DoctrineBundle::class => ['all' => true], + SyliusOrderBundle::class => ['all' => true], + SyliusMoneyBundle::class => ['all' => true], + SyliusCurrencyBundle::class => ['all' => true], + SyliusLocaleBundle::class => ['all' => true], + SyliusProductBundle::class => ['all' => true], + SyliusChannelBundle::class => ['all' => true], + SyliusAttributeBundle::class => ['all' => true], + SyliusTaxationBundle::class => ['all' => true], + SyliusShippingBundle::class => ['all' => true], + SyliusPaymentBundle::class => ['all' => true], + SyliusMailerBundle::class => ['all' => true], + SyliusPromotionBundle::class => ['all' => true], + SyliusAddressingBundle::class => ['all' => true], + SyliusInventoryBundle::class => ['all' => true], + SyliusTaxonomyBundle::class => ['all' => true], + SyliusUserBundle::class => ['all' => true], + SyliusCustomerBundle::class => ['all' => true], + SyliusUiBundle::class => ['all' => true], + SyliusReviewBundle::class => ['all' => true], + SyliusCoreBundle::class => ['all' => true], + SyliusResourceBundle::class => ['all' => true], // Begin: In test app, those 3 needs to be loaded before our plugin or the Api Resource override won't work - Lexik\Bundle\JWTAuthenticationBundle\LexikJWTAuthenticationBundle::class => ['all' => true], - ApiPlatform\Core\Bridge\Symfony\Bundle\ApiPlatformBundle::class => ['all' => true], - Sylius\Bundle\ApiBundle\SyliusApiBundle::class => ['all' => true], + LexikJWTAuthenticationBundle::class => ['all' => true], + ApiPlatformBundle::class => ['all' => true], + SyliusApiBundle::class => ['all' => true], // End: In test app, those 3 needs to be loaded before our plugin or the Api Resource override won't work - winzou\Bundle\StateMachineBundle\winzouStateMachineBundle::class => ['all' => true], - Sonata\BlockBundle\SonataBlockBundle::class => ['all' => true], - Bazinga\Bundle\HateoasBundle\BazingaHateoasBundle::class => ['all' => true], - JMS\SerializerBundle\JMSSerializerBundle::class => ['all' => true], - FOS\RestBundle\FOSRestBundle::class => ['all' => true], - Knp\Bundle\GaufretteBundle\KnpGaufretteBundle::class => ['all' => true], - Knp\Bundle\MenuBundle\KnpMenuBundle::class => ['all' => true], - League\FlysystemBundle\FlysystemBundle::class => ['all' => true], - Liip\ImagineBundle\LiipImagineBundle::class => ['all' => true], - Payum\Bundle\PayumBundle\PayumBundle::class => ['all' => true], - Stof\DoctrineExtensionsBundle\StofDoctrineExtensionsBundle::class => ['all' => true], - Doctrine\Bundle\MigrationsBundle\DoctrineMigrationsBundle::class => ['all' => true], - Sylius\Bundle\FixturesBundle\SyliusFixturesBundle::class => ['all' => true], - Sylius\Bundle\PayumBundle\SyliusPayumBundle::class => ['all' => true], - Sylius\Bundle\ThemeBundle\SyliusThemeBundle::class => ['all' => true], - Sylius\Bundle\AdminBundle\SyliusAdminBundle::class => ['all' => true], - Sylius\Bundle\ShopBundle\SyliusShopBundle::class => ['all' => true], - Symfony\Bundle\DebugBundle\DebugBundle::class => ['dev' => true, 'test' => true], - Symfony\Bundle\WebProfilerBundle\WebProfilerBundle::class => ['dev' => true, 'test' => true], - FriendsOfBehat\SymfonyExtension\Bundle\FriendsOfBehatSymfonyExtensionBundle::class => ['test' => true], - Knp\Bundle\SnappyBundle\KnpSnappyBundle::class => ['all' => true], - SyliusLabs\DoctrineMigrationsExtraBundle\SyliusLabsDoctrineMigrationsExtraBundle::class => ['all' => true], - BabDev\PagerfantaBundle\BabDevPagerfantaBundle::class => ['all' => true], - SyliusLabs\Polyfill\Symfony\Security\Bundle\SyliusLabsPolyfillSymfonySecurityBundle::class => ['all' => true], - Symfony\WebpackEncoreBundle\WebpackEncoreBundle::class => ['all' => true], - Sylius\Calendar\SyliusCalendarBundle::class => ['all' => true], - Setono\SyliusGiftCardPlugin\SetonoSyliusGiftCardPlugin::class => ['all' => true], - Sylius\Bundle\GridBundle\SyliusGridBundle::class => ['all' => true], + winzouStateMachineBundle::class => ['all' => true], + SonataBlockBundle::class => ['all' => true], + BazingaHateoasBundle::class => ['all' => true], + JMSSerializerBundle::class => ['all' => true], + FOSRestBundle::class => ['all' => true], + KnpGaufretteBundle::class => ['all' => true], + KnpMenuBundle::class => ['all' => true], + FlysystemBundle::class => ['all' => true], + LiipImagineBundle::class => ['all' => true], + PayumBundle::class => ['all' => true], + StofDoctrineExtensionsBundle::class => ['all' => true], + DoctrineMigrationsBundle::class => ['all' => true], + SyliusFixturesBundle::class => ['all' => true], + SyliusPayumBundle::class => ['all' => true], + SyliusThemeBundle::class => ['all' => true], + SyliusAdminBundle::class => ['all' => true], + SyliusShopBundle::class => ['all' => true], + DebugBundle::class => ['dev' => true, 'test' => true], + WebProfilerBundle::class => ['dev' => true, 'test' => true], + FriendsOfBehatSymfonyExtensionBundle::class => ['test' => true], + KnpSnappyBundle::class => ['all' => true], + SyliusLabsDoctrineMigrationsExtraBundle::class => ['all' => true], + BabDevPagerfantaBundle::class => ['all' => true], + SyliusLabsPolyfillSymfonySecurityBundle::class => ['all' => true], + WebpackEncoreBundle::class => ['all' => true], + SyliusCalendarBundle::class => ['all' => true], + SetonoSyliusGiftCardPlugin::class => ['all' => true], + SyliusGridBundle::class => ['all' => true], ]; diff --git a/tests/Application/public/index.php b/tests/Application/public/index.php index b550b6a8..7c9207ff 100644 --- a/tests/Application/public/index.php +++ b/tests/Application/public/index.php @@ -15,7 +15,7 @@ } if ($trustedProxies = $_SERVER['TRUSTED_PROXIES'] ?? $_ENV['TRUSTED_PROXIES'] ?? false) { - Request::setTrustedProxies(explode(',', $trustedProxies), Request::HEADER_X_FORWARDED_ALL ^ Request::HEADER_X_FORWARDED_HOST); + Request::setTrustedProxies(explode(',', (string) $trustedProxies), Request::HEADER_X_FORWARDED_ALL ^ Request::HEADER_X_FORWARDED_HOST); } if ($trustedHosts = $_SERVER['TRUSTED_HOSTS'] ?? $_ENV['TRUSTED_HOSTS'] ?? false) { diff --git a/tests/Behat/Context/Api/Admin/ManagingGiftCardConfigurationsContext.php b/tests/Behat/Context/Api/Admin/ManagingGiftCardConfigurationsContext.php index 827a22e9..414e05e7 100644 --- a/tests/Behat/Context/Api/Admin/ManagingGiftCardConfigurationsContext.php +++ b/tests/Behat/Context/Api/Admin/ManagingGiftCardConfigurationsContext.php @@ -16,24 +16,8 @@ final class ManagingGiftCardConfigurationsContext implements Context { - private ApiClientInterface $client; - - private ResponseCheckerInterface $responseChecker; - - private IriConverterInterface $iriConverter; - - private RequestFactoryInterface $requestFactory; - - public function __construct( - ApiClientInterface $client, - ResponseCheckerInterface $responseChecker, - IriConverterInterface $iriConverter, - RequestFactoryInterface $requestFactory, - ) { - $this->client = $client; - $this->responseChecker = $responseChecker; - $this->iriConverter = $iriConverter; - $this->requestFactory = $requestFactory; + public function __construct(private readonly ApiClientInterface $client, private readonly ResponseCheckerInterface $responseChecker, private readonly IriConverterInterface $iriConverter, private readonly RequestFactoryInterface $requestFactory) + { } /** diff --git a/tests/Behat/Context/Api/Admin/ManagingGiftCardsBalanceContext.php b/tests/Behat/Context/Api/Admin/ManagingGiftCardsBalanceContext.php index 0fde9bf8..1cd3936c 100644 --- a/tests/Behat/Context/Api/Admin/ManagingGiftCardsBalanceContext.php +++ b/tests/Behat/Context/Api/Admin/ManagingGiftCardsBalanceContext.php @@ -12,16 +12,8 @@ final class ManagingGiftCardsBalanceContext implements Context { - private ApiClientInterface $client; - - private ResponseCheckerInterface $responseChecker; - - public function __construct( - ApiClientInterface $client, - ResponseCheckerInterface $responseChecker, - ) { - $this->client = $client; - $this->responseChecker = $responseChecker; + public function __construct(private readonly ApiClientInterface $client, private readonly ResponseCheckerInterface $responseChecker) + { } /** diff --git a/tests/Behat/Context/Api/Admin/ManagingGiftCardsContext.php b/tests/Behat/Context/Api/Admin/ManagingGiftCardsContext.php index d0bf6708..ab0c57cf 100644 --- a/tests/Behat/Context/Api/Admin/ManagingGiftCardsContext.php +++ b/tests/Behat/Context/Api/Admin/ManagingGiftCardsContext.php @@ -16,20 +16,8 @@ final class ManagingGiftCardsContext implements Context { - private ApiClientInterface $client; - - private ResponseCheckerInterface $responseChecker; - - private IriConverterInterface $iriConverter; - - public function __construct( - ApiClientInterface $client, - ResponseCheckerInterface $responseChecker, - IriConverterInterface $iriConverter, - ) { - $this->client = $client; - $this->responseChecker = $responseChecker; - $this->iriConverter = $iriConverter; + public function __construct(private readonly ApiClientInterface $client, private readonly ResponseCheckerInterface $responseChecker, private readonly IriConverterInterface $iriConverter) + { } /** @@ -137,7 +125,7 @@ public function iShouldNotSeeGiftCard(string $code): void */ public function iSpecifyItsCustomerAs(?CustomerInterface $customer = null): void { - $this->client->addRequestData('customer', null !== $customer ? $this->iriConverter->getIriFromItem($customer) : null); + $this->client->addRequestData('customer', $customer instanceof CustomerInterface ? $this->iriConverter->getIriFromItem($customer) : null); } /** diff --git a/tests/Behat/Context/Api/Shop/CartContext.php b/tests/Behat/Context/Api/Shop/CartContext.php index d7454346..2fd793ce 100644 --- a/tests/Behat/Context/Api/Shop/CartContext.php +++ b/tests/Behat/Context/Api/Shop/CartContext.php @@ -16,36 +16,8 @@ final class CartContext implements Context { - private ApiClientInterface $cartsClient; - - private ResponseCheckerInterface $responseChecker; - - private SharedStorageInterface $sharedStorage; - - private ProductVariantResolverInterface $productVariantResolver; - - private IriConverterInterface $iriConverter; - - private RequestFactoryInterface $requestFactory; - - private string $apiUrlPrefix; - - public function __construct( - ApiClientInterface $cartsClient, - ResponseCheckerInterface $responseChecker, - SharedStorageInterface $sharedStorage, - ProductVariantResolverInterface $productVariantResolver, - IriConverterInterface $iriConverter, - RequestFactoryInterface $requestFactory, - string $apiUrlPrefix, - ) { - $this->cartsClient = $cartsClient; - $this->responseChecker = $responseChecker; - $this->sharedStorage = $sharedStorage; - $this->productVariantResolver = $productVariantResolver; - $this->iriConverter = $iriConverter; - $this->requestFactory = $requestFactory; - $this->apiUrlPrefix = $apiUrlPrefix; + public function __construct(private readonly ApiClientInterface $cartsClient, private readonly ResponseCheckerInterface $responseChecker, private readonly SharedStorageInterface $sharedStorage, private readonly ProductVariantResolverInterface $productVariantResolver, private readonly IriConverterInterface $iriConverter, private readonly RequestFactoryInterface $requestFactory, private readonly string $apiUrlPrefix) + { } /** @@ -53,7 +25,7 @@ public function __construct( */ public function iAddProductWithAmountAndMessage(ProductInterface $product, int $amount, string $message): void { - $tokenValue = $tokenValue ?? $this->pickupCart(); + $tokenValue ??= $this->pickupCart(); $request = $this->requestFactory->customItemAction('shop', 'orders', $tokenValue, HttpRequest::METHOD_POST, 'items'); diff --git a/tests/Behat/Context/Api/Shop/ManagingGiftCardsContext.php b/tests/Behat/Context/Api/Shop/ManagingGiftCardsContext.php index 728c6894..abfb227f 100644 --- a/tests/Behat/Context/Api/Shop/ManagingGiftCardsContext.php +++ b/tests/Behat/Context/Api/Shop/ManagingGiftCardsContext.php @@ -15,24 +15,8 @@ final class ManagingGiftCardsContext implements Context { - private ApiClientInterface $client; - - private ResponseCheckerInterface $responseChecker; - - private SharedStorageInterface $sharedStorage; - - private RequestFactoryInterface $requestFactory; - - public function __construct( - ApiClientInterface $client, - ResponseCheckerInterface $responseChecker, - SharedStorageInterface $sharedStorage, - RequestFactoryInterface $requestFactory, - ) { - $this->client = $client; - $this->responseChecker = $responseChecker; - $this->sharedStorage = $sharedStorage; - $this->requestFactory = $requestFactory; + public function __construct(private readonly ApiClientInterface $client, private readonly ResponseCheckerInterface $responseChecker, private readonly SharedStorageInterface $sharedStorage, private readonly RequestFactoryInterface $requestFactory) + { } /** diff --git a/tests/Behat/Context/Setup/GiftCardConfigurationContext.php b/tests/Behat/Context/Setup/GiftCardConfigurationContext.php index aee505fd..1cbfa917 100644 --- a/tests/Behat/Context/Setup/GiftCardConfigurationContext.php +++ b/tests/Behat/Context/Setup/GiftCardConfigurationContext.php @@ -10,16 +10,8 @@ final class GiftCardConfigurationContext implements Context { - private RepositoryInterface $giftCardConfigurationRepository; - - private GiftCardConfigurationFactoryInterface $giftCardConfigurationFactory; - - public function __construct( - RepositoryInterface $giftCardConfigurationRepository, - GiftCardConfigurationFactoryInterface $giftCardConfigurationFactory, - ) { - $this->giftCardConfigurationRepository = $giftCardConfigurationRepository; - $this->giftCardConfigurationFactory = $giftCardConfigurationFactory; + public function __construct(private readonly RepositoryInterface $giftCardConfigurationRepository, private readonly GiftCardConfigurationFactoryInterface $giftCardConfigurationFactory) + { } /** diff --git a/tests/Behat/Context/Setup/GiftCardContext.php b/tests/Behat/Context/Setup/GiftCardContext.php index 4c751f63..2ba03f01 100644 --- a/tests/Behat/Context/Setup/GiftCardContext.php +++ b/tests/Behat/Context/Setup/GiftCardContext.php @@ -17,28 +17,8 @@ final class GiftCardContext implements Context { - private SharedStorageInterface $sharedStorage; - - private GiftCardRepositoryInterface $giftCardRepository; - - private GiftCardFactoryInterface $giftCardFactory; - - private ObjectManager $productManager; - - private MessageBusInterface $messageBus; - - public function __construct( - SharedStorageInterface $sharedStorage, - GiftCardRepositoryInterface $giftCardRepository, - GiftCardFactoryInterface $giftCardFactory, - ObjectManager $productManager, - MessageBusInterface $messageBus, - ) { - $this->sharedStorage = $sharedStorage; - $this->giftCardRepository = $giftCardRepository; - $this->giftCardFactory = $giftCardFactory; - $this->productManager = $productManager; - $this->messageBus = $messageBus; + public function __construct(private readonly SharedStorageInterface $sharedStorage, private readonly GiftCardRepositoryInterface $giftCardRepository, private readonly GiftCardFactoryInterface $giftCardFactory, private readonly ObjectManager $productManager, private readonly MessageBusInterface $messageBus) + { } /** @@ -73,7 +53,7 @@ public function theStoreHasGiftCardWithCode( int $price, ?ChannelInterface $channel = null, ): void { - if (null === $channel) { + if (!$channel instanceof ChannelInterface) { /** @var ChannelInterface $channel */ $channel = $this->sharedStorage->get('channel'); } diff --git a/tests/Behat/Context/Transform/GiftCardConfigurationContext.php b/tests/Behat/Context/Transform/GiftCardConfigurationContext.php index ccbef741..53f0f4b9 100644 --- a/tests/Behat/Context/Transform/GiftCardConfigurationContext.php +++ b/tests/Behat/Context/Transform/GiftCardConfigurationContext.php @@ -10,11 +10,8 @@ final class GiftCardConfigurationContext implements Context { - private RepositoryInterface $giftCardConfigurationRepository; - - public function __construct(RepositoryInterface $giftCardConfigurationRepository) + public function __construct(private readonly RepositoryInterface $giftCardConfigurationRepository) { - $this->giftCardConfigurationRepository = $giftCardConfigurationRepository; } /** diff --git a/tests/Behat/Context/Transform/GiftCardContext.php b/tests/Behat/Context/Transform/GiftCardContext.php index a49b7ee6..35a6c9c5 100644 --- a/tests/Behat/Context/Transform/GiftCardContext.php +++ b/tests/Behat/Context/Transform/GiftCardContext.php @@ -10,12 +10,8 @@ final class GiftCardContext implements Context { - /** @var GiftCardRepositoryInterface */ - private $giftCardRepository; - - public function __construct(GiftCardRepositoryInterface $giftCardRepository) + public function __construct(private readonly GiftCardRepositoryInterface $giftCardRepository) { - $this->giftCardRepository = $giftCardRepository; } /** diff --git a/tests/Behat/Context/Ui/Admin/ManagingGiftCardsContext.php b/tests/Behat/Context/Ui/Admin/ManagingGiftCardsContext.php index 6815edc7..33eb07fa 100644 --- a/tests/Behat/Context/Ui/Admin/ManagingGiftCardsContext.php +++ b/tests/Behat/Context/Ui/Admin/ManagingGiftCardsContext.php @@ -11,13 +11,8 @@ final class ManagingGiftCardsContext implements Context { - /** @var CreateSimpleProductPageInterface */ - private $createGiftCardPage; - - public function __construct( - CreateSimpleProductPageInterface $createGiftCardPage, - ) { - $this->createGiftCardPage = $createGiftCardPage; + public function __construct(private readonly CreateSimpleProductPageInterface $createGiftCardPage) + { } /** diff --git a/tests/Behat/Context/Ui/Shop/CartContext.php b/tests/Behat/Context/Ui/Shop/CartContext.php index 486b6830..48715835 100644 --- a/tests/Behat/Context/Ui/Shop/CartContext.php +++ b/tests/Behat/Context/Ui/Shop/CartContext.php @@ -12,14 +12,8 @@ final class CartContext implements Context { - private SummaryPageInterface $summaryPage; - - private ShowPageInterface $productShowPage; - - public function __construct(SummaryPageInterface $summaryPage, ShowPageInterface $productShowPage) + public function __construct(private readonly SummaryPageInterface $summaryPage, private readonly ShowPageInterface $productShowPage) { - $this->summaryPage = $summaryPage; - $this->productShowPage = $productShowPage; } /** diff --git a/tests/Behat/Context/Ui/Shop/CheckoutContext.php b/tests/Behat/Context/Ui/Shop/CheckoutContext.php index b72d0c72..3e0cb403 100644 --- a/tests/Behat/Context/Ui/Shop/CheckoutContext.php +++ b/tests/Behat/Context/Ui/Shop/CheckoutContext.php @@ -15,28 +15,8 @@ final class CheckoutContext implements Context { - /** @var CheckoutCompleteContext */ - private $checkoutCompleteContext; - - /** @var OrderContext */ - private $orderContext; - - /** @var OrderRepositoryInterface */ - private $orderRepository; - - /** @var EntityManagerInterface */ - private $giftCardManager; - - public function __construct( - CheckoutCompleteContext $checkoutCompleteContext, - OrderContext $orderContext, - OrderRepositoryInterface $orderRepository, - EntityManagerInterface $giftCardManager, - ) { - $this->checkoutCompleteContext = $checkoutCompleteContext; - $this->orderContext = $orderContext; - $this->orderRepository = $orderRepository; - $this->giftCardManager = $giftCardManager; + public function __construct(private readonly CheckoutCompleteContext $checkoutCompleteContext, private readonly OrderContext $orderContext, private readonly OrderRepositoryInterface $orderRepository, private readonly EntityManagerInterface $giftCardManager) + { } /** diff --git a/tests/Unit/EventSubscriber/SendEmailWithGiftCardToCustomerSubscriberTest.php b/tests/Unit/EventSubscriber/SendEmailWithGiftCardToCustomerSubscriberTest.php index 9fdc4beb..c08d0390 100644 --- a/tests/Unit/EventSubscriber/SendEmailWithGiftCardToCustomerSubscriberTest.php +++ b/tests/Unit/EventSubscriber/SendEmailWithGiftCardToCustomerSubscriberTest.php @@ -10,6 +10,7 @@ use Setono\SyliusGiftCardPlugin\EmailManager\GiftCardEmailManagerInterface; use Setono\SyliusGiftCardPlugin\EventSubscriber\SendEmailWithGiftCardToCustomerSubscriber; use Setono\SyliusGiftCardPlugin\Model\GiftCardInterface; +use stdClass; use Sylius\Bundle\ResourceBundle\Event\ResourceControllerEvent; use Sylius\Component\Core\Model\CustomerInterface; use Sylius\Component\Resource\Exception\UnexpectedTypeException; @@ -25,10 +26,10 @@ public function it_throws_an_error_if_the_subject_is_not_gift_card(): void { $giftCardEmailManager = $this->prophesize(GiftCardEmailManagerInterface::class); $event = $this->prophesize(ResourceControllerEvent::class); - $event->getSubject()->willReturn(new \stdClass()); + $event->getSubject()->willReturn(new stdClass()); $this->expectException(UnexpectedTypeException::class); - $subscriber = new \Setono\SyliusGiftCardPlugin\EventSubscriber\SendEmailWithGiftCardToCustomerSubscriber($giftCardEmailManager->reveal()); + $subscriber = new SendEmailWithGiftCardToCustomerSubscriber($giftCardEmailManager->reveal()); $subscriber->postCreate($event->reveal()); } @@ -61,7 +62,7 @@ public function it_does_not_send_email_if_it_was_not_asked(): void $event = $this->prophesize(ResourceControllerEvent::class); $event->getSubject()->willReturn($giftCard); - $subscriber = new \Setono\SyliusGiftCardPlugin\EventSubscriber\SendEmailWithGiftCardToCustomerSubscriber($giftCardEmailManager->reveal()); + $subscriber = new SendEmailWithGiftCardToCustomerSubscriber($giftCardEmailManager->reveal()); $subscriber->postCreate($event->reveal()); $giftCardEmailManager->sendEmailToCustomerWithGiftCard(Argument::any(), Argument::any())->shouldNotHaveBeenCalled(); diff --git a/tests/Unit/Factory/GiftCardFactoryTest.php b/tests/Unit/Factory/GiftCardFactoryTest.php index 94031a27..28e89085 100644 --- a/tests/Unit/Factory/GiftCardFactoryTest.php +++ b/tests/Unit/Factory/GiftCardFactoryTest.php @@ -4,6 +4,8 @@ namespace Setono\SyliusGiftCardPlugin\Tests\Unit\Factory; +use DateTime; +use DateTimeImmutable; use PHPUnit\Framework\TestCase; use Prophecy\PhpUnit\ProphecyTrait; use Setono\SyliusGiftCardPlugin\Factory\GiftCardFactory; @@ -93,7 +95,7 @@ public function it_creates_a_new_gift_card_for_channel_with_expiration_date(): v $channel = new Channel(); $giftCardConfiguration = new GiftCardConfiguration(); $giftCardConfiguration->setDefaultValidityPeriod('1 month'); - $expectedValidUntilDate = new \DateTime('2022-01-01 12:00:00'); + $expectedValidUntilDate = new DateTime('2022-01-01 12:00:00'); $expectedValidUntilDate->modify('+1 month'); $decoratedFactory = $this->prophesize(FactoryInterface::class); @@ -105,7 +107,7 @@ public function it_creates_a_new_gift_card_for_channel_with_expiration_date(): v $decoratedFactory->createNew()->willReturn($giftCard); $giftCardCodeGenerator->generate()->willReturn('super-code'); $configurationProvider->getConfigurationForGiftCard($giftCard)->willReturn($giftCardConfiguration); - $calendar->today()->willReturn(new \DateTimeImmutable('2022-01-01 12:00:00')); + $calendar->today()->willReturn(new DateTimeImmutable('2022-01-01 12:00:00')); $factory = new GiftCardFactory( $decoratedFactory->reveal(), diff --git a/tests/Unit/Model/GiftCardTest.php b/tests/Unit/Model/GiftCardTest.php index f9b76d0e..0d6cf6c5 100644 --- a/tests/Unit/Model/GiftCardTest.php +++ b/tests/Unit/Model/GiftCardTest.php @@ -4,6 +4,7 @@ namespace Setono\SyliusGiftCardPlugin\Tests\Unit\Model; +use DateTime; use PHPUnit\Framework\TestCase; use Prophecy\PhpUnit\ProphecyTrait; use Setono\SyliusGiftCardPlugin\Model\GiftCard; @@ -58,7 +59,7 @@ public function it_has_properties(): void $giftCard->setOrigin('My origin'); $this->assertSame('My origin', $giftCard->getOrigin()); - $expiresAt = new \DateTime(); + $expiresAt = new DateTime(); $giftCard->setExpiresAt($expiresAt); $this->assertSame($expiresAt, $giftCard->getExpiresAt()); @@ -156,9 +157,9 @@ public function it_has_null_origin_by_default(): void */ public function it_can_expire(): void { - $today = new \DateTime('2022-01-01 00:00:00'); + $today = new DateTime('2022-01-01 00:00:00'); $giftCard = new GiftCard(); - $giftCard->setExpiresAt(new \DateTime('2021-12-15 14:00:00')); + $giftCard->setExpiresAt(new DateTime('2021-12-15 14:00:00')); $this->assertTrue($giftCard->isExpired($today)); } @@ -178,9 +179,9 @@ public function it_is_not_expired_if_expires_at_is_null(): void */ public function it_is_not_expired_if_expiresAt_is_in_future(): void { - $today = new \DateTime('2022-01-01 00:00:00'); + $today = new DateTime('2022-01-01 00:00:00'); $giftCard = new GiftCard(); - $giftCard->setExpiresAt(new \DateTime('2022-12-15 14:00:00')); + $giftCard->setExpiresAt(new DateTime('2022-12-15 14:00:00')); $this->assertFalse($giftCard->isExpired($today)); } From e6f650a122ca3d21713b69e4f03ebf91b0120b58 Mon Sep 17 00:00:00 2001 From: Ibes Date: Tue, 8 Oct 2024 10:30:59 +0200 Subject: [PATCH 05/15] Suggested changes by @Prometee --- src/Applicator/GiftCardApplicator.php | 5 +- src/EmailManager/GiftCardEmailManager.php | 5 +- ...dEmailWithGiftCardToCustomerSubscriber.php | 4 +- .../GiftCardToCodeDataTransformer.php | 2 +- src/Generator/GiftCardCodeGenerator.php | 7 +- src/Model/GiftCard.php | 20 +- src/Modifier/OrderGiftCardAmountModifier.php | 9 - .../GiftCardConfigurationProvider.php | 11 +- src/Renderer/PdfRenderer.php | 11 +- src/Resolver/CustomerChannelResolver.php | 5 +- src/Resolver/LocaleResolver.php | 7 +- src/Security/GiftCardVoter.php | 3 +- .../GiftCardConfigurationNormalizer.php | 5 +- ...iftCardConfigurationMustExistValidator.php | 2 +- .../HasBackgroundImageValidator.php | 6 +- tests/Application/config/bundles.php | 172 ++++++------------ tests/Behat/Context/Setup/GiftCardContext.php | 3 +- 17 files changed, 102 insertions(+), 175 deletions(-) diff --git a/src/Applicator/GiftCardApplicator.php b/src/Applicator/GiftCardApplicator.php index 5424f8d9..ff307e7f 100644 --- a/src/Applicator/GiftCardApplicator.php +++ b/src/Applicator/GiftCardApplicator.php @@ -10,7 +10,6 @@ use Setono\SyliusGiftCardPlugin\Model\GiftCardInterface; use Setono\SyliusGiftCardPlugin\Model\OrderInterface; use Setono\SyliusGiftCardPlugin\Repository\GiftCardRepositoryInterface; -use Sylius\Component\Channel\Model\ChannelInterface; use Sylius\Component\Order\Processor\OrderProcessorInterface; final class GiftCardApplicator implements GiftCardApplicatorInterface @@ -37,7 +36,7 @@ public function apply(OrderInterface $order, $giftCard): void } $orderChannel = $order->getChannel(); - if (!$orderChannel instanceof ChannelInterface) { + if (null === $orderChannel) { throw new RuntimeException('The channel on the order cannot be null'); } @@ -73,7 +72,7 @@ private function getGiftCard(string $giftCardCode): GiftCardInterface { $giftCard = $this->giftCardRepository->findOneByCode($giftCardCode); - if (!$giftCard instanceof GiftCardInterface) { + if (null === $giftCard) { throw new GiftCardNotFoundException($giftCardCode); } diff --git a/src/EmailManager/GiftCardEmailManager.php b/src/EmailManager/GiftCardEmailManager.php index 905931fe..2f2dea4d 100644 --- a/src/EmailManager/GiftCardEmailManager.php +++ b/src/EmailManager/GiftCardEmailManager.php @@ -9,7 +9,6 @@ use Setono\SyliusGiftCardPlugin\Renderer\PdfRendererInterface; use Setono\SyliusGiftCardPlugin\Resolver\CustomerChannelResolverInterface; use Setono\SyliusGiftCardPlugin\Resolver\LocaleResolverInterface; -use Sylius\Component\Channel\Model\ChannelInterface; use Sylius\Component\Core\Model\CustomerInterface; use Sylius\Component\Core\Model\OrderInterface; use Sylius\Component\Mailer\Sender\SenderInterface; @@ -52,7 +51,7 @@ public function sendEmailToCustomerWithGiftCard(CustomerInterface $customer, Gif public function sendEmailWithGiftCardsFromOrder(OrderInterface $order, array $giftCards): void { $customer = $order->getCustomer(); - if (!$customer instanceof \Sylius\Component\Customer\Model\CustomerInterface) { + if (null === $customer) { return; } @@ -62,7 +61,7 @@ public function sendEmailWithGiftCardsFromOrder(OrderInterface $order, array $gi } $channel = $order->getChannel(); - if (!$channel instanceof ChannelInterface) { + if (null === $channel) { return; } diff --git a/src/EventSubscriber/SendEmailWithGiftCardToCustomerSubscriber.php b/src/EventSubscriber/SendEmailWithGiftCardToCustomerSubscriber.php index 23ff3297..e36edfbb 100644 --- a/src/EventSubscriber/SendEmailWithGiftCardToCustomerSubscriber.php +++ b/src/EventSubscriber/SendEmailWithGiftCardToCustomerSubscriber.php @@ -7,7 +7,6 @@ use Setono\SyliusGiftCardPlugin\EmailManager\GiftCardEmailManagerInterface; use Setono\SyliusGiftCardPlugin\Model\GiftCardInterface; use Sylius\Bundle\ResourceBundle\Event\ResourceControllerEvent; -use Sylius\Component\Core\Model\CustomerInterface; use Sylius\Component\Resource\Exception\UnexpectedTypeException; use Symfony\Component\EventDispatcher\EventSubscriberInterface; @@ -31,12 +30,13 @@ public static function getSubscribedEvents(): array public function postCreate(ResourceControllerEvent $event): void { $giftCard = $event->getSubject(); + if (!$giftCard instanceof GiftCardInterface) { throw new UnexpectedTypeException($giftCard, GiftCardInterface::class); } $customer = $giftCard->getCustomer(); - if (!$customer instanceof CustomerInterface) { + if (null === $customer) { return; } diff --git a/src/Form/DataTransformer/GiftCardToCodeDataTransformer.php b/src/Form/DataTransformer/GiftCardToCodeDataTransformer.php index a109f1d1..482d21b4 100644 --- a/src/Form/DataTransformer/GiftCardToCodeDataTransformer.php +++ b/src/Form/DataTransformer/GiftCardToCodeDataTransformer.php @@ -46,7 +46,7 @@ public function reverseTransform($value): ?GiftCardInterface $this->channelContext->getChannel(), ); - if ($giftCard instanceof GiftCardInterface) { + if (null !== $giftCard) { return $giftCard; } diff --git a/src/Generator/GiftCardCodeGenerator.php b/src/Generator/GiftCardCodeGenerator.php index 61df4f85..ac7b301b 100644 --- a/src/Generator/GiftCardCodeGenerator.php +++ b/src/Generator/GiftCardCodeGenerator.php @@ -5,7 +5,6 @@ namespace Setono\SyliusGiftCardPlugin\Generator; use function preg_replace; -use Setono\SyliusGiftCardPlugin\Model\GiftCardInterface; use Setono\SyliusGiftCardPlugin\Repository\GiftCardRepositoryInterface; use Webmozart\Assert\Assert; @@ -31,7 +30,9 @@ public function generate(): string /** @psalm-suppress ArgumentTypeCoercion */ $code = bin2hex(random_bytes($this->codeLength)); $code = preg_replace('/[01]/', '', $code); // remove hard to read characters - $code = mb_strtoupper(mb_substr((string) $code, 0, $this->codeLength)); + Assert::string($code); + + $code = mb_strtoupper(mb_substr($code, 0, $this->codeLength)); } while (mb_strlen($code) !== $this->codeLength || $this->exists($code)); return $code; @@ -39,6 +40,6 @@ public function generate(): string private function exists(string $code): bool { - return $this->giftCardRepository->findOneByCode($code) instanceof GiftCardInterface; + return null !== $this->giftCardRepository->findOneByCode($code); } } diff --git a/src/Model/GiftCard.php b/src/Model/GiftCard.php index 2491a171..7ae941ee 100644 --- a/src/Model/GiftCard.php +++ b/src/Model/GiftCard.php @@ -77,7 +77,7 @@ public function getId(): ?int public function isDeletable(): bool { - return !$this->orderItemUnit instanceof OrderItemUnitInterface; + return null === $this->orderItemUnit; } public function getOrderItemUnit(): ?OrderItemUnitInterface @@ -99,7 +99,8 @@ public function setOrderItemUnit(OrderItemUnitInterface $orderItemUnit): void public function getOrder(): ?OrderInterface { $orderItemUnit = $this->getOrderItemUnit(); - if (!$orderItemUnit instanceof OrderItemUnitInterface) { + + if (null === $orderItemUnit) { return null; } @@ -216,7 +217,7 @@ public function setChannel(ChannelInterface $channel): void public function getCustomerIdentification(): ?array { $customer = $this->getCustomer(); - if (!$customer instanceof CustomerInterface) { + if (null === $customer) { return null; } @@ -229,7 +230,7 @@ public function getCustomerIdentification(): ?array public function getOrderIdentification(): ?array { $order = $this->getOrder(); - if (!$order instanceof OrderInterface) { + if (null === $order) { return null; } @@ -249,12 +250,7 @@ public function getOrderIdentification(): ?array public function getChannelCode(): ?string { - $channel = $this->getChannel(); - if (!$channel instanceof ChannelInterface) { - return null; - } - - return $channel->getCode(); + return $this->getChannel()?->getCode(); } public function hasOrderOrCustomer(): bool @@ -294,12 +290,12 @@ public function setExpiresAt(?DateTimeInterface $expiresAt): void public function isExpired(DateTimeInterface $date = null): bool { - if (!$date instanceof DateTimeInterface) { + if (null === $date) { $date = new DateTime(); } $giftCardValidUntil = $this->getExpiresAt(); - if (!$giftCardValidUntil instanceof DateTimeInterface) { + if (null === $giftCardValidUntil) { return false; } diff --git a/src/Modifier/OrderGiftCardAmountModifier.php b/src/Modifier/OrderGiftCardAmountModifier.php index 1d630e17..d88102ec 100644 --- a/src/Modifier/OrderGiftCardAmountModifier.php +++ b/src/Modifier/OrderGiftCardAmountModifier.php @@ -4,7 +4,6 @@ namespace Setono\SyliusGiftCardPlugin\Modifier; -use Doctrine\Persistence\ObjectManager; use RuntimeException; use Setono\SyliusGiftCardPlugin\Model\AdjustmentInterface; use Setono\SyliusGiftCardPlugin\Model\GiftCardInterface; @@ -16,10 +15,6 @@ */ final class OrderGiftCardAmountModifier implements OrderGiftCardAmountModifierInterface { - public function __construct(private readonly ObjectManager $giftCardManager) - { - } - public function decrement(OrderInterface $order): void { foreach ($order->getAdjustments(AdjustmentInterface::ORDER_GIFT_CARD_ADJUSTMENT) as $adjustment) { @@ -38,8 +33,6 @@ public function decrement(OrderInterface $order): void $giftCard->setAmount($giftCard->getAmount() - $amount); } } - - $this->giftCardManager->flush(); } public function increment(OrderInterface $order): void @@ -53,8 +46,6 @@ public function increment(OrderInterface $order): void $giftCard->enable(); } } - - $this->giftCardManager->flush(); } private function getGiftCard(OrderInterface $order, string $code): GiftCardInterface diff --git a/src/Provider/GiftCardConfigurationProvider.php b/src/Provider/GiftCardConfigurationProvider.php index 63ad379f..cd216e62 100644 --- a/src/Provider/GiftCardConfigurationProvider.php +++ b/src/Provider/GiftCardConfigurationProvider.php @@ -36,12 +36,12 @@ public function __construct( public function getConfiguration(BaseChannelInterface $channel, LocaleInterface $locale): GiftCardConfigurationInterface { $configuration = $this->giftCardConfigurationRepository->findOneByChannelAndLocale($channel, $locale); - if ($configuration instanceof GiftCardConfigurationInterface) { + if (null !== $configuration) { return $configuration; } $configuration = $this->giftCardConfigurationRepository->findDefault(); - if ($configuration instanceof GiftCardConfigurationInterface) { + if (null !== $configuration) { return $configuration; } @@ -65,7 +65,12 @@ public function getConfigurationForGiftCard(GiftCardInterface $giftCard): GiftCa try { $order = $giftCard->getOrder(); - $localeCode = $order instanceof OrderInterface ? $order->getLocaleCode() : $this->localeContext->getLocaleCode(); + + $localeCode = $this->localeContext->getLocaleCode(); + if ($order instanceof OrderInterface) { + $localeCode = $order->getLocaleCode(); + } + $locale = $this->localeRepository->findOneBy(['code' => $localeCode]); if (!$locale instanceof LocaleInterface) { throw new LocaleNotFoundException(); diff --git a/src/Renderer/PdfRenderer.php b/src/Renderer/PdfRenderer.php index e92a0be2..d1c37679 100644 --- a/src/Renderer/PdfRenderer.php +++ b/src/Renderer/PdfRenderer.php @@ -11,7 +11,6 @@ use Setono\SyliusGiftCardPlugin\Provider\PdfRenderingOptionsProviderInterface; use Sylius\Component\Channel\Context\ChannelContextInterface; use Sylius\Component\Channel\Model\ChannelInterface; -use Sylius\Component\Core\Model\OrderInterface; use Sylius\Component\Locale\Context\LocaleContextInterface; use Symfony\Component\Serializer\Normalizer\NormalizerInterface; use Twig\Environment; @@ -29,20 +28,20 @@ public function render( ChannelInterface $channel = null, string $localeCode = null, ): PdfResponse { - if (!$channel instanceof ChannelInterface) { + if (null === $channel) { $order = $giftCard->getOrder(); - if ($order instanceof OrderInterface) { + if (null !== $order) { $channel = $order->getChannel(); } - if (!$channel instanceof ChannelInterface) { + if (null === $channel) { $channel = $this->channelContext->getChannel(); } } if (null === $localeCode) { $order = $giftCard->getOrder(); - if ($order instanceof OrderInterface) { + if (null !== $order) { $localeCode = $order->getLocaleCode(); } @@ -51,7 +50,7 @@ public function render( } } - if (!$giftCardConfiguration instanceof GiftCardConfigurationInterface) { + if (null === $giftCardConfiguration) { $giftCardConfiguration = $this->configurationProvider->getConfigurationForGiftCard($giftCard); } diff --git a/src/Resolver/CustomerChannelResolver.php b/src/Resolver/CustomerChannelResolver.php index 7b347aab..51a2447c 100644 --- a/src/Resolver/CustomerChannelResolver.php +++ b/src/Resolver/CustomerChannelResolver.php @@ -5,7 +5,6 @@ namespace Setono\SyliusGiftCardPlugin\Resolver; use RuntimeException; -use Setono\SyliusGiftCardPlugin\Model\OrderInterface; use Setono\SyliusGiftCardPlugin\Repository\OrderRepositoryInterface; use Sylius\Component\Channel\Repository\ChannelRepositoryInterface; use Sylius\Component\Core\Model\ChannelInterface; @@ -20,9 +19,9 @@ public function __construct(private readonly OrderRepositoryInterface $orderRepo public function resolve(CustomerInterface $customer): ChannelInterface { $latestOrder = $this->orderRepository->findLatestByCustomer($customer); - if ($latestOrder instanceof OrderInterface) { + if (null !== $latestOrder) { $channel = $latestOrder->getChannel(); - if ($channel instanceof \Sylius\Component\Channel\Model\ChannelInterface) { + if (null !== $channel) { return $channel; } } diff --git a/src/Resolver/LocaleResolver.php b/src/Resolver/LocaleResolver.php index 95992623..82e4881d 100644 --- a/src/Resolver/LocaleResolver.php +++ b/src/Resolver/LocaleResolver.php @@ -10,7 +10,6 @@ use Sylius\Component\Core\Model\ChannelInterface; use Sylius\Component\Core\Model\CustomerInterface; use Sylius\Component\Core\Model\OrderInterface; -use Sylius\Component\Locale\Model\LocaleInterface; final class LocaleResolver implements LocaleResolverInterface { @@ -21,7 +20,7 @@ public function __construct(private readonly OrderRepositoryInterface $orderRepo public function resolveFromCustomer(CustomerInterface $customer): string { $latestOrder = $this->orderRepository->findLatestByCustomer($customer); - if ($latestOrder instanceof \Setono\SyliusGiftCardPlugin\Model\OrderInterface) { + if (null !== $latestOrder) { return $this->resolveFromOrder($latestOrder); } @@ -36,7 +35,7 @@ public function resolveFromOrder(OrderInterface $order): string } $channel = $order->getChannel(); - if ($channel instanceof \Sylius\Component\Channel\Model\ChannelInterface) { + if (null !== $channel) { return $this->resolveFromChannel($channel); } @@ -71,7 +70,7 @@ private function resolve(): string private function _resolveFromChannel(ChannelInterface $channel): ?string { $locale = $channel->getDefaultLocale(); - if ($locale instanceof LocaleInterface) { + if (null !== $locale) { $localeCode = $locale->getCode(); if (null !== $localeCode) { return $localeCode; diff --git a/src/Security/GiftCardVoter.php b/src/Security/GiftCardVoter.php index 1f0aee9b..65b3e4ea 100644 --- a/src/Security/GiftCardVoter.php +++ b/src/Security/GiftCardVoter.php @@ -7,7 +7,6 @@ use LogicException; use Setono\SyliusGiftCardPlugin\Model\GiftCardInterface; use Sylius\Component\Core\Model\AdminUserInterface; -use Sylius\Component\Core\Model\CustomerInterface; use Sylius\Component\Core\Model\ShopUserInterface; use Sylius\Component\User\Model\UserInterface; use Symfony\Component\Security\Core\Authentication\Token\TokenInterface; @@ -52,7 +51,7 @@ protected function voteOnAttribute(string $attribute, mixed $subject, TokenInter private function canRead(GiftCardInterface $giftCard, ShopUserInterface $user): bool { // Anonymous gift cards can be seen by everyone - if (!$giftCard->getCustomer() instanceof CustomerInterface) { + if (null === $giftCard->getCustomer()) { return true; } diff --git a/src/Serializer/Normalizer/GiftCardConfigurationNormalizer.php b/src/Serializer/Normalizer/GiftCardConfigurationNormalizer.php index 27591c27..acbb5050 100644 --- a/src/Serializer/Normalizer/GiftCardConfigurationNormalizer.php +++ b/src/Serializer/Normalizer/GiftCardConfigurationNormalizer.php @@ -6,7 +6,6 @@ use ArrayObject; use Setono\SyliusGiftCardPlugin\Exception\UnexpectedTypeException; -use Setono\SyliusGiftCardPlugin\Model\GiftCardConfigurationImageInterface; use Setono\SyliusGiftCardPlugin\Model\GiftCardConfigurationInterface; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\RequestStack; @@ -46,12 +45,12 @@ public function normalize($object, $format = null, array $context = []): array $data['image'] = ''; $request = $this->requestStack->getMainRequest(); - if ($request instanceof Request) { + if (null !== $request) { $data['image'] = $request->getSchemeAndHttpHost() . '/bundles/setonosyliusgiftcardplugin/setono-logo.png'; } $image = $object->getBackgroundImage(); - if (!$image instanceof GiftCardConfigurationImageInterface) { + if (null === $image) { return $data; } diff --git a/src/Validator/Constraints/DefaultGiftCardConfigurationMustExistValidator.php b/src/Validator/Constraints/DefaultGiftCardConfigurationMustExistValidator.php index 74e43331..4625fce0 100644 --- a/src/Validator/Constraints/DefaultGiftCardConfigurationMustExistValidator.php +++ b/src/Validator/Constraints/DefaultGiftCardConfigurationMustExistValidator.php @@ -34,7 +34,7 @@ public function validate($value, Constraint $constraint): void } $defaultGiftCardConfiguration = $this->giftCardConfigurationRepository->findDefault(); - if (!$defaultGiftCardConfiguration instanceof GiftCardConfigurationInterface || $defaultGiftCardConfiguration->getId() === $value->getId()) { + if (null === $defaultGiftCardConfiguration || $defaultGiftCardConfiguration->getId() === $value->getId()) { $this->context->buildViolation($constraint->message) ->atPath('default') ->addViolation() diff --git a/src/Validator/Constraints/HasBackgroundImageValidator.php b/src/Validator/Constraints/HasBackgroundImageValidator.php index 28d2076c..1efd72a7 100644 --- a/src/Validator/Constraints/HasBackgroundImageValidator.php +++ b/src/Validator/Constraints/HasBackgroundImageValidator.php @@ -4,9 +4,7 @@ namespace Setono\SyliusGiftCardPlugin\Validator\Constraints; -use Setono\SyliusGiftCardPlugin\Model\GiftCardConfigurationImageInterface; use Setono\SyliusGiftCardPlugin\Model\GiftCardConfigurationInterface; -use SplFileInfo; use Symfony\Component\Validator\Constraint; use Symfony\Component\Validator\ConstraintValidator; use Symfony\Component\Validator\Exception\UnexpectedTypeException; @@ -28,11 +26,11 @@ public function validate($value, Constraint $constraint): void $backgroundImage = $value->getBackgroundImage(); - if (!$backgroundImage instanceof GiftCardConfigurationImageInterface) { + if (null === $backgroundImage) { return; } - if (!$backgroundImage->getFile() instanceof SplFileInfo && null === $backgroundImage->getPath()) { + if (null === $backgroundImage->getFile() && null === $backgroundImage->getPath()) { $this->context->buildViolation($constraint->message) ->addViolation(); } diff --git a/tests/Application/config/bundles.php b/tests/Application/config/bundles.php index 526f9d10..a60ea358 100644 --- a/tests/Application/config/bundles.php +++ b/tests/Application/config/bundles.php @@ -2,124 +2,66 @@ declare(strict_types=1); -use ApiPlatform\Core\Bridge\Symfony\Bundle\ApiPlatformBundle; -use BabDev\PagerfantaBundle\BabDevPagerfantaBundle; -use Bazinga\Bundle\HateoasBundle\BazingaHateoasBundle; -use Doctrine\Bundle\DoctrineBundle\DoctrineBundle; -use Doctrine\Bundle\MigrationsBundle\DoctrineMigrationsBundle; -use FOS\RestBundle\FOSRestBundle; -use FriendsOfBehat\SymfonyExtension\Bundle\FriendsOfBehatSymfonyExtensionBundle; -use JMS\SerializerBundle\JMSSerializerBundle; -use Knp\Bundle\GaufretteBundle\KnpGaufretteBundle; -use Knp\Bundle\MenuBundle\KnpMenuBundle; -use Knp\Bundle\SnappyBundle\KnpSnappyBundle; -use League\FlysystemBundle\FlysystemBundle; -use Lexik\Bundle\JWTAuthenticationBundle\LexikJWTAuthenticationBundle; -use Liip\ImagineBundle\LiipImagineBundle; -use Payum\Bundle\PayumBundle\PayumBundle; -use Setono\SyliusGiftCardPlugin\SetonoSyliusGiftCardPlugin; -use Sonata\BlockBundle\SonataBlockBundle; -use Stof\DoctrineExtensionsBundle\StofDoctrineExtensionsBundle; -use Sylius\Bundle\AddressingBundle\SyliusAddressingBundle; -use Sylius\Bundle\AdminBundle\SyliusAdminBundle; -use Sylius\Bundle\ApiBundle\SyliusApiBundle; -use Sylius\Bundle\AttributeBundle\SyliusAttributeBundle; -use Sylius\Bundle\ChannelBundle\SyliusChannelBundle; -use Sylius\Bundle\CoreBundle\SyliusCoreBundle; -use Sylius\Bundle\CurrencyBundle\SyliusCurrencyBundle; -use Sylius\Bundle\CustomerBundle\SyliusCustomerBundle; -use Sylius\Bundle\FixturesBundle\SyliusFixturesBundle; -use Sylius\Bundle\GridBundle\SyliusGridBundle; -use Sylius\Bundle\InventoryBundle\SyliusInventoryBundle; -use Sylius\Bundle\LocaleBundle\SyliusLocaleBundle; -use Sylius\Bundle\MailerBundle\SyliusMailerBundle; -use Sylius\Bundle\MoneyBundle\SyliusMoneyBundle; -use Sylius\Bundle\OrderBundle\SyliusOrderBundle; -use Sylius\Bundle\PaymentBundle\SyliusPaymentBundle; -use Sylius\Bundle\PayumBundle\SyliusPayumBundle; -use Sylius\Bundle\ProductBundle\SyliusProductBundle; -use Sylius\Bundle\PromotionBundle\SyliusPromotionBundle; -use Sylius\Bundle\ResourceBundle\SyliusResourceBundle; -use Sylius\Bundle\ReviewBundle\SyliusReviewBundle; -use Sylius\Bundle\ShippingBundle\SyliusShippingBundle; -use Sylius\Bundle\ShopBundle\SyliusShopBundle; -use Sylius\Bundle\TaxationBundle\SyliusTaxationBundle; -use Sylius\Bundle\TaxonomyBundle\SyliusTaxonomyBundle; -use Sylius\Bundle\ThemeBundle\SyliusThemeBundle; -use Sylius\Bundle\UiBundle\SyliusUiBundle; -use Sylius\Bundle\UserBundle\SyliusUserBundle; -use Sylius\Calendar\SyliusCalendarBundle; -use SyliusLabs\DoctrineMigrationsExtraBundle\SyliusLabsDoctrineMigrationsExtraBundle; -use SyliusLabs\Polyfill\Symfony\Security\Bundle\SyliusLabsPolyfillSymfonySecurityBundle; -use Symfony\Bundle\DebugBundle\DebugBundle; -use Symfony\Bundle\FrameworkBundle\FrameworkBundle; -use Symfony\Bundle\MonologBundle\MonologBundle; -use Symfony\Bundle\SecurityBundle\SecurityBundle; -use Symfony\Bundle\TwigBundle\TwigBundle; -use Symfony\Bundle\WebProfilerBundle\WebProfilerBundle; -use Symfony\WebpackEncoreBundle\WebpackEncoreBundle; -use winzou\Bundle\StateMachineBundle\winzouStateMachineBundle; - return [ - FrameworkBundle::class => ['all' => true], - MonologBundle::class => ['all' => true], - SecurityBundle::class => ['all' => true], - TwigBundle::class => ['all' => true], - DoctrineBundle::class => ['all' => true], - SyliusOrderBundle::class => ['all' => true], - SyliusMoneyBundle::class => ['all' => true], - SyliusCurrencyBundle::class => ['all' => true], - SyliusLocaleBundle::class => ['all' => true], - SyliusProductBundle::class => ['all' => true], - SyliusChannelBundle::class => ['all' => true], - SyliusAttributeBundle::class => ['all' => true], - SyliusTaxationBundle::class => ['all' => true], - SyliusShippingBundle::class => ['all' => true], - SyliusPaymentBundle::class => ['all' => true], - SyliusMailerBundle::class => ['all' => true], - SyliusPromotionBundle::class => ['all' => true], - SyliusAddressingBundle::class => ['all' => true], - SyliusInventoryBundle::class => ['all' => true], - SyliusTaxonomyBundle::class => ['all' => true], - SyliusUserBundle::class => ['all' => true], - SyliusCustomerBundle::class => ['all' => true], - SyliusUiBundle::class => ['all' => true], - SyliusReviewBundle::class => ['all' => true], - SyliusCoreBundle::class => ['all' => true], - SyliusResourceBundle::class => ['all' => true], + Symfony\Bundle\FrameworkBundle\FrameworkBundle::class => ['all' => true], + Symfony\Bundle\MonologBundle\MonologBundle::class => ['all' => true], + Symfony\Bundle\SecurityBundle\SecurityBundle::class => ['all' => true], + Symfony\Bundle\TwigBundle\TwigBundle::class => ['all' => true], + Doctrine\Bundle\DoctrineBundle\DoctrineBundle::class => ['all' => true], + Sylius\Bundle\OrderBundle\SyliusOrderBundle::class => ['all' => true], + Sylius\Bundle\MoneyBundle\SyliusMoneyBundle::class => ['all' => true], + Sylius\Bundle\CurrencyBundle\SyliusCurrencyBundle::class => ['all' => true], + Sylius\Bundle\LocaleBundle\SyliusLocaleBundle::class => ['all' => true], + Sylius\Bundle\ProductBundle\SyliusProductBundle::class => ['all' => true], + Sylius\Bundle\ChannelBundle\SyliusChannelBundle::class => ['all' => true], + Sylius\Bundle\AttributeBundle\SyliusAttributeBundle::class => ['all' => true], + Sylius\Bundle\TaxationBundle\SyliusTaxationBundle::class => ['all' => true], + Sylius\Bundle\ShippingBundle\SyliusShippingBundle::class => ['all' => true], + Sylius\Bundle\PaymentBundle\SyliusPaymentBundle::class => ['all' => true], + Sylius\Bundle\MailerBundle\SyliusMailerBundle::class => ['all' => true], + Sylius\Bundle\PromotionBundle\SyliusPromotionBundle::class => ['all' => true], + Sylius\Bundle\AddressingBundle\SyliusAddressingBundle::class => ['all' => true], + Sylius\Bundle\InventoryBundle\SyliusInventoryBundle::class => ['all' => true], + Sylius\Bundle\TaxonomyBundle\SyliusTaxonomyBundle::class => ['all' => true], + Sylius\Bundle\UserBundle\SyliusUserBundle::class => ['all' => true], + Sylius\Bundle\CustomerBundle\SyliusCustomerBundle::class => ['all' => true], + Sylius\Bundle\UiBundle\SyliusUiBundle::class => ['all' => true], + Sylius\Bundle\ReviewBundle\SyliusReviewBundle::class => ['all' => true], + Sylius\Bundle\CoreBundle\SyliusCoreBundle::class => ['all' => true], + Sylius\Bundle\ResourceBundle\SyliusResourceBundle::class => ['all' => true], // Begin: In test app, those 3 needs to be loaded before our plugin or the Api Resource override won't work - LexikJWTAuthenticationBundle::class => ['all' => true], - ApiPlatformBundle::class => ['all' => true], - SyliusApiBundle::class => ['all' => true], + Lexik\Bundle\JWTAuthenticationBundle\LexikJWTAuthenticationBundle::class => ['all' => true], + ApiPlatform\Core\Bridge\Symfony\Bundle\ApiPlatformBundle::class => ['all' => true], + Sylius\Bundle\ApiBundle\SyliusApiBundle::class => ['all' => true], // End: In test app, those 3 needs to be loaded before our plugin or the Api Resource override won't work - winzouStateMachineBundle::class => ['all' => true], - SonataBlockBundle::class => ['all' => true], - BazingaHateoasBundle::class => ['all' => true], - JMSSerializerBundle::class => ['all' => true], - FOSRestBundle::class => ['all' => true], - KnpGaufretteBundle::class => ['all' => true], - KnpMenuBundle::class => ['all' => true], - FlysystemBundle::class => ['all' => true], - LiipImagineBundle::class => ['all' => true], - PayumBundle::class => ['all' => true], - StofDoctrineExtensionsBundle::class => ['all' => true], - DoctrineMigrationsBundle::class => ['all' => true], - SyliusFixturesBundle::class => ['all' => true], - SyliusPayumBundle::class => ['all' => true], - SyliusThemeBundle::class => ['all' => true], - SyliusAdminBundle::class => ['all' => true], - SyliusShopBundle::class => ['all' => true], - DebugBundle::class => ['dev' => true, 'test' => true], - WebProfilerBundle::class => ['dev' => true, 'test' => true], - FriendsOfBehatSymfonyExtensionBundle::class => ['test' => true], - KnpSnappyBundle::class => ['all' => true], - SyliusLabsDoctrineMigrationsExtraBundle::class => ['all' => true], - BabDevPagerfantaBundle::class => ['all' => true], - SyliusLabsPolyfillSymfonySecurityBundle::class => ['all' => true], - WebpackEncoreBundle::class => ['all' => true], - SyliusCalendarBundle::class => ['all' => true], - SetonoSyliusGiftCardPlugin::class => ['all' => true], - SyliusGridBundle::class => ['all' => true], + winzou\Bundle\StateMachineBundle\winzouStateMachineBundle::class => ['all' => true], + Sonata\BlockBundle\SonataBlockBundle::class => ['all' => true], + Bazinga\Bundle\HateoasBundle\BazingaHateoasBundle::class => ['all' => true], + JMS\SerializerBundle\JMSSerializerBundle::class => ['all' => true], + FOS\RestBundle\FOSRestBundle::class => ['all' => true], + Knp\Bundle\GaufretteBundle\KnpGaufretteBundle::class => ['all' => true], + Knp\Bundle\MenuBundle\KnpMenuBundle::class => ['all' => true], + League\FlysystemBundle\FlysystemBundle::class => ['all' => true], + Liip\ImagineBundle\LiipImagineBundle::class => ['all' => true], + Payum\Bundle\PayumBundle\PayumBundle::class => ['all' => true], + Stof\DoctrineExtensionsBundle\StofDoctrineExtensionsBundle::class => ['all' => true], + Doctrine\Bundle\MigrationsBundle\DoctrineMigrationsBundle::class => ['all' => true], + Sylius\Bundle\FixturesBundle\SyliusFixturesBundle::class => ['all' => true], + Sylius\Bundle\PayumBundle\SyliusPayumBundle::class => ['all' => true], + Sylius\Bundle\ThemeBundle\SyliusThemeBundle::class => ['all' => true], + Sylius\Bundle\AdminBundle\SyliusAdminBundle::class => ['all' => true], + Sylius\Bundle\ShopBundle\SyliusShopBundle::class => ['all' => true], + Symfony\Bundle\DebugBundle\DebugBundle::class => ['dev' => true, 'test' => true], + Symfony\Bundle\WebProfilerBundle\WebProfilerBundle::class => ['dev' => true, 'test' => true], + FriendsOfBehat\SymfonyExtension\Bundle\FriendsOfBehatSymfonyExtensionBundle::class => ['test' => true], + Knp\Bundle\SnappyBundle\KnpSnappyBundle::class => ['all' => true], + SyliusLabs\DoctrineMigrationsExtraBundle\SyliusLabsDoctrineMigrationsExtraBundle::class => ['all' => true], + BabDev\PagerfantaBundle\BabDevPagerfantaBundle::class => ['all' => true], + SyliusLabs\Polyfill\Symfony\Security\Bundle\SyliusLabsPolyfillSymfonySecurityBundle::class => ['all' => true], + Symfony\WebpackEncoreBundle\WebpackEncoreBundle::class => ['all' => true], + Sylius\Calendar\SyliusCalendarBundle::class => ['all' => true], + Setono\SyliusGiftCardPlugin\SetonoSyliusGiftCardPlugin::class => ['all' => true], + Sylius\Bundle\GridBundle\SyliusGridBundle::class => ['all' => true], ]; diff --git a/tests/Behat/Context/Setup/GiftCardContext.php b/tests/Behat/Context/Setup/GiftCardContext.php index 2ba03f01..ef85b2ff 100644 --- a/tests/Behat/Context/Setup/GiftCardContext.php +++ b/tests/Behat/Context/Setup/GiftCardContext.php @@ -53,7 +53,7 @@ public function theStoreHasGiftCardWithCode( int $price, ?ChannelInterface $channel = null, ): void { - if (!$channel instanceof ChannelInterface) { + if (null === $channel) { /** @var ChannelInterface $channel */ $channel = $this->sharedStorage->get('channel'); } @@ -95,6 +95,7 @@ public function theStoreHasGiftCardWithCodeForCustomer( */ public function iApplyGiftCardToOrder(string $code): void { + /** @var string $cartToken */ $cartToken = $this->sharedStorage->get('cart_token'); $message = new AddGiftCardToOrder($cartToken); $message->setGiftCardCode($code); From 36e4fb4a13d648a936f76837bf5c6072427d8b89 Mon Sep 17 00:00:00 2001 From: Ibes Date: Sun, 13 Oct 2024 18:49:39 +0200 Subject: [PATCH 06/15] issue #261 fix, thanks to @TalkMarc --- .../CommandHandler/AddItemToCartHandler.php | 18 ++++++++++++++++-- .../AddItemToCartHandlerTest.php | 1 - 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/Api/CommandHandler/AddItemToCartHandler.php b/src/Api/CommandHandler/AddItemToCartHandler.php index 22652031..2cdf6c9e 100644 --- a/src/Api/CommandHandler/AddItemToCartHandler.php +++ b/src/Api/CommandHandler/AddItemToCartHandler.php @@ -43,10 +43,13 @@ public function __invoke(SyliusAddItemToCart $addItemToCart): OrderInterface $cartItem = $this->cartItemFactory->createNew(); $cartItem->setVariant($productVariant); - if ($addItemToCart instanceof SetonoSyliusGiftCardAddItemToCart) { + if ($this->isGiftCard($addItemToCart, $productVariant)) { /** @var ProductInterface $product */ $product = $productVariant->getProduct(); if ($product->isGiftCardAmountConfigurable()) { + /** @var SetonoSyliusGiftCardAddItemToCart $addItemToCart */ + $addItemToCart = $addItemToCart; + /** @var int|null $giftCardAmount */ $giftCardAmount = $addItemToCart->getAmount(); Assert::notNull($giftCardAmount); $cartItem->setUnitPrice($giftCardAmount); @@ -57,10 +60,12 @@ public function __invoke(SyliusAddItemToCart $addItemToCart): OrderInterface $this->orderItemQuantityModifier->modify($cartItem, $addItemToCart->quantity); $this->orderModifier->addToOrder($cart, $cartItem); - if ($addItemToCart instanceof SetonoSyliusGiftCardAddItemToCart) { + if ($this->isGiftCard($addItemToCart, $productVariant)) { /** @var OrderItemUnitInterface $unit */ foreach ($cartItem->getUnits() as $unit) { $giftCard = $this->giftCardFactory->createFromOrderItemUnitAndCart($unit, $cart); + /** @var SetonoSyliusGiftCardAddItemToCart $addItemToCart */ + $addItemToCart = $addItemToCart; $giftCard->setCustomMessage($addItemToCart->getCustomMessage()); // As the common flow for any add to cart action will flush later. Do not flush here. @@ -70,4 +75,13 @@ public function __invoke(SyliusAddItemToCart $addItemToCart): OrderInterface return $cart; } + + private function isGiftCard(SyliusAddItemToCart $addItemToCart, ProductVariantInterface $productVariant): bool + { + $product = $productVariant->getProduct(); + + return $addItemToCart instanceof SetonoSyliusGiftCardAddItemToCart && + $product instanceof ProductInterface && + $product->isGiftCard(); + } } diff --git a/tests/Unit/Api/CommandHandler/AddItemToCartHandlerTest.php b/tests/Unit/Api/CommandHandler/AddItemToCartHandlerTest.php index ea9c923d..d833b44b 100644 --- a/tests/Unit/Api/CommandHandler/AddItemToCartHandlerTest.php +++ b/tests/Unit/Api/CommandHandler/AddItemToCartHandlerTest.php @@ -146,7 +146,6 @@ public function it_adds_simple_item_to_cart(): void ->createNew() ->willReturn($cartItem); - $productVariant->getProduct()->shouldNotBeCalled(); $orderItemQuantityModifier->modify($cartItem, 1)->shouldBeCalled(); $orderModifier->addToOrder($cart, $cartItem)->shouldBeCalled(); From a6017afc60f318d73746841dbb99b3842cf27956 Mon Sep 17 00:00:00 2001 From: Ibes Date: Mon, 14 Oct 2024 17:13:43 +0200 Subject: [PATCH 07/15] ecs fix --- tests/Unit/Api/CommandHandler/AddItemToCartHandlerTest.php | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/Unit/Api/CommandHandler/AddItemToCartHandlerTest.php b/tests/Unit/Api/CommandHandler/AddItemToCartHandlerTest.php index d833b44b..258687bd 100644 --- a/tests/Unit/Api/CommandHandler/AddItemToCartHandlerTest.php +++ b/tests/Unit/Api/CommandHandler/AddItemToCartHandlerTest.php @@ -146,7 +146,6 @@ public function it_adds_simple_item_to_cart(): void ->createNew() ->willReturn($cartItem); - $orderItemQuantityModifier->modify($cartItem, 1)->shouldBeCalled(); $orderModifier->addToOrder($cart, $cartItem)->shouldBeCalled(); From 3609d984ea512e547ddddf2ba4710905af5624d0 Mon Sep 17 00:00:00 2001 From: Nicolo Singer Date: Tue, 18 Mar 2025 10:18:01 -0500 Subject: [PATCH 08/15] chore: ser versions in composer to support sylius 2.x and symfony 7.x Signed-off-by: Nicolo Singer --- composer.json | 92 +++++++++++++++++++++++++++------------------------ 1 file changed, 48 insertions(+), 44 deletions(-) diff --git a/composer.json b/composer.json index aa5f479d..b5a90f76 100644 --- a/composer.json +++ b/composer.json @@ -7,8 +7,8 @@ "php": ">=8.1", "ext-filter": "*", "ext-mbstring": "*", - "api-platform/core": "^2.6", - "doctrine/collections": "^1.8", + "api-platform/core": "^4.0", + "doctrine/collections": "^2.2", "doctrine/dbal": "^2.13 || ^3.0", "doctrine/orm": "^2.7", "doctrine/persistence": "^1.3 || ^2.5 || ^3.0", @@ -17,54 +17,54 @@ "knplabs/knp-snappy": "^1.4", "knplabs/knp-snappy-bundle": "^1.9", "setono/doctrine-object-manager-trait": "^1.1", - "sylius/api-bundle": "^1.10", - "sylius/channel": "^1.0", - "sylius/channel-bundle": "^1.0", - "sylius/core": "^1.0", - "sylius/core-bundle": "^1.0", - "sylius/currency": "^1.0", - "sylius/customer": "^1.0", + "sylius/api-bundle": "^2.0", + "sylius/channel": "^2.0", + "sylius/channel-bundle": "^2.0", + "sylius/core": "^2.0", + "sylius/core-bundle": "^2.0", + "sylius/currency": "^2.0", + "sylius/customer": "^2.0", "sylius/grid-bundle": "^1.0", - "sylius/locale": "^1.0", - "sylius/locale-bundle": "^1.0", + "sylius/locale": "^2.0", + "sylius/locale-bundle": "^2.0", "sylius/mailer-bundle": "^1.6 || ^2.0", - "sylius/money-bundle": "^1.0", - "sylius/order": "^1.10", - "sylius/order-bundle": "^1.0", - "sylius/product": "^1.0", - "sylius/product-bundle": "^1.0", - "sylius/promotion": "^1.0", + "sylius/money-bundle": "^2.0", + "sylius/order": "^2.0", + "sylius/order-bundle": "^2.0", + "sylius/product": "^2.0", + "sylius/product-bundle": "^2.0", + "sylius/promotion": "^2.0", "sylius/resource-bundle": "^1.8", - "sylius/shipping-bundle": "^1.0", - "sylius/ui-bundle": "^1.0", - "sylius/user": "^1.0", - "symfony/config": "^5.4 || ^6.4", - "symfony/dependency-injection": "^5.4 || ^6.4", - "symfony/event-dispatcher": "^5.4 || ^6.4", - "symfony/form": "^5.4 || ^6.4", - "symfony/http-foundation": "^5.4 || ^6.4", - "symfony/http-kernel": "^5.4 || ^6.4", - "symfony/messenger": "^5.4 || ^6.4", - "symfony/options-resolver": "^5.4 || ^6.4", - "symfony/property-access": "^5.4 || ^6.4", - "symfony/routing": "^5.4 || ^6.4", - "symfony/security-core": "^5.4 || ^6.4", - "symfony/serializer": "^5.4 || ^6.4", - "symfony/translation-contracts": "^2.4", - "symfony/validator": "^5.4 || ^6.4", + "sylius/shipping-bundle": "^2.0", + "sylius/ui-bundle": "^2.0", + "sylius/user": "^2.0", + "symfony/config": "^6.4 || ^7.0", + "symfony/dependency-injection": "^6.4 || ^7.0", + "symfony/event-dispatcher": "^6.4 || ^7.0", + "symfony/form": "^6.4 || ^7.0", + "symfony/http-foundation": "^6.4 || ^7.0", + "symfony/http-kernel": "^6.4 || ^7.0", + "symfony/messenger": "^6.4 || ^7.0", + "symfony/options-resolver": "^6.4 || ^7.0", + "symfony/property-access": "^6.4 || ^7.0", + "symfony/routing": "^6.4 || ^7.0", + "symfony/security-core": "^6.4 || ^7.0", + "symfony/serializer": "^6.4 || ^7.0", + "symfony/translation-contracts": "^2.4 || ^3.5", + "symfony/validator": "^6.4 || ^7.0", "twig/twig": "^2.15 || ^3.5", "webimpress/safe-writer": "^2.2", "webmozart/assert": "^1.11" }, "require-dev": { - "babdev/pagerfanta-bundle": "^3.8", + "babdev/pagerfanta-bundle": "^4.4", "behat/behat": "^3.14", "dmore/behat-chrome-extension": "^1.4", "dmore/chrome-mink-driver": "^2.9", "doctrine/doctrine-bundle": "^2.7", "infection/infection": "^0.27.10", "jms/serializer-bundle": "^4.2", - "lexik/jwt-authentication-bundle": "^2.17", + "lexik/jwt-authentication-bundle": "^3.1", "matthiasnoback/symfony-config-test": "^4.3 || ^5.1", "matthiasnoback/symfony-dependency-injection-test": "^4.3 || ^5.1", "php-http/message-factory": "^1.1", @@ -76,14 +76,14 @@ "psalm/plugin-symfony": "^5.0", "setono/code-quality-pack": "^2.7", "setono/sylius-behat-pack": "^0.2.2", - "sylius/sylius": "~1.12.13", + "sylius/sylius": "~2.0.5", "sylius/sylius-rector": "^2.0", - "symfony/debug-bundle": "^5.4 || ^6.4", - "symfony/dotenv": "^5.4 || ^6.4", - "symfony/intl": "^5.4 || ^6.4", - "symfony/property-info": "^5.4 || ^6.4", - "symfony/web-profiler-bundle": "^5.4 || ^6.4", - "symfony/webpack-encore-bundle": "^1.17.2", + "symfony/debug-bundle": "^6.4 || ^7.0", + "symfony/dotenv": "^6.4 || ^7.0", + "symfony/intl": "^6.4 || ^7.0", + "symfony/property-info": "^6.4 || ^7.0", + "symfony/web-profiler-bundle": "^6.4 || ^7.0", + "symfony/webpack-encore-bundle": "^1.17.2 || ^2.2.0", "weirdan/doctrine-psalm-plugin": "^2.9", "willdurand/negotiation": "^3.1" }, @@ -106,9 +106,13 @@ "dealerdirect/phpcodesniffer-composer-installer": false, "ergebnis/composer-normalize": true, "infection/extension-installer": true, + "php-http/discovery": true, "symfony/thanks": false }, - "sort-packages": true + "sort-packages": true, + "platform": { + "php": "8.3.99" + } }, "scripts": { "analyse": "psalm", From c8845b52f862ee07802b60c30384728456968652 Mon Sep 17 00:00:00 2001 From: Nicolo Singer Date: Tue, 18 Mar 2025 11:01:16 -0500 Subject: [PATCH 09/15] chore: rector annotations to attributes Signed-off-by: Nicolo Singer --- rector.php | 15 ++ src/Applicator/GiftCardApplicator.php | 5 +- src/EmailManager/GiftCardEmailManager.php | 5 +- ...dEmailWithGiftCardToCustomerSubscriber.php | 3 +- .../GiftCardToCodeDataTransformer.php | 2 +- src/Generator/GiftCardCodeGenerator.php | 3 +- src/Model/GiftCard.php | 12 +- src/Model/OrderItemUnitTrait.php | 2 +- src/Model/OrderTrait.php | 7 +- src/Model/ProductTrait.php | 4 +- .../GiftCardConfigurationProvider.php | 4 +- src/Renderer/PdfRenderer.php | 11 +- src/Resolver/CustomerChannelResolver.php | 5 +- src/Resolver/LocaleResolver.php | 7 +- src/Security/GiftCardVoter.php | 3 +- .../GiftCardConfigurationNormalizer.php | 5 +- ...iftCardConfigurationMustExistValidator.php | 2 +- .../HasBackgroundImageValidator.php | 6 +- tests/Application/Model/Order.php | 8 +- tests/Application/Model/OrderItem.php | 8 +- tests/Application/Model/OrderItemUnit.php | 8 +- tests/Application/Model/Product.php | 8 +- tests/Application/config/bundles.php | 172 ++++++++++++------ tests/Behat/Context/Setup/GiftCardContext.php | 2 +- .../Api/Command/AddGiftCardToOrderTest.php | 9 +- tests/Unit/Api/Command/AddItemToCartTest.php | 17 +- .../AssociateConfigurationToChannelTest.php | 9 +- .../CreateGiftCardConfigurationTest.php | 21 +-- .../Command/RemoveGiftCardFromOrderTest.php | 9 +- .../AddGiftCardToOrderHandlerTest.php | 17 +- .../AddItemToCartHandlerTest.php | 17 +- ...ciateConfigurationToChannelHandlerTest.php | 25 +-- ...CreateGiftCardConfigurationHandlerTest.php | 13 +- .../RemoveGiftCardFromOrderHandlerTest.php | 17 +- .../Action/DownloadGiftCardPdfActionTest.php | 5 +- .../Action/GiftCardBalanceActionTest.php | 5 +- .../Action/ResendGiftCardEmailActionTest.php | 13 +- ...adGiftCardConfigurationImageActionTest.php | 21 +-- .../GiftCardDataPersisterTest.php | 13 +- ...deAwareInputCommandDataTransformerTest.php | 9 +- .../GiftCardsByLoggedInUserExtensionTest.php | 17 +- .../GenerateEncodedExamplePdfActionTest.php | 5 +- .../DependencyInjection/ConfigurationTest.php | 5 +- .../SetonoSyliusGiftCardExtensionTest.php | 5 +- ...ultGiftCardConfigurationSubscriberTest.php | 9 +- ...ilWithGiftCardToCustomerSubscriberTest.php | 17 +- .../GiftCardConfigurationFactoryTest.php | 5 +- tests/Unit/Factory/GiftCardFactoryTest.php | 29 +-- .../Extension/AddToCartTypeExtensionTest.php | 9 +- tests/Unit/Form/Type/DatePeriodTypeTest.php | 5 +- .../Generator/GiftCardCodeGeneratorTest.php | 5 +- .../Unit/Model/GiftCardConfigurationTest.php | 5 +- tests/Unit/Model/GiftCardTest.php | 41 ++--- tests/Unit/Model/ProductTraitTest.php | 5 +- tests/Unit/Operator/GiftCardOperatorTest.php | 17 +- tests/Unit/Order/AddToCartCommandTest.php | 5 +- .../Factory/AddToCardCommandFactoryTest.php | 5 +- .../GiftCardInformationFactoryTest.php | 5 +- tests/Unit/Order/GiftCardInformationTest.php | 13 +- .../OrderGiftCardProcessorTest.php | 9 +- .../Provider/DatePeriodUnitProviderTest.php | 5 +- .../OrderEligibleTotalProviderTest.php | 5 +- .../PdfRenderingOptionProviderTest.php | 13 +- tests/Unit/Twig/Extension/PdfRuntimeTest.php | 5 +- .../Constraints/DatePeriodValidatorTest.php | 13 +- .../GiftCardIsNotExpiredValidatorTest.php | 9 +- .../HasBackgroundImageValidatorTest.php | 9 +- .../Pdf/ValidOrientationValidatorTest.php | 13 +- .../Pdf/ValidPageSizeValidatorTest.php | 13 +- 69 files changed, 354 insertions(+), 474 deletions(-) diff --git a/rector.php b/rector.php index a7acd5fa..338c4986 100644 --- a/rector.php +++ b/rector.php @@ -3,8 +3,14 @@ declare(strict_types=1); use Rector\Config\RectorConfig; +use Rector\Doctrine\Set\DoctrineSetList; +use Rector\PHPUnit\Set\PHPUnitSetList; use Rector\Set\ValueObject\LevelSetList; use Rector\Set\ValueObject\SetList; +use Rector\Symfony\Set\FOSRestSetList; +use Rector\Symfony\Set\JMSSetList; +use Rector\Symfony\Set\SensiolabsSetList; +use Rector\Symfony\Set\SymfonySetList; return static function (RectorConfig $rectorConfig): void { $rectorConfig->importNames(); @@ -12,6 +18,7 @@ $rectorConfig->paths([ __DIR__ . '/src', __DIR__ . '/tests', + __DIR__ . '/rector.php', ]); $rectorConfig->skip([ @@ -21,5 +28,13 @@ $rectorConfig->sets([ LevelSetList::UP_TO_PHP_81, // Adapt this to your PHP version SetList::CODE_QUALITY, + SymfonySetList::ANNOTATIONS_TO_ATTRIBUTES, + DoctrineSetList::ANNOTATIONS_TO_ATTRIBUTES, + DoctrineSetList::MONGODB__ANNOTATIONS_TO_ATTRIBUTES, + DoctrineSetList::GEDMO_ANNOTATIONS_TO_ATTRIBUTES, + PHPUnitSetList::ANNOTATIONS_TO_ATTRIBUTES, + FOSRestSetList::ANNOTATIONS_TO_ATTRIBUTES, + JMSSetList::ANNOTATIONS_TO_ATTRIBUTES, + SensiolabsSetList::ANNOTATIONS_TO_ATTRIBUTES, ]); }; diff --git a/src/Applicator/GiftCardApplicator.php b/src/Applicator/GiftCardApplicator.php index ff307e7f..9299cdeb 100644 --- a/src/Applicator/GiftCardApplicator.php +++ b/src/Applicator/GiftCardApplicator.php @@ -4,6 +4,7 @@ namespace Setono\SyliusGiftCardPlugin\Applicator; +use Sylius\Component\Channel\Model\ChannelInterface; use RuntimeException; use Setono\SyliusGiftCardPlugin\Exception\ChannelMismatchException; use Setono\SyliusGiftCardPlugin\Exception\GiftCardNotFoundException; @@ -36,7 +37,7 @@ public function apply(OrderInterface $order, $giftCard): void } $orderChannel = $order->getChannel(); - if (null === $orderChannel) { + if (!$orderChannel instanceof ChannelInterface) { throw new RuntimeException('The channel on the order cannot be null'); } @@ -72,7 +73,7 @@ private function getGiftCard(string $giftCardCode): GiftCardInterface { $giftCard = $this->giftCardRepository->findOneByCode($giftCardCode); - if (null === $giftCard) { + if (!$giftCard instanceof GiftCardInterface) { throw new GiftCardNotFoundException($giftCardCode); } diff --git a/src/EmailManager/GiftCardEmailManager.php b/src/EmailManager/GiftCardEmailManager.php index 2f2dea4d..481ac306 100644 --- a/src/EmailManager/GiftCardEmailManager.php +++ b/src/EmailManager/GiftCardEmailManager.php @@ -4,6 +4,7 @@ namespace Setono\SyliusGiftCardPlugin\EmailManager; +use Sylius\Component\Channel\Model\ChannelInterface; use Setono\SyliusGiftCardPlugin\Mailer\Emails; use Setono\SyliusGiftCardPlugin\Model\GiftCardInterface; use Setono\SyliusGiftCardPlugin\Renderer\PdfRendererInterface; @@ -51,7 +52,7 @@ public function sendEmailToCustomerWithGiftCard(CustomerInterface $customer, Gif public function sendEmailWithGiftCardsFromOrder(OrderInterface $order, array $giftCards): void { $customer = $order->getCustomer(); - if (null === $customer) { + if (!$customer instanceof \Sylius\Component\Customer\Model\CustomerInterface) { return; } @@ -61,7 +62,7 @@ public function sendEmailWithGiftCardsFromOrder(OrderInterface $order, array $gi } $channel = $order->getChannel(); - if (null === $channel) { + if (!$channel instanceof ChannelInterface) { return; } diff --git a/src/EventSubscriber/SendEmailWithGiftCardToCustomerSubscriber.php b/src/EventSubscriber/SendEmailWithGiftCardToCustomerSubscriber.php index e36edfbb..c7bad3b4 100644 --- a/src/EventSubscriber/SendEmailWithGiftCardToCustomerSubscriber.php +++ b/src/EventSubscriber/SendEmailWithGiftCardToCustomerSubscriber.php @@ -4,6 +4,7 @@ namespace Setono\SyliusGiftCardPlugin\EventSubscriber; +use Sylius\Component\Core\Model\CustomerInterface; use Setono\SyliusGiftCardPlugin\EmailManager\GiftCardEmailManagerInterface; use Setono\SyliusGiftCardPlugin\Model\GiftCardInterface; use Sylius\Bundle\ResourceBundle\Event\ResourceControllerEvent; @@ -36,7 +37,7 @@ public function postCreate(ResourceControllerEvent $event): void } $customer = $giftCard->getCustomer(); - if (null === $customer) { + if (!$customer instanceof CustomerInterface) { return; } diff --git a/src/Form/DataTransformer/GiftCardToCodeDataTransformer.php b/src/Form/DataTransformer/GiftCardToCodeDataTransformer.php index 482d21b4..a109f1d1 100644 --- a/src/Form/DataTransformer/GiftCardToCodeDataTransformer.php +++ b/src/Form/DataTransformer/GiftCardToCodeDataTransformer.php @@ -46,7 +46,7 @@ public function reverseTransform($value): ?GiftCardInterface $this->channelContext->getChannel(), ); - if (null !== $giftCard) { + if ($giftCard instanceof GiftCardInterface) { return $giftCard; } diff --git a/src/Generator/GiftCardCodeGenerator.php b/src/Generator/GiftCardCodeGenerator.php index ac7b301b..e817ad1c 100644 --- a/src/Generator/GiftCardCodeGenerator.php +++ b/src/Generator/GiftCardCodeGenerator.php @@ -4,6 +4,7 @@ namespace Setono\SyliusGiftCardPlugin\Generator; +use Setono\SyliusGiftCardPlugin\Model\GiftCardInterface; use function preg_replace; use Setono\SyliusGiftCardPlugin\Repository\GiftCardRepositoryInterface; use Webmozart\Assert\Assert; @@ -40,6 +41,6 @@ public function generate(): string private function exists(string $code): bool { - return null !== $this->giftCardRepository->findOneByCode($code); + return $this->giftCardRepository->findOneByCode($code) instanceof GiftCardInterface; } } diff --git a/src/Model/GiftCard.php b/src/Model/GiftCard.php index 7ae941ee..8ba7fdbc 100644 --- a/src/Model/GiftCard.php +++ b/src/Model/GiftCard.php @@ -77,7 +77,7 @@ public function getId(): ?int public function isDeletable(): bool { - return null === $this->orderItemUnit; + return !$this->orderItemUnit instanceof OrderItemUnitInterface; } public function getOrderItemUnit(): ?OrderItemUnitInterface @@ -100,7 +100,7 @@ public function getOrder(): ?OrderInterface { $orderItemUnit = $this->getOrderItemUnit(); - if (null === $orderItemUnit) { + if (!$orderItemUnit instanceof OrderItemUnitInterface) { return null; } @@ -217,7 +217,7 @@ public function setChannel(ChannelInterface $channel): void public function getCustomerIdentification(): ?array { $customer = $this->getCustomer(); - if (null === $customer) { + if (!$customer instanceof CustomerInterface) { return null; } @@ -230,7 +230,7 @@ public function getCustomerIdentification(): ?array public function getOrderIdentification(): ?array { $order = $this->getOrder(); - if (null === $order) { + if (!$order instanceof OrderInterface) { return null; } @@ -290,12 +290,12 @@ public function setExpiresAt(?DateTimeInterface $expiresAt): void public function isExpired(DateTimeInterface $date = null): bool { - if (null === $date) { + if (!$date instanceof DateTimeInterface) { $date = new DateTime(); } $giftCardValidUntil = $this->getExpiresAt(); - if (null === $giftCardValidUntil) { + if (!$giftCardValidUntil instanceof DateTimeInterface) { return false; } diff --git a/src/Model/OrderItemUnitTrait.php b/src/Model/OrderItemUnitTrait.php index 80cf5cd6..cb4d41b9 100644 --- a/src/Model/OrderItemUnitTrait.php +++ b/src/Model/OrderItemUnitTrait.php @@ -8,7 +8,7 @@ trait OrderItemUnitTrait { - /** @ORM\OneToOne (targetEntity="Setono\SyliusGiftCardPlugin\Model\GiftCardInterface", mappedBy="orderItemUnit") */ + #[ORM\OneToOne(targetEntity: GiftCardInterface::class, mappedBy: 'orderItemUnit')] protected ?GiftCardInterface $giftCard = null; public function getGiftCard(): ?GiftCardInterface diff --git a/src/Model/OrderTrait.php b/src/Model/OrderTrait.php index e28519a2..3975b908 100644 --- a/src/Model/OrderTrait.php +++ b/src/Model/OrderTrait.php @@ -18,13 +18,10 @@ trait OrderTrait /** * @var Collection|GiftCardInterface[] * - * @ORM\ManyToMany(targetEntity="Setono\SyliusGiftCardPlugin\Model\GiftCardInterface", inversedBy="appliedOrders") * - * @ORM\JoinTable(name="setono_sylius_gift_card__order_gift_cards", - * joinColumns={@ORM\JoinColumn(name="order_id", referencedColumnName="id", onDelete="CASCADE")}, - * inverseJoinColumns={@ORM\JoinColumn(name="gift_card_id", referencedColumnName="id", onDelete="CASCADE")} - * ) */ + #[ORM\ManyToMany(targetEntity: GiftCardInterface::class, inversedBy: 'appliedOrders')] + #[ORM\JoinTable(name: 'setono_sylius_gift_card__order_gift_cards', joinColumns: [new ORM\JoinColumn(name: 'order_id', referencedColumnName: 'id', onDelete: 'CASCADE')], inverseJoinColumns: [new ORM\JoinColumn(name: 'gift_card_id', referencedColumnName: 'id', onDelete: 'CASCADE')])] protected Collection $giftCards; public function __construct() diff --git a/src/Model/ProductTrait.php b/src/Model/ProductTrait.php index e4bad295..34a04c3a 100644 --- a/src/Model/ProductTrait.php +++ b/src/Model/ProductTrait.php @@ -8,10 +8,10 @@ trait ProductTrait { - /** @ORM\Column(type="boolean", options={"default": false}) */ + #[ORM\Column(type: 'boolean', options: ['default' => false])] protected bool $giftCard = false; - /** @ORM\Column(type="boolean", options={"default": false}) */ + #[ORM\Column(type: 'boolean', options: ['default' => false])] protected bool $giftCardAmountConfigurable = false; public function isGiftCard(): bool diff --git a/src/Provider/GiftCardConfigurationProvider.php b/src/Provider/GiftCardConfigurationProvider.php index cd216e62..dfc609bd 100644 --- a/src/Provider/GiftCardConfigurationProvider.php +++ b/src/Provider/GiftCardConfigurationProvider.php @@ -36,12 +36,12 @@ public function __construct( public function getConfiguration(BaseChannelInterface $channel, LocaleInterface $locale): GiftCardConfigurationInterface { $configuration = $this->giftCardConfigurationRepository->findOneByChannelAndLocale($channel, $locale); - if (null !== $configuration) { + if ($configuration instanceof GiftCardConfigurationInterface) { return $configuration; } $configuration = $this->giftCardConfigurationRepository->findDefault(); - if (null !== $configuration) { + if ($configuration instanceof GiftCardConfigurationInterface) { return $configuration; } diff --git a/src/Renderer/PdfRenderer.php b/src/Renderer/PdfRenderer.php index d1c37679..1cea4799 100644 --- a/src/Renderer/PdfRenderer.php +++ b/src/Renderer/PdfRenderer.php @@ -4,6 +4,7 @@ namespace Setono\SyliusGiftCardPlugin\Renderer; +use Sylius\Component\Core\Model\OrderInterface; use Knp\Snappy\GeneratorInterface; use Setono\SyliusGiftCardPlugin\Model\GiftCardConfigurationInterface; use Setono\SyliusGiftCardPlugin\Model\GiftCardInterface; @@ -28,20 +29,20 @@ public function render( ChannelInterface $channel = null, string $localeCode = null, ): PdfResponse { - if (null === $channel) { + if (!$channel instanceof ChannelInterface) { $order = $giftCard->getOrder(); - if (null !== $order) { + if ($order instanceof OrderInterface) { $channel = $order->getChannel(); } - if (null === $channel) { + if (!$channel instanceof ChannelInterface) { $channel = $this->channelContext->getChannel(); } } if (null === $localeCode) { $order = $giftCard->getOrder(); - if (null !== $order) { + if ($order instanceof OrderInterface) { $localeCode = $order->getLocaleCode(); } @@ -50,7 +51,7 @@ public function render( } } - if (null === $giftCardConfiguration) { + if (!$giftCardConfiguration instanceof GiftCardConfigurationInterface) { $giftCardConfiguration = $this->configurationProvider->getConfigurationForGiftCard($giftCard); } diff --git a/src/Resolver/CustomerChannelResolver.php b/src/Resolver/CustomerChannelResolver.php index 51a2447c..7e0c6837 100644 --- a/src/Resolver/CustomerChannelResolver.php +++ b/src/Resolver/CustomerChannelResolver.php @@ -4,6 +4,7 @@ namespace Setono\SyliusGiftCardPlugin\Resolver; +use Setono\SyliusGiftCardPlugin\Model\OrderInterface; use RuntimeException; use Setono\SyliusGiftCardPlugin\Repository\OrderRepositoryInterface; use Sylius\Component\Channel\Repository\ChannelRepositoryInterface; @@ -19,9 +20,9 @@ public function __construct(private readonly OrderRepositoryInterface $orderRepo public function resolve(CustomerInterface $customer): ChannelInterface { $latestOrder = $this->orderRepository->findLatestByCustomer($customer); - if (null !== $latestOrder) { + if ($latestOrder instanceof OrderInterface) { $channel = $latestOrder->getChannel(); - if (null !== $channel) { + if ($channel instanceof \Sylius\Component\Channel\Model\ChannelInterface) { return $channel; } } diff --git a/src/Resolver/LocaleResolver.php b/src/Resolver/LocaleResolver.php index 82e4881d..763684f0 100644 --- a/src/Resolver/LocaleResolver.php +++ b/src/Resolver/LocaleResolver.php @@ -4,6 +4,7 @@ namespace Setono\SyliusGiftCardPlugin\Resolver; +use Sylius\Component\Locale\Model\LocaleInterface; use RuntimeException; use Setono\SyliusGiftCardPlugin\Repository\OrderRepositoryInterface; use Sylius\Component\Channel\Repository\ChannelRepositoryInterface; @@ -20,7 +21,7 @@ public function __construct(private readonly OrderRepositoryInterface $orderRepo public function resolveFromCustomer(CustomerInterface $customer): string { $latestOrder = $this->orderRepository->findLatestByCustomer($customer); - if (null !== $latestOrder) { + if ($latestOrder instanceof \Setono\SyliusGiftCardPlugin\Model\OrderInterface) { return $this->resolveFromOrder($latestOrder); } @@ -35,7 +36,7 @@ public function resolveFromOrder(OrderInterface $order): string } $channel = $order->getChannel(); - if (null !== $channel) { + if ($channel instanceof \Sylius\Component\Channel\Model\ChannelInterface) { return $this->resolveFromChannel($channel); } @@ -70,7 +71,7 @@ private function resolve(): string private function _resolveFromChannel(ChannelInterface $channel): ?string { $locale = $channel->getDefaultLocale(); - if (null !== $locale) { + if ($locale instanceof LocaleInterface) { $localeCode = $locale->getCode(); if (null !== $localeCode) { return $localeCode; diff --git a/src/Security/GiftCardVoter.php b/src/Security/GiftCardVoter.php index 65b3e4ea..e541bdce 100644 --- a/src/Security/GiftCardVoter.php +++ b/src/Security/GiftCardVoter.php @@ -4,6 +4,7 @@ namespace Setono\SyliusGiftCardPlugin\Security; +use Sylius\Component\Core\Model\CustomerInterface; use LogicException; use Setono\SyliusGiftCardPlugin\Model\GiftCardInterface; use Sylius\Component\Core\Model\AdminUserInterface; @@ -51,7 +52,7 @@ protected function voteOnAttribute(string $attribute, mixed $subject, TokenInter private function canRead(GiftCardInterface $giftCard, ShopUserInterface $user): bool { // Anonymous gift cards can be seen by everyone - if (null === $giftCard->getCustomer()) { + if (!$giftCard->getCustomer() instanceof CustomerInterface) { return true; } diff --git a/src/Serializer/Normalizer/GiftCardConfigurationNormalizer.php b/src/Serializer/Normalizer/GiftCardConfigurationNormalizer.php index acbb5050..79681248 100644 --- a/src/Serializer/Normalizer/GiftCardConfigurationNormalizer.php +++ b/src/Serializer/Normalizer/GiftCardConfigurationNormalizer.php @@ -4,6 +4,7 @@ namespace Setono\SyliusGiftCardPlugin\Serializer\Normalizer; +use Setono\SyliusGiftCardPlugin\Model\GiftCardConfigurationImageInterface; use ArrayObject; use Setono\SyliusGiftCardPlugin\Exception\UnexpectedTypeException; use Setono\SyliusGiftCardPlugin\Model\GiftCardConfigurationInterface; @@ -45,12 +46,12 @@ public function normalize($object, $format = null, array $context = []): array $data['image'] = ''; $request = $this->requestStack->getMainRequest(); - if (null !== $request) { + if ($request instanceof Request) { $data['image'] = $request->getSchemeAndHttpHost() . '/bundles/setonosyliusgiftcardplugin/setono-logo.png'; } $image = $object->getBackgroundImage(); - if (null === $image) { + if (!$image instanceof GiftCardConfigurationImageInterface) { return $data; } diff --git a/src/Validator/Constraints/DefaultGiftCardConfigurationMustExistValidator.php b/src/Validator/Constraints/DefaultGiftCardConfigurationMustExistValidator.php index 4625fce0..74e43331 100644 --- a/src/Validator/Constraints/DefaultGiftCardConfigurationMustExistValidator.php +++ b/src/Validator/Constraints/DefaultGiftCardConfigurationMustExistValidator.php @@ -34,7 +34,7 @@ public function validate($value, Constraint $constraint): void } $defaultGiftCardConfiguration = $this->giftCardConfigurationRepository->findDefault(); - if (null === $defaultGiftCardConfiguration || $defaultGiftCardConfiguration->getId() === $value->getId()) { + if (!$defaultGiftCardConfiguration instanceof GiftCardConfigurationInterface || $defaultGiftCardConfiguration->getId() === $value->getId()) { $this->context->buildViolation($constraint->message) ->atPath('default') ->addViolation() diff --git a/src/Validator/Constraints/HasBackgroundImageValidator.php b/src/Validator/Constraints/HasBackgroundImageValidator.php index 1efd72a7..32ecabdf 100644 --- a/src/Validator/Constraints/HasBackgroundImageValidator.php +++ b/src/Validator/Constraints/HasBackgroundImageValidator.php @@ -4,6 +4,8 @@ namespace Setono\SyliusGiftCardPlugin\Validator\Constraints; +use Setono\SyliusGiftCardPlugin\Model\GiftCardConfigurationImageInterface; +use SplFileInfo; use Setono\SyliusGiftCardPlugin\Model\GiftCardConfigurationInterface; use Symfony\Component\Validator\Constraint; use Symfony\Component\Validator\ConstraintValidator; @@ -26,11 +28,11 @@ public function validate($value, Constraint $constraint): void $backgroundImage = $value->getBackgroundImage(); - if (null === $backgroundImage) { + if (!$backgroundImage instanceof GiftCardConfigurationImageInterface) { return; } - if (null === $backgroundImage->getFile() && null === $backgroundImage->getPath()) { + if (!$backgroundImage->getFile() instanceof SplFileInfo && null === $backgroundImage->getPath()) { $this->context->buildViolation($constraint->message) ->addViolation(); } diff --git a/tests/Application/Model/Order.php b/tests/Application/Model/Order.php index 70250382..1b150281 100644 --- a/tests/Application/Model/Order.php +++ b/tests/Application/Model/Order.php @@ -9,11 +9,9 @@ use Setono\SyliusGiftCardPlugin\Model\OrderTrait as SetonoSyliusGiftCardPluginOrderTrait; use Sylius\Component\Core\Model\Order as BaseOrder; -/** - * @ORM\Entity - * - * @ORM\Table(name="sylius_order") - */ + +#[ORM\Entity] +#[ORM\Table(name: 'sylius_order')] class Order extends BaseOrder implements SetonoSyliusGiftCardPluginOrderInterface { use SetonoSyliusGiftCardPluginOrderTrait { diff --git a/tests/Application/Model/OrderItem.php b/tests/Application/Model/OrderItem.php index 936f6694..3a9ddc5c 100644 --- a/tests/Application/Model/OrderItem.php +++ b/tests/Application/Model/OrderItem.php @@ -7,11 +7,9 @@ use Doctrine\ORM\Mapping as ORM; use Sylius\Component\Core\Model\OrderItem as BaseOrderItem; -/** - * @ORM\Entity - * - * @ORM\Table(name="sylius_order_item") - */ + +#[ORM\Entity] +#[ORM\Table(name: 'sylius_order_item')] class OrderItem extends BaseOrderItem { } diff --git a/tests/Application/Model/OrderItemUnit.php b/tests/Application/Model/OrderItemUnit.php index 390b0e61..30b6b19c 100644 --- a/tests/Application/Model/OrderItemUnit.php +++ b/tests/Application/Model/OrderItemUnit.php @@ -9,11 +9,9 @@ use Setono\SyliusGiftCardPlugin\Model\OrderItemUnitTrait as SetonoSyliusGiftCardOrderItemUnitTrait; use Sylius\Component\Core\Model\OrderItemUnit as BaseOrderItemUnit; -/** - * @ORM\Entity - * - * @ORM\Table(name="sylius_order_item_unit") - */ + +#[ORM\Entity] +#[ORM\Table(name: 'sylius_order_item_unit')] class OrderItemUnit extends BaseOrderItemUnit implements SetonoSyliusGiftCardOrderItemUnitInterface { use SetonoSyliusGiftCardOrderItemUnitTrait; diff --git a/tests/Application/Model/Product.php b/tests/Application/Model/Product.php index 620639da..8dd7e0bd 100644 --- a/tests/Application/Model/Product.php +++ b/tests/Application/Model/Product.php @@ -9,11 +9,9 @@ use Setono\SyliusGiftCardPlugin\Model\ProductTrait as SetonoSyliusGiftCardProductTrait; use Sylius\Component\Core\Model\Product as BaseProduct; -/** - * @ORM\Entity - * - * @ORM\Table(name="sylius_product") - */ + +#[ORM\Entity] +#[ORM\Table(name: 'sylius_product')] class Product extends BaseProduct implements SetonoSyliusGiftCardProductInterface { use SetonoSyliusGiftCardProductTrait; diff --git a/tests/Application/config/bundles.php b/tests/Application/config/bundles.php index a60ea358..00c91cdd 100644 --- a/tests/Application/config/bundles.php +++ b/tests/Application/config/bundles.php @@ -2,66 +2,124 @@ declare(strict_types=1); +use Symfony\Bundle\FrameworkBundle\FrameworkBundle; +use Symfony\Bundle\MonologBundle\MonologBundle; +use Symfony\Bundle\SecurityBundle\SecurityBundle; +use Symfony\Bundle\TwigBundle\TwigBundle; +use Doctrine\Bundle\DoctrineBundle\DoctrineBundle; +use Sylius\Bundle\OrderBundle\SyliusOrderBundle; +use Sylius\Bundle\MoneyBundle\SyliusMoneyBundle; +use Sylius\Bundle\CurrencyBundle\SyliusCurrencyBundle; +use Sylius\Bundle\LocaleBundle\SyliusLocaleBundle; +use Sylius\Bundle\ProductBundle\SyliusProductBundle; +use Sylius\Bundle\ChannelBundle\SyliusChannelBundle; +use Sylius\Bundle\AttributeBundle\SyliusAttributeBundle; +use Sylius\Bundle\TaxationBundle\SyliusTaxationBundle; +use Sylius\Bundle\ShippingBundle\SyliusShippingBundle; +use Sylius\Bundle\PaymentBundle\SyliusPaymentBundle; +use Sylius\Bundle\MailerBundle\SyliusMailerBundle; +use Sylius\Bundle\PromotionBundle\SyliusPromotionBundle; +use Sylius\Bundle\AddressingBundle\SyliusAddressingBundle; +use Sylius\Bundle\InventoryBundle\SyliusInventoryBundle; +use Sylius\Bundle\TaxonomyBundle\SyliusTaxonomyBundle; +use Sylius\Bundle\UserBundle\SyliusUserBundle; +use Sylius\Bundle\CustomerBundle\SyliusCustomerBundle; +use Sylius\Bundle\UiBundle\SyliusUiBundle; +use Sylius\Bundle\ReviewBundle\SyliusReviewBundle; +use Sylius\Bundle\CoreBundle\SyliusCoreBundle; +use Sylius\Bundle\ResourceBundle\SyliusResourceBundle; +use Lexik\Bundle\JWTAuthenticationBundle\LexikJWTAuthenticationBundle; +use ApiPlatform\Core\Bridge\Symfony\Bundle\ApiPlatformBundle; +use Sylius\Bundle\ApiBundle\SyliusApiBundle; +use winzou\Bundle\StateMachineBundle\winzouStateMachineBundle; +use Sonata\BlockBundle\SonataBlockBundle; +use Bazinga\Bundle\HateoasBundle\BazingaHateoasBundle; +use JMS\SerializerBundle\JMSSerializerBundle; +use FOS\RestBundle\FOSRestBundle; +use Knp\Bundle\GaufretteBundle\KnpGaufretteBundle; +use Knp\Bundle\MenuBundle\KnpMenuBundle; +use League\FlysystemBundle\FlysystemBundle; +use Liip\ImagineBundle\LiipImagineBundle; +use Payum\Bundle\PayumBundle\PayumBundle; +use Stof\DoctrineExtensionsBundle\StofDoctrineExtensionsBundle; +use Doctrine\Bundle\MigrationsBundle\DoctrineMigrationsBundle; +use Sylius\Bundle\FixturesBundle\SyliusFixturesBundle; +use Sylius\Bundle\PayumBundle\SyliusPayumBundle; +use Sylius\Bundle\ThemeBundle\SyliusThemeBundle; +use Sylius\Bundle\AdminBundle\SyliusAdminBundle; +use Sylius\Bundle\ShopBundle\SyliusShopBundle; +use Symfony\Bundle\DebugBundle\DebugBundle; +use Symfony\Bundle\WebProfilerBundle\WebProfilerBundle; +use FriendsOfBehat\SymfonyExtension\Bundle\FriendsOfBehatSymfonyExtensionBundle; +use Knp\Bundle\SnappyBundle\KnpSnappyBundle; +use SyliusLabs\DoctrineMigrationsExtraBundle\SyliusLabsDoctrineMigrationsExtraBundle; +use BabDev\PagerfantaBundle\BabDevPagerfantaBundle; +use SyliusLabs\Polyfill\Symfony\Security\Bundle\SyliusLabsPolyfillSymfonySecurityBundle; +use Symfony\WebpackEncoreBundle\WebpackEncoreBundle; +use Sylius\Calendar\SyliusCalendarBundle; +use Setono\SyliusGiftCardPlugin\SetonoSyliusGiftCardPlugin; +use Sylius\Bundle\GridBundle\SyliusGridBundle; + return [ - Symfony\Bundle\FrameworkBundle\FrameworkBundle::class => ['all' => true], - Symfony\Bundle\MonologBundle\MonologBundle::class => ['all' => true], - Symfony\Bundle\SecurityBundle\SecurityBundle::class => ['all' => true], - Symfony\Bundle\TwigBundle\TwigBundle::class => ['all' => true], - Doctrine\Bundle\DoctrineBundle\DoctrineBundle::class => ['all' => true], - Sylius\Bundle\OrderBundle\SyliusOrderBundle::class => ['all' => true], - Sylius\Bundle\MoneyBundle\SyliusMoneyBundle::class => ['all' => true], - Sylius\Bundle\CurrencyBundle\SyliusCurrencyBundle::class => ['all' => true], - Sylius\Bundle\LocaleBundle\SyliusLocaleBundle::class => ['all' => true], - Sylius\Bundle\ProductBundle\SyliusProductBundle::class => ['all' => true], - Sylius\Bundle\ChannelBundle\SyliusChannelBundle::class => ['all' => true], - Sylius\Bundle\AttributeBundle\SyliusAttributeBundle::class => ['all' => true], - Sylius\Bundle\TaxationBundle\SyliusTaxationBundle::class => ['all' => true], - Sylius\Bundle\ShippingBundle\SyliusShippingBundle::class => ['all' => true], - Sylius\Bundle\PaymentBundle\SyliusPaymentBundle::class => ['all' => true], - Sylius\Bundle\MailerBundle\SyliusMailerBundle::class => ['all' => true], - Sylius\Bundle\PromotionBundle\SyliusPromotionBundle::class => ['all' => true], - Sylius\Bundle\AddressingBundle\SyliusAddressingBundle::class => ['all' => true], - Sylius\Bundle\InventoryBundle\SyliusInventoryBundle::class => ['all' => true], - Sylius\Bundle\TaxonomyBundle\SyliusTaxonomyBundle::class => ['all' => true], - Sylius\Bundle\UserBundle\SyliusUserBundle::class => ['all' => true], - Sylius\Bundle\CustomerBundle\SyliusCustomerBundle::class => ['all' => true], - Sylius\Bundle\UiBundle\SyliusUiBundle::class => ['all' => true], - Sylius\Bundle\ReviewBundle\SyliusReviewBundle::class => ['all' => true], - Sylius\Bundle\CoreBundle\SyliusCoreBundle::class => ['all' => true], - Sylius\Bundle\ResourceBundle\SyliusResourceBundle::class => ['all' => true], + FrameworkBundle::class => ['all' => true], + MonologBundle::class => ['all' => true], + SecurityBundle::class => ['all' => true], + TwigBundle::class => ['all' => true], + DoctrineBundle::class => ['all' => true], + SyliusOrderBundle::class => ['all' => true], + SyliusMoneyBundle::class => ['all' => true], + SyliusCurrencyBundle::class => ['all' => true], + SyliusLocaleBundle::class => ['all' => true], + SyliusProductBundle::class => ['all' => true], + SyliusChannelBundle::class => ['all' => true], + SyliusAttributeBundle::class => ['all' => true], + SyliusTaxationBundle::class => ['all' => true], + SyliusShippingBundle::class => ['all' => true], + SyliusPaymentBundle::class => ['all' => true], + SyliusMailerBundle::class => ['all' => true], + SyliusPromotionBundle::class => ['all' => true], + SyliusAddressingBundle::class => ['all' => true], + SyliusInventoryBundle::class => ['all' => true], + SyliusTaxonomyBundle::class => ['all' => true], + SyliusUserBundle::class => ['all' => true], + SyliusCustomerBundle::class => ['all' => true], + SyliusUiBundle::class => ['all' => true], + SyliusReviewBundle::class => ['all' => true], + SyliusCoreBundle::class => ['all' => true], + SyliusResourceBundle::class => ['all' => true], // Begin: In test app, those 3 needs to be loaded before our plugin or the Api Resource override won't work - Lexik\Bundle\JWTAuthenticationBundle\LexikJWTAuthenticationBundle::class => ['all' => true], - ApiPlatform\Core\Bridge\Symfony\Bundle\ApiPlatformBundle::class => ['all' => true], - Sylius\Bundle\ApiBundle\SyliusApiBundle::class => ['all' => true], + LexikJWTAuthenticationBundle::class => ['all' => true], + ApiPlatformBundle::class => ['all' => true], + SyliusApiBundle::class => ['all' => true], // End: In test app, those 3 needs to be loaded before our plugin or the Api Resource override won't work - winzou\Bundle\StateMachineBundle\winzouStateMachineBundle::class => ['all' => true], - Sonata\BlockBundle\SonataBlockBundle::class => ['all' => true], - Bazinga\Bundle\HateoasBundle\BazingaHateoasBundle::class => ['all' => true], - JMS\SerializerBundle\JMSSerializerBundle::class => ['all' => true], - FOS\RestBundle\FOSRestBundle::class => ['all' => true], - Knp\Bundle\GaufretteBundle\KnpGaufretteBundle::class => ['all' => true], - Knp\Bundle\MenuBundle\KnpMenuBundle::class => ['all' => true], - League\FlysystemBundle\FlysystemBundle::class => ['all' => true], - Liip\ImagineBundle\LiipImagineBundle::class => ['all' => true], - Payum\Bundle\PayumBundle\PayumBundle::class => ['all' => true], - Stof\DoctrineExtensionsBundle\StofDoctrineExtensionsBundle::class => ['all' => true], - Doctrine\Bundle\MigrationsBundle\DoctrineMigrationsBundle::class => ['all' => true], - Sylius\Bundle\FixturesBundle\SyliusFixturesBundle::class => ['all' => true], - Sylius\Bundle\PayumBundle\SyliusPayumBundle::class => ['all' => true], - Sylius\Bundle\ThemeBundle\SyliusThemeBundle::class => ['all' => true], - Sylius\Bundle\AdminBundle\SyliusAdminBundle::class => ['all' => true], - Sylius\Bundle\ShopBundle\SyliusShopBundle::class => ['all' => true], - Symfony\Bundle\DebugBundle\DebugBundle::class => ['dev' => true, 'test' => true], - Symfony\Bundle\WebProfilerBundle\WebProfilerBundle::class => ['dev' => true, 'test' => true], - FriendsOfBehat\SymfonyExtension\Bundle\FriendsOfBehatSymfonyExtensionBundle::class => ['test' => true], - Knp\Bundle\SnappyBundle\KnpSnappyBundle::class => ['all' => true], - SyliusLabs\DoctrineMigrationsExtraBundle\SyliusLabsDoctrineMigrationsExtraBundle::class => ['all' => true], - BabDev\PagerfantaBundle\BabDevPagerfantaBundle::class => ['all' => true], - SyliusLabs\Polyfill\Symfony\Security\Bundle\SyliusLabsPolyfillSymfonySecurityBundle::class => ['all' => true], - Symfony\WebpackEncoreBundle\WebpackEncoreBundle::class => ['all' => true], - Sylius\Calendar\SyliusCalendarBundle::class => ['all' => true], - Setono\SyliusGiftCardPlugin\SetonoSyliusGiftCardPlugin::class => ['all' => true], - Sylius\Bundle\GridBundle\SyliusGridBundle::class => ['all' => true], + winzouStateMachineBundle::class => ['all' => true], + SonataBlockBundle::class => ['all' => true], + BazingaHateoasBundle::class => ['all' => true], + JMSSerializerBundle::class => ['all' => true], + FOSRestBundle::class => ['all' => true], + KnpGaufretteBundle::class => ['all' => true], + KnpMenuBundle::class => ['all' => true], + FlysystemBundle::class => ['all' => true], + LiipImagineBundle::class => ['all' => true], + PayumBundle::class => ['all' => true], + StofDoctrineExtensionsBundle::class => ['all' => true], + DoctrineMigrationsBundle::class => ['all' => true], + SyliusFixturesBundle::class => ['all' => true], + SyliusPayumBundle::class => ['all' => true], + SyliusThemeBundle::class => ['all' => true], + SyliusAdminBundle::class => ['all' => true], + SyliusShopBundle::class => ['all' => true], + DebugBundle::class => ['dev' => true, 'test' => true], + WebProfilerBundle::class => ['dev' => true, 'test' => true], + FriendsOfBehatSymfonyExtensionBundle::class => ['test' => true], + KnpSnappyBundle::class => ['all' => true], + SyliusLabsDoctrineMigrationsExtraBundle::class => ['all' => true], + BabDevPagerfantaBundle::class => ['all' => true], + SyliusLabsPolyfillSymfonySecurityBundle::class => ['all' => true], + WebpackEncoreBundle::class => ['all' => true], + SyliusCalendarBundle::class => ['all' => true], + SetonoSyliusGiftCardPlugin::class => ['all' => true], + SyliusGridBundle::class => ['all' => true], ]; diff --git a/tests/Behat/Context/Setup/GiftCardContext.php b/tests/Behat/Context/Setup/GiftCardContext.php index ef85b2ff..d029fc9d 100644 --- a/tests/Behat/Context/Setup/GiftCardContext.php +++ b/tests/Behat/Context/Setup/GiftCardContext.php @@ -53,7 +53,7 @@ public function theStoreHasGiftCardWithCode( int $price, ?ChannelInterface $channel = null, ): void { - if (null === $channel) { + if (!$channel instanceof ChannelInterface) { /** @var ChannelInterface $channel */ $channel = $this->sharedStorage->get('channel'); } diff --git a/tests/Unit/Api/Command/AddGiftCardToOrderTest.php b/tests/Unit/Api/Command/AddGiftCardToOrderTest.php index eb9688ac..a71a29f9 100644 --- a/tests/Unit/Api/Command/AddGiftCardToOrderTest.php +++ b/tests/Unit/Api/Command/AddGiftCardToOrderTest.php @@ -4,15 +4,14 @@ namespace Setono\SyliusGiftCardPlugin\Tests\Unit\Api\Command; +use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\TestCase; use Setono\SyliusGiftCardPlugin\Api\Command\AddGiftCardToOrder; use Setono\SyliusGiftCardPlugin\Api\Command\GiftCardCodeAwareInterface; class AddGiftCardToOrderTest extends TestCase { - /** - * @test - */ + #[Test] public function it_is_initializable(): void { $command = new AddGiftCardToOrder('order_code'); @@ -20,9 +19,7 @@ public function it_is_initializable(): void $this->assertInstanceOf(GiftCardCodeAwareInterface::class, $command); } - /** - * @test - */ + #[Test] public function it_has_nullable_gift_card_code(): void { $command = new AddGiftCardToOrder('order_token_vaue'); diff --git a/tests/Unit/Api/Command/AddItemToCartTest.php b/tests/Unit/Api/Command/AddItemToCartTest.php index 34f7e6db..5534503c 100644 --- a/tests/Unit/Api/Command/AddItemToCartTest.php +++ b/tests/Unit/Api/Command/AddItemToCartTest.php @@ -4,14 +4,13 @@ namespace Setono\SyliusGiftCardPlugin\Tests\Unit\Api\Command; +use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\TestCase; use Setono\SyliusGiftCardPlugin\Api\Command\AddItemToCart; class AddItemToCartTest extends TestCase { - /** - * @test - */ + #[Test] public function it_is_initializable(): void { $command = new AddItemToCart('variant', 1, 15, 'Custom message'); @@ -19,9 +18,7 @@ public function it_is_initializable(): void $this->assertInstanceOf(AddItemToCart::class, $command); } - /** - * @test - */ + #[Test] public function it_has_its_parents_properties(): void { $command = new AddItemToCart('variant', 1); @@ -30,9 +27,7 @@ public function it_has_its_parents_properties(): void $this->assertEquals(1, $command->quantity); } - /** - * @test - */ + #[Test] public function it_has_nullable_amount(): void { $command = new AddItemToCart('variant', 1); @@ -41,9 +36,7 @@ public function it_has_nullable_amount(): void $this->assertEquals(150, $command->getAmount()); } - /** - * @test - */ + #[Test] public function it_has_nullable_custom_message(): void { $command = new AddItemToCart('variant', 1); diff --git a/tests/Unit/Api/Command/AssociateConfigurationToChannelTest.php b/tests/Unit/Api/Command/AssociateConfigurationToChannelTest.php index 85ba15e6..4b958662 100644 --- a/tests/Unit/Api/Command/AssociateConfigurationToChannelTest.php +++ b/tests/Unit/Api/Command/AssociateConfigurationToChannelTest.php @@ -4,15 +4,14 @@ namespace Setono\SyliusGiftCardPlugin\Tests\Unit\Api\Command; +use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\TestCase; use Setono\SyliusGiftCardPlugin\Api\Command\AssociateConfigurationToChannel; use Setono\SyliusGiftCardPlugin\Api\Command\ConfigurationCodeAwareInterface; class AssociateConfigurationToChannelTest extends TestCase { - /** - * @test - */ + #[Test] public function it_is_initializable(): void { $command = new AssociateConfigurationToChannel('locale_code', 'channel_code'); @@ -20,9 +19,7 @@ public function it_is_initializable(): void $this->assertInstanceOf(ConfigurationCodeAwareInterface::class, $command); } - /** - * @test - */ + #[Test] public function it_has_nullable_configuration_code(): void { $command = new AssociateConfigurationToChannel('locale_code', 'channel_code'); diff --git a/tests/Unit/Api/Command/CreateGiftCardConfigurationTest.php b/tests/Unit/Api/Command/CreateGiftCardConfigurationTest.php index adb52290..f5bf982b 100644 --- a/tests/Unit/Api/Command/CreateGiftCardConfigurationTest.php +++ b/tests/Unit/Api/Command/CreateGiftCardConfigurationTest.php @@ -4,14 +4,13 @@ namespace Setono\SyliusGiftCardPlugin\Tests\Unit\Api\Command; +use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\TestCase; use Setono\SyliusGiftCardPlugin\Api\Command\CreateGiftCardConfiguration; class CreateGiftCardConfigurationTest extends TestCase { - /** - * @test - */ + #[Test] public function it_is_initializable(): void { $command = new CreateGiftCardConfiguration('code', false, false); @@ -19,36 +18,28 @@ public function it_is_initializable(): void $this->assertInstanceOf(CreateGiftCardConfiguration::class, $command); } - /** - * @test - */ + #[Test] public function it_has_nullable_default_validity_period(): void { $command = new CreateGiftCardConfiguration('code', false, false); $this->assertNull($command->defaultValidityPeriod); } - /** - * @test - */ + #[Test] public function it_has_nullable_page_size(): void { $command = new CreateGiftCardConfiguration('code', false, false); $this->assertNull($command->pageSize); } - /** - * @test - */ + #[Test] public function it_has_nullable_orientation(): void { $command = new CreateGiftCardConfiguration('code', false, false); $this->assertNull($command->orientation); } - /** - * @test - */ + #[Test] public function it_has_nullable_template(): void { $command = new CreateGiftCardConfiguration('code', false, false); diff --git a/tests/Unit/Api/Command/RemoveGiftCardFromOrderTest.php b/tests/Unit/Api/Command/RemoveGiftCardFromOrderTest.php index b17422c1..9f7910c2 100644 --- a/tests/Unit/Api/Command/RemoveGiftCardFromOrderTest.php +++ b/tests/Unit/Api/Command/RemoveGiftCardFromOrderTest.php @@ -4,15 +4,14 @@ namespace Setono\SyliusGiftCardPlugin\Tests\Unit\Api\Command; +use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\TestCase; use Setono\SyliusGiftCardPlugin\Api\Command\GiftCardCodeAwareInterface; use Setono\SyliusGiftCardPlugin\Api\Command\RemoveGiftCardFromOrder; class RemoveGiftCardFromOrderTest extends TestCase { - /** - * @test - */ + #[Test] public function it_is_initializable(): void { $command = new RemoveGiftCardFromOrder('order_code'); @@ -20,9 +19,7 @@ public function it_is_initializable(): void $this->assertInstanceOf(GiftCardCodeAwareInterface::class, $command); } - /** - * @test - */ + #[Test] public function it_has_nullable_gift_card_code(): void { $command = new RemoveGiftCardFromOrder('order_token_vaue'); diff --git a/tests/Unit/Api/CommandHandler/AddGiftCardToOrderHandlerTest.php b/tests/Unit/Api/CommandHandler/AddGiftCardToOrderHandlerTest.php index 17abca48..38eed982 100644 --- a/tests/Unit/Api/CommandHandler/AddGiftCardToOrderHandlerTest.php +++ b/tests/Unit/Api/CommandHandler/AddGiftCardToOrderHandlerTest.php @@ -4,6 +4,7 @@ namespace Setono\SyliusGiftCardPlugin\Tests\Unit\Api\CommandHandler; +use PHPUnit\Framework\Attributes\Test; use InvalidArgumentException; use PHPUnit\Framework\TestCase; use Prophecy\PhpUnit\ProphecyTrait; @@ -19,9 +20,7 @@ final class AddGiftCardToOrderHandlerTest extends TestCase { use ProphecyTrait; - /** - * @test - */ + #[Test] public function it_adds_gift_card_to_order(): void { $giftCard = new GiftCard(); @@ -46,9 +45,7 @@ public function it_adds_gift_card_to_order(): void $addGiftCardToOrderHandler($command); } - /** - * @test - */ + #[Test] public function it_throws_error_if_gift_card_code_is_null(): void { $command = new AddGiftCardToOrder('order_token_value'); @@ -67,9 +64,7 @@ public function it_throws_error_if_gift_card_code_is_null(): void $addGiftCardToOrderHandler($command); } - /** - * @test - */ + #[Test] public function it_throws_error_if_gift_card_not_found(): void { $command = new AddGiftCardToOrder('order_token_value'); @@ -89,9 +84,7 @@ public function it_throws_error_if_gift_card_not_found(): void $addGiftCardToOrderHandler($command); } - /** - * @test - */ + #[Test] public function it_throws_exception_if_order_not_found(): void { $giftCard = new GiftCard(); diff --git a/tests/Unit/Api/CommandHandler/AddItemToCartHandlerTest.php b/tests/Unit/Api/CommandHandler/AddItemToCartHandlerTest.php index 258687bd..a63dcf8a 100644 --- a/tests/Unit/Api/CommandHandler/AddItemToCartHandlerTest.php +++ b/tests/Unit/Api/CommandHandler/AddItemToCartHandlerTest.php @@ -4,6 +4,7 @@ namespace Setono\SyliusGiftCardPlugin\Tests\Unit\Api\CommandHandler; +use PHPUnit\Framework\Attributes\Test; use Doctrine\Common\Collections\ArrayCollection; use Doctrine\ORM\EntityManagerInterface; use PHPUnit\Framework\TestCase; @@ -29,9 +30,7 @@ final class AddItemToCartHandlerTest extends TestCase { use ProphecyTrait; - /** - * @test - */ + #[Test] public function it_is_initializable(): void { $orderRepository = $this->prophesize(OrderRepositoryInterface::class); @@ -55,9 +54,7 @@ public function it_is_initializable(): void $this->assertInstanceOf(AddItemToCartHandler::class, $handler); } - /** - * @test - */ + #[Test] public function it_adds_configurable_gift_card_to_cart(): void { $orderTokenValue = 'orderTokenValue'; @@ -115,9 +112,7 @@ public function it_adds_configurable_gift_card_to_cart(): void $handler($message); } - /** - * @test - */ + #[Test] public function it_adds_simple_item_to_cart(): void { $orderTokenValue = 'orderTokenValue'; @@ -165,9 +160,7 @@ public function it_adds_simple_item_to_cart(): void $handler($message); } - /** - * @test - */ + #[Test] public function it_adds_simple_gift_card_to_cart(): void { $orderTokenValue = 'orderTokenValue'; diff --git a/tests/Unit/Api/CommandHandler/AssociateConfigurationToChannelHandlerTest.php b/tests/Unit/Api/CommandHandler/AssociateConfigurationToChannelHandlerTest.php index 54c0b619..7acad1e1 100644 --- a/tests/Unit/Api/CommandHandler/AssociateConfigurationToChannelHandlerTest.php +++ b/tests/Unit/Api/CommandHandler/AssociateConfigurationToChannelHandlerTest.php @@ -4,6 +4,7 @@ namespace Setono\SyliusGiftCardPlugin\Tests\Unit\Api\CommandHandler; +use PHPUnit\Framework\Attributes\Test; use Doctrine\Common\Collections\ArrayCollection; use InvalidArgumentException; use PHPUnit\Framework\TestCase; @@ -22,9 +23,7 @@ class AssociateConfigurationToChannelHandlerTest extends TestCase { use ProphecyTrait; - /** - * @test - */ + #[Test] public function it_associates_configuration_to_channel(): void { $configuration = new GiftCardConfiguration(); @@ -78,9 +77,7 @@ public function it_associates_configuration_to_channel(): void self::assertEquals($locale, $returnedChannelConfiguration->getLocale()); } - /** - * @test - */ + #[Test] public function it_does_nothing_if_association_already_exists(): void { $configuration = new GiftCardConfiguration(); @@ -129,9 +126,7 @@ public function it_does_nothing_if_association_already_exists(): void self::assertEquals(0, $returnedConfiguration->getChannelConfigurations()->count()); } - /** - * @test - */ + #[Test] public function it_throws_exception_if_configuration_code_empty(): void { $giftCardConfigurationRepository = $this->prophesize(RepositoryInterface::class); @@ -154,9 +149,7 @@ public function it_throws_exception_if_configuration_code_empty(): void $handler($command); } - /** - * @test - */ + #[Test] public function it_throws_exception_if_configuration_not_found(): void { $giftCardConfigurationRepository = $this->prophesize(RepositoryInterface::class); @@ -180,9 +173,7 @@ public function it_throws_exception_if_configuration_not_found(): void $handler($command); } - /** - * @test - */ + #[Test] public function it_throws_eception_if_channel_not_found(): void { $configuration = new GiftCardConfiguration(); @@ -212,9 +203,7 @@ public function it_throws_eception_if_channel_not_found(): void $handler($command); } - /** - * @test - */ + #[Test] public function if_throws_exception_if_locale_not_found(): void { $configuration = new GiftCardConfiguration(); diff --git a/tests/Unit/Api/CommandHandler/CreateGiftCardConfigurationHandlerTest.php b/tests/Unit/Api/CommandHandler/CreateGiftCardConfigurationHandlerTest.php index 2649006f..345d6c10 100644 --- a/tests/Unit/Api/CommandHandler/CreateGiftCardConfigurationHandlerTest.php +++ b/tests/Unit/Api/CommandHandler/CreateGiftCardConfigurationHandlerTest.php @@ -4,6 +4,7 @@ namespace Setono\SyliusGiftCardPlugin\Tests\Unit\Api\CommandHandler; +use PHPUnit\Framework\Attributes\Test; use Doctrine\Persistence\ObjectManager; use PHPUnit\Framework\TestCase; use Prophecy\Argument; @@ -17,9 +18,7 @@ final class CreateGiftCardConfigurationHandlerTest extends TestCase { use ProphecyTrait; - /** - * @test - */ + #[Test] public function it_is_initializable(): void { $handler = new CreateGiftCardConfigurationHandler( @@ -30,9 +29,7 @@ public function it_is_initializable(): void $this->assertInstanceOf(CreateGiftCardConfigurationHandler::class, $handler); } - /** - * @test - */ + #[Test] public function it_creates_gift_card_configuration(): void { $giftCardConfigurationFactory = $this->prophesize(GiftCardConfigurationFactoryInterface::class); @@ -53,9 +50,7 @@ public function it_creates_gift_card_configuration(): void $handler->__invoke($command); } - /** - * @test - */ + #[Test] public function it_does_not_set_values_if_null(): void { $giftCardConfigurationFactory = $this->prophesize(GiftCardConfigurationFactoryInterface::class); diff --git a/tests/Unit/Api/CommandHandler/RemoveGiftCardFromOrderHandlerTest.php b/tests/Unit/Api/CommandHandler/RemoveGiftCardFromOrderHandlerTest.php index 5ec6209b..c36cb1c7 100644 --- a/tests/Unit/Api/CommandHandler/RemoveGiftCardFromOrderHandlerTest.php +++ b/tests/Unit/Api/CommandHandler/RemoveGiftCardFromOrderHandlerTest.php @@ -4,6 +4,7 @@ namespace Setono\SyliusGiftCardPlugin\Tests\Unit\Api\CommandHandler; +use PHPUnit\Framework\Attributes\Test; use InvalidArgumentException; use PHPUnit\Framework\TestCase; use Prophecy\PhpUnit\ProphecyTrait; @@ -19,9 +20,7 @@ final class RemoveGiftCardFromOrderHandlerTest extends TestCase { use ProphecyTrait; - /** - * @test - */ + #[Test] public function it_removes_gift_card_from_order(): void { $giftCard = new GiftCard(); @@ -46,9 +45,7 @@ public function it_removes_gift_card_from_order(): void $removeGiftCardFromOrderHandler($command); } - /** - * @test - */ + #[Test] public function it_throws_error_if_gift_card_code_is_null(): void { $command = new RemoveGiftCardFromOrder('order_token_value'); @@ -67,9 +64,7 @@ public function it_throws_error_if_gift_card_code_is_null(): void $removeGiftCardFromOrderHandler($command); } - /** - * @test - */ + #[Test] public function it_throws_error_if_gift_card_not_found(): void { $command = new RemoveGiftCardFromOrder('order_token_value'); @@ -89,9 +84,7 @@ public function it_throws_error_if_gift_card_not_found(): void $removeGiftCardFromOrderHandler($command); } - /** - * @test - */ + #[Test] public function it_throws_exception_if_order_not_found(): void { $giftCard = new GiftCard(); diff --git a/tests/Unit/Api/Controller/Action/DownloadGiftCardPdfActionTest.php b/tests/Unit/Api/Controller/Action/DownloadGiftCardPdfActionTest.php index 5ae20137..26bf72f7 100644 --- a/tests/Unit/Api/Controller/Action/DownloadGiftCardPdfActionTest.php +++ b/tests/Unit/Api/Controller/Action/DownloadGiftCardPdfActionTest.php @@ -4,6 +4,7 @@ namespace Setono\SyliusGiftCardPlugin\Tests\Unit\Api\Controller\Action; +use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\TestCase; use Prophecy\PhpUnit\ProphecyTrait; use Setono\SyliusGiftCardPlugin\Api\Controller\Action\DownloadGiftCardPdfAction; @@ -17,9 +18,7 @@ final class DownloadGiftCardPdfActionTest extends TestCase { use ProphecyTrait; - /** - * @test - */ + #[Test] public function it_downloads_associated_pdf(): void { $giftCard = new GiftCard(); diff --git a/tests/Unit/Api/Controller/Action/GiftCardBalanceActionTest.php b/tests/Unit/Api/Controller/Action/GiftCardBalanceActionTest.php index 0d5f0e91..20438794 100644 --- a/tests/Unit/Api/Controller/Action/GiftCardBalanceActionTest.php +++ b/tests/Unit/Api/Controller/Action/GiftCardBalanceActionTest.php @@ -4,6 +4,7 @@ namespace Setono\SyliusGiftCardPlugin\Tests\Unit\Api\Controller\Action; +use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\TestCase; use Prophecy\PhpUnit\ProphecyTrait; use Setono\SyliusGiftCardPlugin\Api\Controller\Action\GiftCardBalanceAction; @@ -15,9 +16,7 @@ final class GiftCardBalanceActionTest extends TestCase { use ProphecyTrait; - /** - * @test - */ + #[Test] public function it_returns_the_balance(): void { $giftCard1 = new GiftCard(); diff --git a/tests/Unit/Api/Controller/Action/ResendGiftCardEmailActionTest.php b/tests/Unit/Api/Controller/Action/ResendGiftCardEmailActionTest.php index 9e6178f0..956c806e 100644 --- a/tests/Unit/Api/Controller/Action/ResendGiftCardEmailActionTest.php +++ b/tests/Unit/Api/Controller/Action/ResendGiftCardEmailActionTest.php @@ -4,6 +4,7 @@ namespace Setono\SyliusGiftCardPlugin\Tests\Unit\Api\Controller\Action; +use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\TestCase; use Prophecy\PhpUnit\ProphecyTrait; use Setono\SyliusGiftCardPlugin\Api\Controller\Action\ResendGiftCardEmailAction; @@ -20,9 +21,7 @@ final class ResendGiftCardEmailActionTest extends TestCase { use ProphecyTrait; - /** - * @test - */ + #[Test] public function it_resends_email_for_order(): void { $giftCard = new GiftCard(); @@ -44,9 +43,7 @@ public function it_resends_email_for_order(): void self::assertEquals($expectedResponse, $response); } - /** - * @test - */ + #[Test] public function it_resends_email_for_customer(): void { $giftCard = new GiftCard(); @@ -65,9 +62,7 @@ public function it_resends_email_for_customer(): void self::assertEquals($expectedResponse, $response); } - /** - * @test - */ + #[Test] public function it_throws_error_if_gift_card_has_no_order_nor_customer(): void { $giftCard = new GiftCard(); diff --git a/tests/Unit/Api/Controller/Action/UploadGiftCardConfigurationImageActionTest.php b/tests/Unit/Api/Controller/Action/UploadGiftCardConfigurationImageActionTest.php index 69f90985..d0830a97 100644 --- a/tests/Unit/Api/Controller/Action/UploadGiftCardConfigurationImageActionTest.php +++ b/tests/Unit/Api/Controller/Action/UploadGiftCardConfigurationImageActionTest.php @@ -4,6 +4,7 @@ namespace Setono\SyliusGiftCardPlugin\Tests\Unit\Api\Controller\Action; +use PHPUnit\Framework\Attributes\Test; use ApiPlatform\Core\Api\IriConverterInterface; use InvalidArgumentException; use PHPUnit\Framework\TestCase; @@ -21,9 +22,7 @@ final class UploadGiftCardConfigurationImageActionTest extends TestCase { use ProphecyTrait; - /** - * @test - */ + #[Test] public function it_uploads_gift_card_configuration_image(): void { $file = new UploadedFile(__DIR__ . '/file.jpg', 'file.jpg'); @@ -62,9 +61,7 @@ public function it_uploads_gift_card_configuration_image(): void self::assertSame($file, $returnedImage->getFile()); } - /** - * @test - */ + #[Test] public function it_throws_error_if_image_empty(): void { $image = new GiftCardConfigurationImage(); @@ -93,9 +90,7 @@ public function it_throws_error_if_image_empty(): void $uploadGiftCardConfigurationImageAction($request); } - /** - * @test - */ + #[Test] public function it_throws_error_if_owner_iri_empty(): void { $file = new UploadedFile(__DIR__ . '/file.jpg', 'file.jpg'); @@ -127,9 +122,7 @@ public function it_throws_error_if_owner_iri_empty(): void $uploadGiftCardConfigurationImageAction($request); } - /** - * @test - */ + #[Test] public function it_throws_error_if_owner_not_found(): void { $file = new UploadedFile(__DIR__ . '/file.jpg', 'file.jpg'); @@ -165,9 +158,7 @@ public function it_throws_error_if_owner_not_found(): void $uploadGiftCardConfigurationImageAction($request); } - /** - * @test - */ + #[Test] public function it_deletes_old_image_of_same_type(): void { $file = new UploadedFile(__DIR__ . '/file.jpg', 'file.jpg'); diff --git a/tests/Unit/Api/DataPersister/GiftCardDataPersisterTest.php b/tests/Unit/Api/DataPersister/GiftCardDataPersisterTest.php index 69eb4b6b..5a6eca9d 100644 --- a/tests/Unit/Api/DataPersister/GiftCardDataPersisterTest.php +++ b/tests/Unit/Api/DataPersister/GiftCardDataPersisterTest.php @@ -4,6 +4,7 @@ namespace Setono\SyliusGiftCardPlugin\Tests\Unit\Api\DataPersister; +use PHPUnit\Framework\Attributes\Test; use ApiPlatform\Core\DataPersister\ContextAwareDataPersisterInterface; use PHPUnit\Framework\TestCase; use Prophecy\PhpUnit\ProphecyTrait; @@ -15,9 +16,7 @@ final class GiftCardDataPersisterTest extends TestCase { use ProphecyTrait; - /** - * @test - */ + #[Test] public function it_supports_gift_cards(): void { $decoratedDataPersister = $this->prophesize(ContextAwareDataPersisterInterface::class); @@ -26,9 +25,7 @@ public function it_supports_gift_cards(): void $this->assertTrue($dataPersister->supports(new GiftCard())); } - /** - * @test - */ + #[Test] public function it_removes_data(): void { $decoratedDataPersister = $this->prophesize(ContextAwareDataPersisterInterface::class); @@ -40,9 +37,7 @@ public function it_removes_data(): void $dataPersister->remove($data, $context); } - /** - * @test - */ + #[Test] public function it_persists_data(): void { $decoratedDataPersister = $this->prophesize(ContextAwareDataPersisterInterface::class); diff --git a/tests/Unit/Api/DataTransformer/GiftCardCodeAwareInputCommandDataTransformerTest.php b/tests/Unit/Api/DataTransformer/GiftCardCodeAwareInputCommandDataTransformerTest.php index 324be62e..0b001d8d 100644 --- a/tests/Unit/Api/DataTransformer/GiftCardCodeAwareInputCommandDataTransformerTest.php +++ b/tests/Unit/Api/DataTransformer/GiftCardCodeAwareInputCommandDataTransformerTest.php @@ -4,6 +4,7 @@ namespace Setono\SyliusGiftCardPlugin\Tests\Unit\Api\DataTransformer; +use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\TestCase; use Setono\SyliusGiftCardPlugin\Api\Command\AddGiftCardToOrder; use Setono\SyliusGiftCardPlugin\Api\Command\GiftCardCodeAwareInterface; @@ -12,9 +13,7 @@ final class GiftCardCodeAwareInputCommandDataTransformerTest extends TestCase { - /** - * @test - */ + #[Test] public function it_supports_gift_card_code_aware_interface(): void { $dataTransformer = new GiftCardCodeAwareInputCommandDataTransformer(); @@ -23,9 +22,7 @@ public function it_supports_gift_card_code_aware_interface(): void self::assertTrue($dataTransformer->supportsTransformation(new AddGiftCardToOrder('token_value'))); } - /** - * @test - */ + #[Test] public function it_adds_gift_card_code_to_object(): void { $dataTransformer = new GiftCardCodeAwareInputCommandDataTransformer(); diff --git a/tests/Unit/Api/Doctrine/QueryCollectionExtension/GiftCardsByLoggedInUserExtensionTest.php b/tests/Unit/Api/Doctrine/QueryCollectionExtension/GiftCardsByLoggedInUserExtensionTest.php index 83c3e657..c28466e7 100644 --- a/tests/Unit/Api/Doctrine/QueryCollectionExtension/GiftCardsByLoggedInUserExtensionTest.php +++ b/tests/Unit/Api/Doctrine/QueryCollectionExtension/GiftCardsByLoggedInUserExtensionTest.php @@ -4,6 +4,7 @@ namespace Setono\SyliusGiftCardPlugin\Tests\Unit\Api\Doctrine\QueryCollectionExtension; +use PHPUnit\Framework\Attributes\Test; use ApiPlatform\Core\Bridge\Doctrine\Orm\Util\QueryNameGeneratorInterface; use Doctrine\DBAL\Types\Types; use Doctrine\ORM\QueryBuilder; @@ -21,9 +22,7 @@ final class GiftCardsByLoggedInUserExtensionTest extends TestCase { use ProphecyTrait; - /** - * @test - */ + #[Test] public function it_applies_filter_to_gift_cards_collection(): void { $shopUser = new ShopUser(); @@ -57,9 +56,7 @@ public function it_applies_filter_to_gift_cards_collection(): void ); } - /** - * @test - */ + #[Test] public function it_does_not_apply_filter_for_other_collections(): void { $shopUser = new ShopUser(); @@ -85,9 +82,7 @@ public function it_does_not_apply_filter_for_other_collections(): void ); } - /** - * @test - */ + #[Test] public function it_does_not_apply_filter_if_user_is_admin(): void { $user = new AdminUser(); @@ -115,9 +110,7 @@ public function it_does_not_apply_filter_if_user_is_admin(): void ); } - /** - * @test - */ + #[Test] public function it_throws_exception_if_user_is_logged_out(): void { $userContext = $this->prophesize(UserContextInterface::class); diff --git a/tests/Unit/Controller/Action/Admin/GenerateEncodedExamplePdfActionTest.php b/tests/Unit/Controller/Action/Admin/GenerateEncodedExamplePdfActionTest.php index 970599df..1cf4f2fc 100644 --- a/tests/Unit/Controller/Action/Admin/GenerateEncodedExamplePdfActionTest.php +++ b/tests/Unit/Controller/Action/Admin/GenerateEncodedExamplePdfActionTest.php @@ -4,6 +4,7 @@ namespace Setono\SyliusGiftCardPlugin\Tests\Unit\Controller\Action\Admin; +use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\TestCase; use Prophecy\PhpUnit\ProphecyTrait; use Setono\SyliusGiftCardPlugin\Controller\Action\Admin\GenerateEncodedExamplePdfAction; @@ -22,9 +23,7 @@ final class GenerateEncodedExamplePdfActionTest extends TestCase { use ProphecyTrait; - /** - * @test - */ + #[Test] public function it_generates_encoded_pdf(): void { $id = 8; diff --git a/tests/Unit/DependencyInjection/ConfigurationTest.php b/tests/Unit/DependencyInjection/ConfigurationTest.php index 8d92e2d5..61f4e678 100644 --- a/tests/Unit/DependencyInjection/ConfigurationTest.php +++ b/tests/Unit/DependencyInjection/ConfigurationTest.php @@ -4,6 +4,7 @@ namespace Setono\SyliusGiftCardPlugin\Tests\Unit\DependencyInjection; +use PHPUnit\Framework\Attributes\Test; use Matthias\SymfonyConfigTest\PhpUnit\ConfigurationTestCaseTrait; use PHPUnit\Framework\TestCase; use Setono\SyliusGiftCardPlugin\DependencyInjection\Configuration; @@ -31,9 +32,7 @@ protected function getConfiguration(): Configuration return new Configuration(); } - /** - * @test - */ + #[Test] public function processed_configuration_for_array_node_1(): void { $this->assertProcessedConfigurationEquals([ diff --git a/tests/Unit/DependencyInjection/SetonoSyliusGiftCardExtensionTest.php b/tests/Unit/DependencyInjection/SetonoSyliusGiftCardExtensionTest.php index 0f91419f..3ebb4d6d 100644 --- a/tests/Unit/DependencyInjection/SetonoSyliusGiftCardExtensionTest.php +++ b/tests/Unit/DependencyInjection/SetonoSyliusGiftCardExtensionTest.php @@ -4,6 +4,7 @@ namespace Setono\SyliusGiftCardPlugin\Tests\Unit\DependencyInjection; +use PHPUnit\Framework\Attributes\Test; use Matthias\SymfonyDependencyInjectionTest\PhpUnit\AbstractExtensionTestCase; use Setono\SyliusGiftCardPlugin\DependencyInjection\SetonoSyliusGiftCardExtension; use Setono\SyliusGiftCardPlugin\Provider\PdfRenderingOptionsProviderInterface; @@ -16,9 +17,7 @@ protected function getContainerExtensions(): array return [new SetonoSyliusGiftCardExtension()]; } - /** - * @test - */ + #[Test] public function after_loading_the_correct_parameter_has_been_set(): void { $this->load(); diff --git a/tests/Unit/EventSubscriber/DefaultGiftCardConfigurationSubscriberTest.php b/tests/Unit/EventSubscriber/DefaultGiftCardConfigurationSubscriberTest.php index bb758820..6157f27e 100644 --- a/tests/Unit/EventSubscriber/DefaultGiftCardConfigurationSubscriberTest.php +++ b/tests/Unit/EventSubscriber/DefaultGiftCardConfigurationSubscriberTest.php @@ -4,6 +4,7 @@ namespace Setono\SyliusGiftCardPlugin\Tests\Unit\EventSubscriber; +use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\TestCase; use Prophecy\PhpUnit\ProphecyTrait; use Setono\SyliusGiftCardPlugin\EventSubscriber\DefaultGiftCardConfigurationSubscriber; @@ -16,9 +17,7 @@ final class DefaultGiftCardConfigurationSubscriberTest extends TestCase { use ProphecyTrait; - /** - * @test - */ + #[Test] public function it_sets_all_existing_to_not_default_when_creating_new(): void { $existing1 = $this->getExistingGiftCardConfiguration(1); @@ -39,9 +38,7 @@ public function it_sets_all_existing_to_not_default_when_creating_new(): void self::assertTrue($giftCardConfiguration->isDefault()); } - /** - * @test - */ + #[Test] public function it_sets_all_existing_to_not_default_when_updating_existing(): void { $existing1 = $this->getExistingGiftCardConfiguration(1); diff --git a/tests/Unit/EventSubscriber/SendEmailWithGiftCardToCustomerSubscriberTest.php b/tests/Unit/EventSubscriber/SendEmailWithGiftCardToCustomerSubscriberTest.php index c08d0390..d778d5d4 100644 --- a/tests/Unit/EventSubscriber/SendEmailWithGiftCardToCustomerSubscriberTest.php +++ b/tests/Unit/EventSubscriber/SendEmailWithGiftCardToCustomerSubscriberTest.php @@ -4,6 +4,7 @@ namespace Setono\SyliusGiftCardPlugin\Tests\Unit\EventSubscriber; +use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\TestCase; use Prophecy\Argument; use Prophecy\PhpUnit\ProphecyTrait; @@ -19,9 +20,7 @@ final class SendEmailWithGiftCardToCustomerSubscriberTest extends TestCase { use ProphecyTrait; - /** - * @test - */ + #[Test] public function it_throws_an_error_if_the_subject_is_not_gift_card(): void { $giftCardEmailManager = $this->prophesize(GiftCardEmailManagerInterface::class); @@ -33,9 +32,7 @@ public function it_throws_an_error_if_the_subject_is_not_gift_card(): void $subscriber->postCreate($event->reveal()); } - /** - * @test - */ + #[Test] public function it_does_not_send_email_if_no_customer(): void { $giftCardEmailManager = $this->prophesize(GiftCardEmailManagerInterface::class); @@ -49,9 +46,7 @@ public function it_does_not_send_email_if_no_customer(): void $giftCardEmailManager->sendEmailToCustomerWithGiftCard(Argument::any(), Argument::any())->shouldNotHaveBeenCalled(); } - /** - * @test - */ + #[Test] public function it_does_not_send_email_if_it_was_not_asked(): void { $giftCardEmailManager = $this->prophesize(GiftCardEmailManagerInterface::class); @@ -68,9 +63,7 @@ public function it_does_not_send_email_if_it_was_not_asked(): void $giftCardEmailManager->sendEmailToCustomerWithGiftCard(Argument::any(), Argument::any())->shouldNotHaveBeenCalled(); } - /** - * @test - */ + #[Test] public function it_sends_email_if_it_was_asked(): void { $giftCardEmailManager = $this->prophesize(GiftCardEmailManagerInterface::class); diff --git a/tests/Unit/Factory/GiftCardConfigurationFactoryTest.php b/tests/Unit/Factory/GiftCardConfigurationFactoryTest.php index 15a3d0f8..7bb41f23 100644 --- a/tests/Unit/Factory/GiftCardConfigurationFactoryTest.php +++ b/tests/Unit/Factory/GiftCardConfigurationFactoryTest.php @@ -4,6 +4,7 @@ namespace Setono\SyliusGiftCardPlugin\Tests\Unit\Factory; +use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\TestCase; use Prophecy\PhpUnit\ProphecyTrait; use Setono\SyliusGiftCardPlugin\Factory\GiftCardConfigurationFactory; @@ -16,9 +17,7 @@ final class GiftCardConfigurationFactoryTest extends TestCase { use ProphecyTrait; - /** - * @test - */ + #[Test] public function it_creates_a_new_gift_card_configuration(): void { $giftCardConfiguration = new GiftCardConfiguration(); diff --git a/tests/Unit/Factory/GiftCardFactoryTest.php b/tests/Unit/Factory/GiftCardFactoryTest.php index 28e89085..a11769f7 100644 --- a/tests/Unit/Factory/GiftCardFactoryTest.php +++ b/tests/Unit/Factory/GiftCardFactoryTest.php @@ -4,6 +4,7 @@ namespace Setono\SyliusGiftCardPlugin\Tests\Unit\Factory; +use PHPUnit\Framework\Attributes\Test; use DateTime; use DateTimeImmutable; use PHPUnit\Framework\TestCase; @@ -28,9 +29,7 @@ final class GiftCardFactoryTest extends TestCase { use ProphecyTrait; - /** - * @test - */ + #[Test] public function it_creates_a_new_gift_card_with_code(): void { $giftCard = new GiftCard(); @@ -56,9 +55,7 @@ public function it_creates_a_new_gift_card_with_code(): void $this->assertSame('super-code', $createdGiftCard->getCode()); } - /** - * @test - */ + #[Test] public function it_creates_a_new_gift_card_for_channel(): void { $giftCard = new GiftCard(); @@ -86,9 +83,7 @@ public function it_creates_a_new_gift_card_for_channel(): void $this->assertSame($channel, $createdGiftCard->getChannel()); } - /** - * @test - */ + #[Test] public function it_creates_a_new_gift_card_for_channel_with_expiration_date(): void { $giftCard = new GiftCard(); @@ -123,9 +118,7 @@ public function it_creates_a_new_gift_card_for_channel_with_expiration_date(): v $this->assertEquals($expectedValidUntilDate, $giftCard->getExpiresAt()); } - /** - * @test - */ + #[Test] public function it_creates_a_new_gift_card_for_channel_from_admin(): void { $giftCard = new GiftCard(); @@ -154,9 +147,7 @@ public function it_creates_a_new_gift_card_for_channel_from_admin(): void $this->assertSame(GiftCardInterface::ORIGIN_ADMIN, $createdGiftCard->getOrigin()); } - /** - * @test - */ + #[Test] public function it_creates_a_new_gift_card_for_order_item_unit_and_cart(): void { $giftCard = new GiftCard(); @@ -196,9 +187,7 @@ public function it_creates_a_new_gift_card_for_order_item_unit_and_cart(): void $this->assertSame(GiftCardInterface::ORIGIN_ORDER, $createdGiftCard->getOrigin()); } - /** - * @test - */ + #[Test] public function it_creates_a_new_gift_card_for_order_item_unit(): void { $giftCard = new GiftCard(); @@ -244,9 +233,7 @@ public function it_creates_a_new_gift_card_for_order_item_unit(): void $this->assertSame(GiftCardInterface::ORIGIN_ORDER, $createdGiftCard->getOrigin()); } - /** - * @test - */ + #[Test] public function it_creates_example_gift_card(): void { $decoratedFactory = $this->prophesize(FactoryInterface::class); diff --git a/tests/Unit/Form/Extension/AddToCartTypeExtensionTest.php b/tests/Unit/Form/Extension/AddToCartTypeExtensionTest.php index f5d988bc..d44ae52e 100644 --- a/tests/Unit/Form/Extension/AddToCartTypeExtensionTest.php +++ b/tests/Unit/Form/Extension/AddToCartTypeExtensionTest.php @@ -4,6 +4,7 @@ namespace Setono\SyliusGiftCardPlugin\Tests\Unit\Form\Extension; +use PHPUnit\Framework\Attributes\Test; use Doctrine\Common\Collections\ArrayCollection; use Doctrine\ORM\EntityManagerInterface; use PHPUnit\Framework\TestCase; @@ -26,9 +27,7 @@ final class AddToCartTypeExtensionTest extends TestCase { use ProphecyTrait; - /** - * @test - */ + #[Test] public function it_populates_cart_item_for_configurable_gift_card(): void { $cart = $this->prophesize(Order::class); @@ -66,9 +65,7 @@ public function it_populates_cart_item_for_configurable_gift_card(): void $extension->populateCartItem($formEvent->reveal()); } - /** - * @test - */ + #[Test] public function it_populates_cart_item_for_not_configurable_gift_card(): void { $cart = $this->prophesize(Order::class); diff --git a/tests/Unit/Form/Type/DatePeriodTypeTest.php b/tests/Unit/Form/Type/DatePeriodTypeTest.php index 14b90063..174b4835 100644 --- a/tests/Unit/Form/Type/DatePeriodTypeTest.php +++ b/tests/Unit/Form/Type/DatePeriodTypeTest.php @@ -4,6 +4,7 @@ namespace Setono\SyliusGiftCardPlugin\Tests\Unit\Form\Type; +use PHPUnit\Framework\Attributes\Test; use Prophecy\PhpUnit\ProphecyTrait; use Prophecy\Prophecy\ObjectProphecy; use Setono\SyliusGiftCardPlugin\Form\Type\DatePeriodType; @@ -24,9 +25,7 @@ protected function setUp(): void parent::setUp(); } - /** - * @test - */ + #[Test] public function it_submits_valid_data(): void { $formData = [ diff --git a/tests/Unit/Generator/GiftCardCodeGeneratorTest.php b/tests/Unit/Generator/GiftCardCodeGeneratorTest.php index 80c950b5..4c105013 100644 --- a/tests/Unit/Generator/GiftCardCodeGeneratorTest.php +++ b/tests/Unit/Generator/GiftCardCodeGeneratorTest.php @@ -4,6 +4,7 @@ namespace Setono\SyliusGiftCardPlugin\Tests\Unit\Generator; +use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\TestCase; use Prophecy\PhpUnit\ProphecyTrait; use Setono\SyliusGiftCardPlugin\Generator\GiftCardCodeGenerator; @@ -13,9 +14,7 @@ final class GiftCardCodeGeneratorTest extends TestCase { use ProphecyTrait; - /** - * @test - */ + #[Test] public function it_generates_gift_card_code(): void { $codeLength = 10; diff --git a/tests/Unit/Model/GiftCardConfigurationTest.php b/tests/Unit/Model/GiftCardConfigurationTest.php index 2281a6cf..8fc481b2 100644 --- a/tests/Unit/Model/GiftCardConfigurationTest.php +++ b/tests/Unit/Model/GiftCardConfigurationTest.php @@ -4,14 +4,13 @@ namespace Setono\SyliusGiftCardPlugin\Tests\Unit\Model; +use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\TestCase; use Setono\SyliusGiftCardPlugin\Model\GiftCardConfiguration; final class GiftCardConfigurationTest extends TestCase { - /** - * @test - */ + #[Test] public function it_has_properties(): void { $giftCardConfiguration = new GiftCardConfiguration(); diff --git a/tests/Unit/Model/GiftCardTest.php b/tests/Unit/Model/GiftCardTest.php index 0d6cf6c5..0939c148 100644 --- a/tests/Unit/Model/GiftCardTest.php +++ b/tests/Unit/Model/GiftCardTest.php @@ -4,6 +4,7 @@ namespace Setono\SyliusGiftCardPlugin\Tests\Unit\Model; +use PHPUnit\Framework\Attributes\Test; use DateTime; use PHPUnit\Framework\TestCase; use Prophecy\PhpUnit\ProphecyTrait; @@ -18,9 +19,7 @@ final class GiftCardTest extends TestCase { use ProphecyTrait; - /** - * @test - */ + #[Test] public function it_has_properties(): void { $orderItemUnit = $this->prophesize(OrderItemUnitInterface::class); @@ -67,9 +66,7 @@ public function it_has_properties(): void $this->assertFalse($giftCard->getSendNotificationEmail()); } - /** - * @test - */ + #[Test] public function it_can_be_converted_to_string(): void { $giftCard = new GiftCard(); @@ -77,18 +74,14 @@ public function it_can_be_converted_to_string(): void $this->assertSame('test-code', $giftCard->__toString()); } - /** - * @test - */ + #[Test] public function it_can_be_deletable(): void { $giftCard = new GiftCard(); $this->assertSame(true, $giftCard->isDeletable()); } - /** - * @test - */ + #[Test] public function it_is_not_deletable_if_it_has_order_item_unit(): void { $orderItemUnit = $this->prophesize(OrderItemUnitInterface::class); @@ -97,9 +90,7 @@ public function it_is_not_deletable_if_it_has_order_item_unit(): void $this->assertSame(false, $giftCard->isDeletable()); } - /** - * @test - */ + #[Test] public function it_has_order_from_order_item_unit(): void { $giftCard = new GiftCard(); @@ -119,9 +110,7 @@ public function it_has_order_from_order_item_unit(): void $this->assertSame($order, $giftCard->getOrder()); } - /** - * @test - */ + #[Test] public function it_has_applied_orders(): void { $giftCard = new GiftCard(); @@ -143,18 +132,14 @@ public function it_has_applied_orders(): void $this->assertFalse($giftCard->hasAppliedOrder($order1)); } - /** - * @test - */ + #[Test] public function it_has_null_origin_by_default(): void { $giftCard = new GiftCard(); $this->assertSame(null, $giftCard->getOrigin()); } - /** - * @test - */ + #[Test] public function it_can_expire(): void { $today = new DateTime('2022-01-01 00:00:00'); @@ -164,9 +149,7 @@ public function it_can_expire(): void $this->assertTrue($giftCard->isExpired($today)); } - /** - * @test - */ + #[Test] public function it_is_not_expired_if_expires_at_is_null(): void { $giftCard = new GiftCard(); @@ -174,9 +157,7 @@ public function it_is_not_expired_if_expires_at_is_null(): void $this->assertFalse($giftCard->isExpired()); } - /** - * @test - */ + #[Test] public function it_is_not_expired_if_expiresAt_is_in_future(): void { $today = new DateTime('2022-01-01 00:00:00'); diff --git a/tests/Unit/Model/ProductTraitTest.php b/tests/Unit/Model/ProductTraitTest.php index a8148aac..58c61b70 100644 --- a/tests/Unit/Model/ProductTraitTest.php +++ b/tests/Unit/Model/ProductTraitTest.php @@ -4,14 +4,13 @@ namespace Setono\SyliusGiftCardPlugin\Tests\Unit\Model; +use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\TestCase; use Setono\SyliusGiftCardPlugin\Tests\Application\Model\Product; final class ProductTraitTest extends TestCase { - /** - * @test - */ + #[Test] public function it_has_properties(): void { $product = new Product(); diff --git a/tests/Unit/Operator/GiftCardOperatorTest.php b/tests/Unit/Operator/GiftCardOperatorTest.php index 06d42c9a..59a20548 100644 --- a/tests/Unit/Operator/GiftCardOperatorTest.php +++ b/tests/Unit/Operator/GiftCardOperatorTest.php @@ -4,6 +4,7 @@ namespace Setono\SyliusGiftCardPlugin\Tests\Unit\Operator; +use PHPUnit\Framework\Attributes\Test; use Doctrine\Common\Collections\ArrayCollection; use Doctrine\ORM\EntityManagerInterface; use PHPUnit\Framework\TestCase; @@ -22,9 +23,7 @@ final class GiftCardOperatorTest extends TestCase { use ProphecyTrait; - /** - * @test - */ + #[Test] public function it_associate_gift_card_to_customer(): void { $order = new Order(); @@ -59,9 +58,7 @@ public function it_associate_gift_card_to_customer(): void $this->assertEquals($customer, $giftCard->getCustomer()); } - /** - * @test - */ + #[Test] public function it_returns_if_there_is_no_gift_card_item(): void { $order = $this->prophesize(Order::class); @@ -79,9 +76,7 @@ public function it_returns_if_there_is_no_gift_card_item(): void $order->getCustomer()->shouldNotBeCalled(); } - /** - * @test - */ + #[Test] public function it_enables_gift_card(): void { $order = new Order(); @@ -117,9 +112,7 @@ public function it_enables_gift_card(): void $this->assertTrue($giftCard->isEnabled()); } - /** - * @test - */ + #[Test] public function it_disables_gift_card(): void { $order = new Order(); diff --git a/tests/Unit/Order/AddToCartCommandTest.php b/tests/Unit/Order/AddToCartCommandTest.php index f8be01ec..05bee1d4 100644 --- a/tests/Unit/Order/AddToCartCommandTest.php +++ b/tests/Unit/Order/AddToCartCommandTest.php @@ -4,6 +4,7 @@ namespace Setono\SyliusGiftCardPlugin\Tests\Unit\Order; +use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\TestCase; use Setono\SyliusGiftCardPlugin\Order\AddToCartCommand; use Setono\SyliusGiftCardPlugin\Order\GiftCardInformation; @@ -12,9 +13,7 @@ final class AddToCartCommandTest extends TestCase { - /** - * @test - */ + #[Test] public function it_has_properties(): void { $cart = new Order(); diff --git a/tests/Unit/Order/Factory/AddToCardCommandFactoryTest.php b/tests/Unit/Order/Factory/AddToCardCommandFactoryTest.php index a7c4e725..3175c869 100644 --- a/tests/Unit/Order/Factory/AddToCardCommandFactoryTest.php +++ b/tests/Unit/Order/Factory/AddToCardCommandFactoryTest.php @@ -4,6 +4,7 @@ namespace Setono\SyliusGiftCardPlugin\Tests\Unit\Order\Factory; +use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\TestCase; use Setono\SyliusGiftCardPlugin\Order\AddToCartCommand; use Setono\SyliusGiftCardPlugin\Order\Factory\AddToCartCommandFactory; @@ -14,9 +15,7 @@ final class AddToCardCommandFactoryTest extends TestCase { - /** - * @test - */ + #[Test] public function it_creates_new_with_cart_and_item(): void { $cart = new Order(); diff --git a/tests/Unit/Order/Factory/GiftCardInformationFactoryTest.php b/tests/Unit/Order/Factory/GiftCardInformationFactoryTest.php index 6d2ce10d..06fde6f8 100644 --- a/tests/Unit/Order/Factory/GiftCardInformationFactoryTest.php +++ b/tests/Unit/Order/Factory/GiftCardInformationFactoryTest.php @@ -4,6 +4,7 @@ namespace Setono\SyliusGiftCardPlugin\Tests\Unit\Order\Factory; +use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\TestCase; use Setono\SyliusGiftCardPlugin\Order\Factory\GiftCardInformationFactory; use Setono\SyliusGiftCardPlugin\Order\GiftCardInformation; @@ -11,9 +12,7 @@ final class GiftCardInformationFactoryTest extends TestCase { - /** - * @test - */ + #[Test] public function it_creates_new(): void { $orderItem = new OrderItem(); diff --git a/tests/Unit/Order/GiftCardInformationTest.php b/tests/Unit/Order/GiftCardInformationTest.php index 771550ff..c581c8a2 100644 --- a/tests/Unit/Order/GiftCardInformationTest.php +++ b/tests/Unit/Order/GiftCardInformationTest.php @@ -4,14 +4,13 @@ namespace Setono\SyliusGiftCardPlugin\Tests\Unit\Order; +use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\TestCase; use Setono\SyliusGiftCardPlugin\Order\GiftCardInformation; final class GiftCardInformationTest extends TestCase { - /** - * @test - */ + #[Test] public function it_has_properties(): void { $giftCardInformation = new GiftCardInformation(80, 'message'); @@ -20,9 +19,7 @@ public function it_has_properties(): void $this->assertEquals($giftCardInformation->getCustomMessage(), 'message'); } - /** - * @test - */ + #[Test] public function it_has_settable_amount(): void { $giftCardInformation = new GiftCardInformation(80, 'message'); @@ -30,9 +27,7 @@ public function it_has_settable_amount(): void $this->assertEquals($giftCardInformation->getAmount(), 200); } - /** - * @test - */ + #[Test] public function it_has_settable_message(): void { $giftCardInformation = new GiftCardInformation(80, 'message'); diff --git a/tests/Unit/OrderProcessor/OrderGiftCardProcessorTest.php b/tests/Unit/OrderProcessor/OrderGiftCardProcessorTest.php index 34ee4ede..57751a2c 100644 --- a/tests/Unit/OrderProcessor/OrderGiftCardProcessorTest.php +++ b/tests/Unit/OrderProcessor/OrderGiftCardProcessorTest.php @@ -4,6 +4,7 @@ namespace Setono\SyliusGiftCardPlugin\Tests\Unit\OrderProcessor; +use PHPUnit\Framework\Attributes\Test; use Doctrine\Common\Collections\ArrayCollection; use PHPUnit\Framework\TestCase; use Prophecy\Argument; @@ -21,9 +22,7 @@ final class OrderGiftCardProcessorTest extends TestCase { use ProphecyTrait; - /** - * @test - */ + #[Test] public function it_is_initializable(): void { $translator = $this->prophesize(TranslatorInterface::class); @@ -35,9 +34,7 @@ public function it_is_initializable(): void $this->assertInstanceOf(OrderProcessorInterface::class, $processor); } - /** - * @test - */ + #[Test] public function it_processes(): void { $translator = $this->prophesize(TranslatorInterface::class); diff --git a/tests/Unit/Provider/DatePeriodUnitProviderTest.php b/tests/Unit/Provider/DatePeriodUnitProviderTest.php index c76569d1..35e70aee 100644 --- a/tests/Unit/Provider/DatePeriodUnitProviderTest.php +++ b/tests/Unit/Provider/DatePeriodUnitProviderTest.php @@ -4,14 +4,13 @@ namespace Setono\SyliusGiftCardPlugin\Tests\Unit\Provider; +use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\TestCase; use Setono\SyliusGiftCardPlugin\Provider\DatePeriodUnitProvider; final class DatePeriodUnitProviderTest extends TestCase { - /** - * @test - */ + #[Test] public function it_provides_units_list(): void { $provider = new DatePeriodUnitProvider(); diff --git a/tests/Unit/Provider/OrderEligibleTotalProviderTest.php b/tests/Unit/Provider/OrderEligibleTotalProviderTest.php index d4e81726..d2343dbd 100644 --- a/tests/Unit/Provider/OrderEligibleTotalProviderTest.php +++ b/tests/Unit/Provider/OrderEligibleTotalProviderTest.php @@ -4,6 +4,7 @@ namespace Setono\SyliusGiftCardPlugin\Tests\Unit\Provider; +use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\TestCase; use Prophecy\PhpUnit\ProphecyTrait; use Setono\SyliusGiftCardPlugin\Model\GiftCard; @@ -14,9 +15,7 @@ final class OrderEligibleTotalProviderTest extends TestCase { use ProphecyTrait; - /** - * @test - */ + #[Test] public function it_returns_order_total(): void { $order = $this->prophesize(Order::class); diff --git a/tests/Unit/Provider/PdfRenderingOptionProviderTest.php b/tests/Unit/Provider/PdfRenderingOptionProviderTest.php index c2f8f0a4..065a3515 100644 --- a/tests/Unit/Provider/PdfRenderingOptionProviderTest.php +++ b/tests/Unit/Provider/PdfRenderingOptionProviderTest.php @@ -4,6 +4,7 @@ namespace Setono\SyliusGiftCardPlugin\Tests\Unit\Provider; +use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\TestCase; use Setono\SyliusGiftCardPlugin\Model\GiftCardConfiguration; use Setono\SyliusGiftCardPlugin\Provider\PdfRenderingOptionsProvider; @@ -11,9 +12,7 @@ final class PdfRenderingOptionProviderTest extends TestCase { - /** - * @test - */ + #[Test] public function it_provides_rendering_options(): void { $provider = new PdfRenderingOptionsProvider(); @@ -23,9 +22,7 @@ public function it_provides_rendering_options(): void $this->assertIsArray($renderingOptions); } - /** - * @test - */ + #[Test] public function it_provides_page_size_if_not_null(): void { $provider = new PdfRenderingOptionsProvider(); @@ -37,9 +34,7 @@ public function it_provides_page_size_if_not_null(): void $this->assertEquals(PdfRenderingOptionsProviderInterface::PAGE_SIZE_A8, $renderingOptions['page-size']); } - /** - * @test - */ + #[Test] public function it_provides_orientation_if_not_null(): void { $provider = new PdfRenderingOptionsProvider(); diff --git a/tests/Unit/Twig/Extension/PdfRuntimeTest.php b/tests/Unit/Twig/Extension/PdfRuntimeTest.php index ad483138..d5e5350b 100644 --- a/tests/Unit/Twig/Extension/PdfRuntimeTest.php +++ b/tests/Unit/Twig/Extension/PdfRuntimeTest.php @@ -4,6 +4,7 @@ namespace Setono\SyliusGiftCardPlugin\Tests\Unit\Twig\Extension; +use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\TestCase; use Prophecy\PhpUnit\ProphecyTrait; use Setono\SyliusGiftCardPlugin\Factory\GiftCardFactoryInterface; @@ -17,9 +18,7 @@ final class PdfRuntimeTest extends TestCase { use ProphecyTrait; - /** - * @test - */ + #[Test] public function it_gets_base64_encoded_pdf_content(): void { $giftCard = new GiftCard(); diff --git a/tests/Unit/Validator/Constraints/DatePeriodValidatorTest.php b/tests/Unit/Validator/Constraints/DatePeriodValidatorTest.php index 3e6549a8..759a42e5 100644 --- a/tests/Unit/Validator/Constraints/DatePeriodValidatorTest.php +++ b/tests/Unit/Validator/Constraints/DatePeriodValidatorTest.php @@ -4,6 +4,7 @@ namespace Setono\SyliusGiftCardPlugin\Tests\Unit\Validator\Constraints; +use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\TestCase; use Prophecy\PhpUnit\ProphecyTrait; use Setono\SyliusGiftCardPlugin\Provider\DatePeriodUnitProvider; @@ -18,9 +19,7 @@ final class DatePeriodValidatorTest extends TestCase { use ProphecyTrait; - /** - * @test - */ + #[Test] public function it_throws_exception_if_constraint_has_wrong_type(): void { $validator = new DatePeriodValidator(new DatePeriodUnitProvider()); @@ -30,9 +29,7 @@ public function it_throws_exception_if_constraint_has_wrong_type(): void $validator->validate('super', $constraint); } - /** - * @test - */ + #[Test] public function it_adds_violation_if_duration_is_negative(): void { $validator = new DatePeriodValidator(new DatePeriodUnitProvider()); @@ -48,9 +45,7 @@ public function it_adds_violation_if_duration_is_negative(): void $validator->validate('-8 month', $constraint); } - /** - * @test - */ + #[Test] public function it_adds_violation_if_unit_is_invalid(): void { $validator = new DatePeriodValidator(new DatePeriodUnitProvider()); diff --git a/tests/Unit/Validator/Constraints/GiftCardIsNotExpiredValidatorTest.php b/tests/Unit/Validator/Constraints/GiftCardIsNotExpiredValidatorTest.php index ada026fa..2b022f61 100644 --- a/tests/Unit/Validator/Constraints/GiftCardIsNotExpiredValidatorTest.php +++ b/tests/Unit/Validator/Constraints/GiftCardIsNotExpiredValidatorTest.php @@ -4,6 +4,7 @@ namespace Setono\SyliusGiftCardPlugin\Tests\Unit\Validator\Constraints; +use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\TestCase; use Prophecy\PhpUnit\ProphecyTrait; use Setono\SyliusGiftCardPlugin\Model\GiftCardInterface; @@ -18,9 +19,7 @@ final class GiftCardIsNotExpiredValidatorTest extends TestCase { use ProphecyTrait; - /** - * @test - */ + #[Test] public function it_throws_exception_if_constraint_has_wrong_type(): void { $validator = new GiftCardIsNotExpiredValidator(); @@ -43,9 +42,7 @@ public function it_returns_if_value_is_null(): void $validator->validate($value, $constraint); } - /** - * @test - */ + #[Test] public function it_adds_violation_if_gift_card_is_expired(): void { $giftCard = $this->prophesize(GiftCardInterface::class); diff --git a/tests/Unit/Validator/Constraints/HasBackgroundImageValidatorTest.php b/tests/Unit/Validator/Constraints/HasBackgroundImageValidatorTest.php index daff61e5..906cafad 100644 --- a/tests/Unit/Validator/Constraints/HasBackgroundImageValidatorTest.php +++ b/tests/Unit/Validator/Constraints/HasBackgroundImageValidatorTest.php @@ -4,6 +4,7 @@ namespace Setono\SyliusGiftCardPlugin\Tests\Unit\Validator\Constraints; +use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\TestCase; use Prophecy\PhpUnit\ProphecyTrait; use Setono\SyliusGiftCardPlugin\Model\GiftCardConfiguration; @@ -19,9 +20,7 @@ final class HasBackgroundImageValidatorTest extends TestCase { use ProphecyTrait; - /** - * @test - */ + #[Test] public function it_throws_exception_if_constraint_has_wrong_type(): void { $validator = new HasBackgroundImageValidator(); @@ -31,9 +30,7 @@ public function it_throws_exception_if_constraint_has_wrong_type(): void $validator->validate(new GiftCardConfiguration(), $constraint); } - /** - * @test - */ + #[Test] public function it_adds_violation_if_no_image_has_been_set(): void { $validator = new HasBackgroundImageValidator(); diff --git a/tests/Unit/Validator/Constraints/Pdf/ValidOrientationValidatorTest.php b/tests/Unit/Validator/Constraints/Pdf/ValidOrientationValidatorTest.php index 5d1c9010..521d5b43 100644 --- a/tests/Unit/Validator/Constraints/Pdf/ValidOrientationValidatorTest.php +++ b/tests/Unit/Validator/Constraints/Pdf/ValidOrientationValidatorTest.php @@ -4,6 +4,7 @@ namespace Setono\SyliusGiftCardPlugin\Tests\Unit\Validator\Constraints\Pdf; +use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\TestCase; use Prophecy\PhpUnit\ProphecyTrait; use Setono\SyliusGiftCardPlugin\Provider\PdfRenderingOptionsProviderInterface; @@ -18,9 +19,7 @@ class ValidOrientationValidatorTest extends TestCase { use ProphecyTrait; - /** - * @test - */ + #[Test] public function it_throws_exception_if_constraint_has_wrong_type(): void { $validator = new ValidOrientationValidator([PdfRenderingOptionsProviderInterface::ORIENTATION_PORTRAIT]); @@ -30,9 +29,7 @@ public function it_throws_exception_if_constraint_has_wrong_type(): void $validator->validate('Any orientation', $constraint); } - /** - * @test - */ + #[Test] public function it_does_nothing_if_value_is_null(): void { $validator = new ValidOrientationValidator([PdfRenderingOptionsProviderInterface::ORIENTATION_PORTRAIT]); @@ -45,9 +42,7 @@ public function it_does_nothing_if_value_is_null(): void $validator->validate(null, $constraint); } - /** - * @test - */ + #[Test] public function it_adds_violation_if_orientation_is_invalid(): void { $validator = new ValidOrientationValidator([PdfRenderingOptionsProviderInterface::ORIENTATION_PORTRAIT]); diff --git a/tests/Unit/Validator/Constraints/Pdf/ValidPageSizeValidatorTest.php b/tests/Unit/Validator/Constraints/Pdf/ValidPageSizeValidatorTest.php index 7bb682c6..185d06f5 100644 --- a/tests/Unit/Validator/Constraints/Pdf/ValidPageSizeValidatorTest.php +++ b/tests/Unit/Validator/Constraints/Pdf/ValidPageSizeValidatorTest.php @@ -4,6 +4,7 @@ namespace Setono\SyliusGiftCardPlugin\Tests\Unit\Validator\Constraints\Pdf; +use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\TestCase; use Prophecy\PhpUnit\ProphecyTrait; use Setono\SyliusGiftCardPlugin\Provider\PdfRenderingOptionsProviderInterface; @@ -18,9 +19,7 @@ class ValidPageSizeValidatorTest extends TestCase { use ProphecyTrait; - /** - * @test - */ + #[Test] public function it_throws_exception_if_constraint_has_wrong_type(): void { $validator = new ValidPageSizeValidator([PdfRenderingOptionsProviderInterface::PAGE_SIZE_A0]); @@ -30,9 +29,7 @@ public function it_throws_exception_if_constraint_has_wrong_type(): void $validator->validate('Any value', $constraint); } - /** - * @test - */ + #[Test] public function it_does_nothing_if_value_is_null(): void { $validator = new ValidPageSizeValidator([PdfRenderingOptionsProviderInterface::PAGE_SIZE_A0]); @@ -44,9 +41,7 @@ public function it_does_nothing_if_value_is_null(): void $validator->validate(null, $constraint); } - /** - * @test - */ + #[Test] public function it_adds_violation_if_orientation_is_invalid(): void { $validator = new ValidPageSizeValidator([PdfRenderingOptionsProviderInterface::PAGE_SIZE_A1]); From d1e1ea6e64c0fd08308ca68748bb18930a9fd3a6 Mon Sep 17 00:00:00 2001 From: Nicolo Singer Date: Tue, 18 Mar 2025 11:17:43 -0500 Subject: [PATCH 10/15] chore: removed jms serialization and use symfony one Signed-off-by: Nicolo Singer --- composer.json | 1 - src/Resources/config/app/config.yaml | 58 +++------------------------ src/Resources/config/sylius_ui.yaml | 59 ++++++++++++++++++++++++---- 3 files changed, 58 insertions(+), 60 deletions(-) diff --git a/composer.json b/composer.json index b5a90f76..8c744d2c 100644 --- a/composer.json +++ b/composer.json @@ -63,7 +63,6 @@ "dmore/chrome-mink-driver": "^2.9", "doctrine/doctrine-bundle": "^2.7", "infection/infection": "^0.27.10", - "jms/serializer-bundle": "^4.2", "lexik/jwt-authentication-bundle": "^3.1", "matthiasnoback/symfony-config-test": "^4.3 || ^5.1", "matthiasnoback/symfony-dependency-injection-test": "^4.3 || ^5.1", diff --git a/src/Resources/config/app/config.yaml b/src/Resources/config/app/config.yaml index 91154c3e..95026897 100644 --- a/src/Resources/config/app/config.yaml +++ b/src/Resources/config/app/config.yaml @@ -15,12 +15,12 @@ sylius_mailer: subject: setono_sylius_gift_card.email.your_gift_cards_you_bought_in_the_order template: "@SetonoSyliusGiftCardPlugin/Email/giftCardsFromOrder.html.twig" -jms_serializer: - metadata: - directories: - setono-sylius-gift-card-sylius: - namespace_prefix: "Setono\\SyliusGiftCardPlugin\\Model" - path: "@SetonoSyliusGiftCardPlugin/Resources/config/serializer" +framework: + serializer: + enabled: true + mapping: + paths: + - '%kernel.project_dir%/vendor/setono/sylius-gift-card-plugin/src/Resources/config/serialization/' liip_imagine: filter_sets: @@ -28,49 +28,3 @@ liip_imagine: filters: thumbnail: { size: [1200], mode: inset } -sylius_ui: - events: - setono_sylius_gift_card.admin.gift_card_configuration.create.javascripts: - blocks: - preview_uploaded_image: '@SetonoSyliusGiftCardPlugin/Admin/GiftCardConfiguration/_javascripts.html.twig' - - setono_sylius_gift_card.admin.gift_card_configuration.update.javascripts: - blocks: - preview_uploaded_image: '@SetonoSyliusGiftCardPlugin/Admin/GiftCardConfiguration/_javascripts.html.twig' - live_pdf_rendering_js: '@SetonoSyliusGiftCardPlugin/Admin/GiftCardConfiguration/Update/_javascripts.html.twig' - - setono_sylius_gift_card.admin.gift_card.create.javascripts: - blocks: - send_customer_email_js: '@SetonoSyliusGiftCardPlugin/Admin/GiftCard/Create/_javascripts.html.twig' - - setono_sylius_gift_card.shop.account.gift_card.index.after_content_header: - blocks: - after_content_header_legacy: - template: "@SyliusUi/Block/_legacySonataEvent.html.twig" - priority: 50 - context: - event: setono_sylius_gift_card.shop.account.gift_card.index.after_content_header - - setono_sylius_gift_card.shop.account.gift_card.index.after_grid: - blocks: - after_content_header_legacy: - template: "@SyliusUi/Block/_legacySonataEvent.html.twig" - priority: 50 - context: - event: setono_sylius_gift_card.shop.account.gift_card.index.after_grid - - setono_sylius_gift_card.shop.account.gift_card.index.header: - blocks: - after_content_header_legacy: - template: "@SyliusUi/Block/_legacySonataEvent.html.twig" - priority: 50 - context: - event: setono_sylius_gift_card.shop.account.gift_card.index.header - - setono_sylius_gift_card.shop.cart.summary.applied_gift_cards: - blocks: - after_content_header_legacy: - template: "@SyliusUi/Block/_legacySonataEvent.html.twig" - priority: 50 - context: - event: setono_sylius_gift_card.shop.cart.summary.applied_gift_cards diff --git a/src/Resources/config/sylius_ui.yaml b/src/Resources/config/sylius_ui.yaml index 7a641d5e..ce106367 100644 --- a/src/Resources/config/sylius_ui.yaml +++ b/src/Resources/config/sylius_ui.yaml @@ -1,7 +1,52 @@ -sylius_ui: - events: - sylius.shop.product.show.add_to_cart_form: - blocks: - setono_sylius_gift_card_information: - template: '@SetonoSyliusGiftCardPlugin/Shop/Product/Show/_addToCartGiftCardInformation.html.twig' - priority: 10 +#sylius_ui: +# events: +# setono_sylius_gift_card.admin.gift_card_configuration.create.javascripts: +# blocks: +# preview_uploaded_image: '@SetonoSyliusGiftCardPlugin/Admin/GiftCardConfiguration/_javascripts.html.twig' +# +# setono_sylius_gift_card.admin.gift_card_configuration.update.javascripts: +# blocks: +# preview_uploaded_image: '@SetonoSyliusGiftCardPlugin/Admin/GiftCardConfiguration/_javascripts.html.twig' +# live_pdf_rendering_js: '@SetonoSyliusGiftCardPlugin/Admin/GiftCardConfiguration/Update/_javascripts.html.twig' +# +# setono_sylius_gift_card.admin.gift_card.create.javascripts: +# blocks: +# send_customer_email_js: '@SetonoSyliusGiftCardPlugin/Admin/GiftCard/Create/_javascripts.html.twig' +# +# setono_sylius_gift_card.shop.account.gift_card.index.after_content_header: +# blocks: +# after_content_header_legacy: +# template: "@SyliusUi/Block/_legacySonataEvent.html.twig" +# priority: 50 +# context: +# event: setono_sylius_gift_card.shop.account.gift_card.index.after_content_header +# +# setono_sylius_gift_card.shop.account.gift_card.index.after_grid: +# blocks: +# after_content_header_legacy: +# template: "@SyliusUi/Block/_legacySonataEvent.html.twig" +# priority: 50 +# context: +# event: setono_sylius_gift_card.shop.account.gift_card.index.after_grid +# +# setono_sylius_gift_card.shop.account.gift_card.index.header: +# blocks: +# after_content_header_legacy: +# template: "@SyliusUi/Block/_legacySonataEvent.html.twig" +# priority: 50 +# context: +# event: setono_sylius_gift_card.shop.account.gift_card.index.header +# +# setono_sylius_gift_card.shop.cart.summary.applied_gift_cards: +# blocks: +# after_content_header_legacy: +# template: "@SyliusUi/Block/_legacySonataEvent.html.twig" +# priority: 50 +# context: +# event: setono_sylius_gift_card.shop.cart.summary.applied_gift_cards +# +# sylius.shop.product.show.add_to_cart_form: +# blocks: +# setono_sylius_gift_card_information: +# template: '@SetonoSyliusGiftCardPlugin/Shop/Product/Show/_addToCartGiftCardInformation.html.twig' +# priority: 10 From 366fb63457deef3e5b9f64a221a76ce611a393f7 Mon Sep 17 00:00:00 2001 From: Nicolo Singer Date: Tue, 18 Mar 2025 12:02:51 -0500 Subject: [PATCH 11/15] chore: sylius 2.x update Signed-off-by: Nicolo Singer --- src/Api/Command/AddItemToCart.php | 4 ++-- src/Api/Command/ConfigurationCodeAwareInterface.php | 4 +--- src/Api/Command/GiftCardCodeAwareInterface.php | 4 +--- src/Resources/config/services/api/command_handler.xml | 10 +++++----- 4 files changed, 9 insertions(+), 13 deletions(-) diff --git a/src/Api/Command/AddItemToCart.php b/src/Api/Command/AddItemToCart.php index aa55c9f8..6832c843 100644 --- a/src/Api/Command/AddItemToCart.php +++ b/src/Api/Command/AddItemToCart.php @@ -8,9 +8,9 @@ class AddItemToCart extends BaseAddItemToCart { - public function __construct(string $productVariantCode, int $quantity, protected ?int $amount = null, protected ?string $customMessage = null) + public function __construct(string $orderTokenValue, string $productVariantCode, int $quantity, protected ?int $amount = null, protected ?string $customMessage = null) { - parent::__construct($productVariantCode, $quantity); + parent::__construct($orderTokenValue, $productVariantCode, $quantity); } public function getAmount(): ?int diff --git a/src/Api/Command/ConfigurationCodeAwareInterface.php b/src/Api/Command/ConfigurationCodeAwareInterface.php index 945d1757..5a7596e5 100644 --- a/src/Api/Command/ConfigurationCodeAwareInterface.php +++ b/src/Api/Command/ConfigurationCodeAwareInterface.php @@ -4,9 +4,7 @@ namespace Setono\SyliusGiftCardPlugin\Api\Command; -use Sylius\Bundle\ApiBundle\Command\CommandAwareDataTransformerInterface; - -interface ConfigurationCodeAwareInterface extends CommandAwareDataTransformerInterface +interface ConfigurationCodeAwareInterface { public function getConfigurationCode(): ?string; diff --git a/src/Api/Command/GiftCardCodeAwareInterface.php b/src/Api/Command/GiftCardCodeAwareInterface.php index 82189996..2759b92a 100644 --- a/src/Api/Command/GiftCardCodeAwareInterface.php +++ b/src/Api/Command/GiftCardCodeAwareInterface.php @@ -4,9 +4,7 @@ namespace Setono\SyliusGiftCardPlugin\Api\Command; -use Sylius\Bundle\ApiBundle\Command\CommandAwareDataTransformerInterface; - -interface GiftCardCodeAwareInterface extends CommandAwareDataTransformerInterface +interface GiftCardCodeAwareInterface { public function getGiftCardCode(): ?string; diff --git a/src/Resources/config/services/api/command_handler.xml b/src/Resources/config/services/api/command_handler.xml index cacbbfb8..2b456168 100644 --- a/src/Resources/config/services/api/command_handler.xml +++ b/src/Resources/config/services/api/command_handler.xml @@ -14,7 +14,7 @@ - + - + - + @@ -46,7 +46,7 @@ - + - + From b091f72f18809def1557bd4cc997ea07480dfa2d Mon Sep 17 00:00:00 2001 From: Nicolo Singer Date: Tue, 18 Mar 2025 13:04:11 -0500 Subject: [PATCH 12/15] fix: adjustment clearing types are loaded by parameters Signed-off-by: Nicolo Singer --- composer.json | 2 +- .../CommandHandler/AddItemToCartHandler.php | 11 +++++++++-- ...UploadGiftCardConfigurationImageAction.php | 8 ++++++-- .../GiftCardsByLoggedInUserExtension.php | 16 ++++++---------- ...djustmentsToOrderAdjustmentClearerPass.php | 17 +++++++---------- src/Factory/GiftCardFactory.php | 10 +++------- src/Form/Extension/AddToCartTypeExtension.php | 2 +- .../Type/AddToCartGiftCardInformationType.php | 9 +++++++-- ...tono_sylius_gift_card_admin_gift_card.yaml | 5 ++--- .../GiftCard.xml | 0 .../GiftCardConfiguration.xml | 0 .../GiftCardConfigurationImage.xml | 0 .../Order.yaml | 0 src/Resources/config/routes/admin.yaml | 8 ++++---- .../config/services/api/command_handler.xml | 6 +++--- .../config/services/api/controller.xml | 2 +- .../config/services/event_listener.xml | 2 +- src/Resources/config/services/factory.xml | 2 +- src/Resources/config/services/fixture.xml | 2 +- src/Resources/config/services/form.xml | 2 +- src/Resources/config/services/serializer.xml | 2 +- .../views/Admin/giftCardBalance.html.twig | 19 +++++++++++-------- .../GiftCardConfigurationNormalizer.php | 11 +++++++++-- .../Normalizer/GiftCardNormalizer.php | 17 +++++++++++++---- 24 files changed, 88 insertions(+), 65 deletions(-) rename src/Resources/config/{api_resources => legacy_api_resources}/GiftCard.xml (100%) rename src/Resources/config/{api_resources => legacy_api_resources}/GiftCardConfiguration.xml (100%) rename src/Resources/config/{api_resources => legacy_api_resources}/GiftCardConfigurationImage.xml (100%) rename src/Resources/config/{api_resources => legacy_api_resources}/Order.yaml (100%) diff --git a/composer.json b/composer.json index 8c744d2c..e4257fce 100644 --- a/composer.json +++ b/composer.json @@ -7,7 +7,7 @@ "php": ">=8.1", "ext-filter": "*", "ext-mbstring": "*", - "api-platform/core": "^4.0", + "api-platform/core": "^4.0.3", "doctrine/collections": "^2.2", "doctrine/dbal": "^2.13 || ^3.0", "doctrine/orm": "^2.7", diff --git a/src/Api/CommandHandler/AddItemToCartHandler.php b/src/Api/CommandHandler/AddItemToCartHandler.php index 2cdf6c9e..1a811167 100644 --- a/src/Api/CommandHandler/AddItemToCartHandler.php +++ b/src/Api/CommandHandler/AddItemToCartHandler.php @@ -22,8 +22,15 @@ final class AddItemToCartHandler { - public function __construct(private readonly OrderRepositoryInterface $orderRepository, private readonly ProductVariantRepositoryInterface $productVariantRepository, private readonly OrderModifierInterface $orderModifier, private readonly CartItemFactoryInterface $cartItemFactory, private readonly OrderItemQuantityModifierInterface $orderItemQuantityModifier, private readonly GiftCardFactoryInterface $giftCardFactory, private readonly EntityManagerInterface $giftCardManager) - { + public function __construct( + private readonly OrderRepositoryInterface $orderRepository, + private readonly ProductVariantRepositoryInterface $productVariantRepository, + private readonly OrderModifierInterface $orderModifier, + private readonly CartItemFactoryInterface $cartItemFactory, + private readonly OrderItemQuantityModifierInterface $orderItemQuantityModifier, + private readonly GiftCardFactoryInterface $giftCardFactory, + private readonly EntityManagerInterface $giftCardManager + ) { } public function __invoke(SyliusAddItemToCart $addItemToCart): OrderInterface diff --git a/src/Api/Controller/Action/UploadGiftCardConfigurationImageAction.php b/src/Api/Controller/Action/UploadGiftCardConfigurationImageAction.php index 1f064f2f..6e2521e8 100644 --- a/src/Api/Controller/Action/UploadGiftCardConfigurationImageAction.php +++ b/src/Api/Controller/Action/UploadGiftCardConfigurationImageAction.php @@ -20,8 +20,12 @@ final class UploadGiftCardConfigurationImageAction /** * @param LegacyIriConverterInterface|IriConverterInterface $iriConverter */ - public function __construct(private readonly FactoryInterface $giftCardConfigurationImageFactory, private readonly RepositoryInterface $giftCardConfigurationImageRepository, private readonly ImageUploaderInterface $imageUploader, private $iriConverter) - { + public function __construct( + private readonly FactoryInterface $giftCardConfigurationImageFactory, + private readonly RepositoryInterface $giftCardConfigurationImageRepository, + private readonly ImageUploaderInterface $imageUploader, + private $iriConverter + ) { } public function __invoke(Request $request): GiftCardConfigurationImageInterface diff --git a/src/Api/Doctrine/QueryCollectionExtension/GiftCardsByLoggedInUserExtension.php b/src/Api/Doctrine/QueryCollectionExtension/GiftCardsByLoggedInUserExtension.php index 49757493..66aee031 100644 --- a/src/Api/Doctrine/QueryCollectionExtension/GiftCardsByLoggedInUserExtension.php +++ b/src/Api/Doctrine/QueryCollectionExtension/GiftCardsByLoggedInUserExtension.php @@ -4,8 +4,9 @@ namespace Setono\SyliusGiftCardPlugin\Api\Doctrine\QueryCollectionExtension; -use ApiPlatform\Core\Bridge\Doctrine\Orm\Extension\ContextAwareQueryCollectionExtensionInterface; -use ApiPlatform\Core\Bridge\Doctrine\Orm\Util\QueryNameGeneratorInterface; +use ApiPlatform\Doctrine\Orm\Extension\QueryCollectionExtensionInterface; +use ApiPlatform\Doctrine\Orm\Util\QueryNameGeneratorInterface; +use ApiPlatform\Metadata\Operation; use Doctrine\DBAL\Types\Types; use Doctrine\ORM\QueryBuilder; use Setono\SyliusGiftCardPlugin\Model\GiftCardInterface; @@ -15,19 +16,14 @@ use Sylius\Component\Core\Model\ShopUserInterface; use Symfony\Component\Security\Core\Exception\AccessDeniedException; -final class GiftCardsByLoggedInUserExtension implements ContextAwareQueryCollectionExtensionInterface +final class GiftCardsByLoggedInUserExtension implements QueryCollectionExtensionInterface { public function __construct(private readonly UserContextInterface $userContext) { } - public function applyToCollection( - QueryBuilder $queryBuilder, - QueryNameGeneratorInterface $queryNameGenerator, - string $resourceClass, - string $operationName = null, - array $context = [], - ): void { + public function applyToCollection(QueryBuilder $queryBuilder, QueryNameGeneratorInterface $queryNameGenerator, string $resourceClass, ?Operation $operation = null, array $context = []): void + { if (!is_a($resourceClass, GiftCardInterface::class, true)) { return; } diff --git a/src/DependencyInjection/Compiler/AddAdjustmentsToOrderAdjustmentClearerPass.php b/src/DependencyInjection/Compiler/AddAdjustmentsToOrderAdjustmentClearerPass.php index ceb73b3b..563a9f23 100644 --- a/src/DependencyInjection/Compiler/AddAdjustmentsToOrderAdjustmentClearerPass.php +++ b/src/DependencyInjection/Compiler/AddAdjustmentsToOrderAdjustmentClearerPass.php @@ -11,19 +11,16 @@ final class AddAdjustmentsToOrderAdjustmentClearerPass implements CompilerPassInterface { + private const ADJUSTMENT_CLEARING_TYPES = 'sylius.order_processing.adjustment_clearing_types'; + public function process(ContainerBuilder $container): void { - if (!$container->has('sylius.order_processing.order_adjustments_clearer')) { + if (!$container->hasParameter(self::ADJUSTMENT_CLEARING_TYPES)) { return; } - - $clearerDefinition = $container->getDefinition('sylius.order_processing.order_adjustments_clearer'); - - $adjustmentsToRemove = $clearerDefinition->getArgument(0); - Assert::isArray($adjustmentsToRemove); - - $adjustmentsToRemove[] = AdjustmentInterface::ORDER_GIFT_CARD_ADJUSTMENT; - - $clearerDefinition->setArgument(0, $adjustmentsToRemove); + $types = $container->getParameter(self::ADJUSTMENT_CLEARING_TYPES); + Assert::isArray($types); + $types[] = AdjustmentInterface::ORDER_GIFT_CARD_ADJUSTMENT; + $container->setParameter(self::ADJUSTMENT_CLEARING_TYPES, $types); } } diff --git a/src/Factory/GiftCardFactory.php b/src/Factory/GiftCardFactory.php index c044cf17..7bce4bfe 100644 --- a/src/Factory/GiftCardFactory.php +++ b/src/Factory/GiftCardFactory.php @@ -6,11 +6,11 @@ use DateTimeImmutable; use DateTimeInterface; +use Psr\Clock\ClockInterface; use Setono\SyliusGiftCardPlugin\Generator\GiftCardCodeGeneratorInterface; use Setono\SyliusGiftCardPlugin\Model\GiftCardInterface; use Setono\SyliusGiftCardPlugin\Model\OrderItemUnitInterface; use Setono\SyliusGiftCardPlugin\Provider\GiftCardConfigurationProviderInterface; -use Sylius\Bundle\ShippingBundle\Provider\DateTimeProvider; use Sylius\Component\Core\Model\ChannelInterface; use Sylius\Component\Core\Model\CustomerInterface; use Sylius\Component\Core\Model\OrderInterface; @@ -24,8 +24,7 @@ public function __construct( private readonly FactoryInterface $decoratedFactory, private readonly GiftCardCodeGeneratorInterface $giftCardCodeGenerator, private readonly GiftCardConfigurationProviderInterface $giftCardConfigurationProvider, - /** @psalm-suppress DeprecatedInterface */ - private readonly DateTimeProvider $dateTimeProvider, + private readonly ClockInterface $clock, private readonly CurrencyContextInterface $currencyContext, ) { } @@ -47,10 +46,7 @@ public function createForChannel(ChannelInterface $channel): GiftCardInterface $channelConfiguration = $this->giftCardConfigurationProvider->getConfigurationForGiftCard($giftCard); $validityPeriod = $channelConfiguration->getDefaultValidityPeriod(); if (null !== $validityPeriod) { - $today = $this->dateTimeProvider->today(); - // Since the interface is types to DateTimeInterface, the modify method does not exist - // whereas it does in DateTime and DateTimeImmutable - Assert::isInstanceOf($today, DateTimeImmutable::class); + $today = $this->clock->now(); /** @var DateTimeInterface $today */ $today = $today->modify('+' . $validityPeriod); $giftCard->setExpiresAt($today); diff --git a/src/Form/Extension/AddToCartTypeExtension.php b/src/Form/Extension/AddToCartTypeExtension.php index fb7b10b5..532f6c29 100644 --- a/src/Form/Extension/AddToCartTypeExtension.php +++ b/src/Form/Extension/AddToCartTypeExtension.php @@ -88,7 +88,7 @@ public function populateCartItem(FormEvent $event): void if ($product->isGiftCardAmountConfigurable()) { $cartItem->setUnitPrice($giftCardInformation->getAmount()); $cartItem->setImmutable(true); - } else { + } elseif (!$cartItem->isImmutable()) { $channel = $data->getCart()->getChannel(); Assert::notNull($channel); $variant = $data->getCartItem()->getVariant(); diff --git a/src/Form/Type/AddToCartGiftCardInformationType.php b/src/Form/Type/AddToCartGiftCardInformationType.php index a7d75b8a..936b7b72 100644 --- a/src/Form/Type/AddToCartGiftCardInformationType.php +++ b/src/Form/Type/AddToCartGiftCardInformationType.php @@ -21,8 +21,13 @@ final class AddToCartGiftCardInformationType extends AbstractType { - public function __construct(private readonly string $dataClass, private readonly array $validationGroups, private readonly CurrencyContextInterface $currencyContext, private readonly ProductVariantResolverInterface $productVariantResolver, private readonly ChannelContextInterface $channelContext) - { + public function __construct( + private readonly string $dataClass, + private readonly array $validationGroups, + private readonly CurrencyContextInterface $currencyContext, + private readonly ProductVariantResolverInterface $productVariantResolver, + private readonly ChannelContextInterface $channelContext + ) { } public function buildForm(FormBuilderInterface $builder, array $options): void diff --git a/src/Resources/config/grids/setono_sylius_gift_card_admin_gift_card.yaml b/src/Resources/config/grids/setono_sylius_gift_card_admin_gift_card.yaml index ee0bc509..6de660eb 100644 --- a/src/Resources/config/grids/setono_sylius_gift_card_admin_gift_card.yaml +++ b/src/Resources/config/grids/setono_sylius_gift_card_admin_gift_card.yaml @@ -32,13 +32,13 @@ sylius_grid: label: sylius.ui.channel sortable: channel.code options: - template: "@SyliusAdmin/Order/Grid/Field/channel.html.twig" + template: "@SyliusAdmin/shared/grid/field/channel.html.twig" enabled: type: twig label: sylius.ui.enabled sortable: ~ options: - template: "@SyliusUi/Grid/Field/enabled.html.twig" + template: "@SyliusUi/grid/field/enabled.html.twig" createdAt: type: datetime label: sylius.ui.created @@ -86,7 +86,6 @@ sylius_grid: configuration: type: default label: setono_sylius_gift_card.ui.configuration - icon: cog options: link: route: setono_sylius_gift_card_admin_gift_card_configuration_index diff --git a/src/Resources/config/api_resources/GiftCard.xml b/src/Resources/config/legacy_api_resources/GiftCard.xml similarity index 100% rename from src/Resources/config/api_resources/GiftCard.xml rename to src/Resources/config/legacy_api_resources/GiftCard.xml diff --git a/src/Resources/config/api_resources/GiftCardConfiguration.xml b/src/Resources/config/legacy_api_resources/GiftCardConfiguration.xml similarity index 100% rename from src/Resources/config/api_resources/GiftCardConfiguration.xml rename to src/Resources/config/legacy_api_resources/GiftCardConfiguration.xml diff --git a/src/Resources/config/api_resources/GiftCardConfigurationImage.xml b/src/Resources/config/legacy_api_resources/GiftCardConfigurationImage.xml similarity index 100% rename from src/Resources/config/api_resources/GiftCardConfigurationImage.xml rename to src/Resources/config/legacy_api_resources/GiftCardConfigurationImage.xml diff --git a/src/Resources/config/api_resources/Order.yaml b/src/Resources/config/legacy_api_resources/Order.yaml similarity index 100% rename from src/Resources/config/api_resources/Order.yaml rename to src/Resources/config/legacy_api_resources/Order.yaml diff --git a/src/Resources/config/routes/admin.yaml b/src/Resources/config/routes/admin.yaml index 31a37f97..79fc6b1a 100644 --- a/src/Resources/config/routes/admin.yaml +++ b/src/Resources/config/routes/admin.yaml @@ -4,7 +4,7 @@ setono_sylius_gift_card_admin_gift_card: section: admin permission: true only: [index, update, delete, bulkDelete] - templates: '@SyliusAdmin\\Crud' + templates: "@SyliusAdmin/shared/crud" redirect: index grid: setono_sylius_gift_card_admin_gift_card vars: @@ -44,7 +44,7 @@ setono_sylius_gift_card_admin_gift_card_configuration: section: admin permission: true only: [index, create, update, delete, bulkDelete] - templates: '@SyliusAdmin\\Crud' + templates: "@SyliusAdmin/shared/crud" redirect: index grid: setono_sylius_gift_card_admin_gift_card_configuration vars: @@ -86,7 +86,7 @@ setono_sylius_gift_card_admin_gift_card_create: method: createForChannelFromAdmin arguments: channel: "expr:service('sylius.repository.channel').findOneByCode($channelCode)" - template: '@SyliusAdmin/Crud/create.html.twig' + template: '@SyliusAdmin/shared/crud/create.html.twig' grid: setono_sylius_gift_card_admin_gift_card section: admin redirect: @@ -109,7 +109,7 @@ setono_sylius_gift_card_admin_gift_card_orders_index: route: parameters: id: $id - template: '@SyliusAdmin/Crud/index.html.twig' + template: '@SyliusAdmin/shared/crud/index.html.twig' grid: setono_sylius_gift_card_admin_gift_card_order section: admin permission: true diff --git a/src/Resources/config/services/api/command_handler.xml b/src/Resources/config/services/api/command_handler.xml index 2b456168..36bdfaac 100644 --- a/src/Resources/config/services/api/command_handler.xml +++ b/src/Resources/config/services/api/command_handler.xml @@ -37,12 +37,12 @@ - + - + - + diff --git a/src/Resources/config/services/api/controller.xml b/src/Resources/config/services/api/controller.xml index 2324a2a3..4bdbfd4b 100644 --- a/src/Resources/config/services/api/controller.xml +++ b/src/Resources/config/services/api/controller.xml @@ -9,7 +9,7 @@ class="Setono\SyliusGiftCardPlugin\Api\Controller\Action\UploadGiftCardConfigurationImageAction"> - + diff --git a/src/Resources/config/services/event_listener.xml b/src/Resources/config/services/event_listener.xml index 1eb03eed..703908a8 100644 --- a/src/Resources/config/services/event_listener.xml +++ b/src/Resources/config/services/event_listener.xml @@ -25,7 +25,7 @@ - + diff --git a/src/Resources/config/services/factory.xml b/src/Resources/config/services/factory.xml index 7b1dfadc..b67b5ca5 100644 --- a/src/Resources/config/services/factory.xml +++ b/src/Resources/config/services/factory.xml @@ -10,7 +10,7 @@ - + diff --git a/src/Resources/config/services/fixture.xml b/src/Resources/config/services/fixture.xml index 71763f39..fc2e3031 100644 --- a/src/Resources/config/services/fixture.xml +++ b/src/Resources/config/services/fixture.xml @@ -19,7 +19,7 @@ - + diff --git a/src/Resources/config/services/form.xml b/src/Resources/config/services/form.xml index 2b17d91b..19d1180f 100644 --- a/src/Resources/config/services/form.xml +++ b/src/Resources/config/services/form.xml @@ -63,7 +63,7 @@ %setono_sylius_gift_card.order.model.gift_card_information.class% %setono_sylius_gift_card.form.type.add_to_cart_gift_card_information.validation_groups% - + diff --git a/src/Resources/config/services/serializer.xml b/src/Resources/config/services/serializer.xml index b746ac67..abc728fb 100644 --- a/src/Resources/config/services/serializer.xml +++ b/src/Resources/config/services/serializer.xml @@ -7,7 +7,7 @@ - + diff --git a/src/Resources/views/Admin/giftCardBalance.html.twig b/src/Resources/views/Admin/giftCardBalance.html.twig index 9f2c1a11..8a4fbb76 100644 --- a/src/Resources/views/Admin/giftCardBalance.html.twig +++ b/src/Resources/views/Admin/giftCardBalance.html.twig @@ -1,13 +1,15 @@ {# @var \Setono\SyliusGiftCardPlugin\Model\GiftCardBalanceCollection giftCardBalanceCollection #} -{% extends '@SyliusAdmin/layout.html.twig' %} +{% extends '@SyliusAdmin/shared/layout/base.html.twig' %} -{% import '@SyliusAdmin/Macro/breadcrumb.html.twig' as breadcrumb %} -{% import "@SyliusAdmin/Common/Macro/money.html.twig" as money %} +{% import '@SyliusAdmin/shared/helper/breadcrumbs.html.twig' as breadcrumb %} +{% import "@SyliusAdmin/shared/helper/money.html.twig" as money %} {% block title %}{{ 'setono_sylius_gift_card.ui.balance'|trans }} {{ parent() }}{% endblock %} -{% block content %} +{% block body %} + {% hook 'add_admin.custom' %} +

@@ -20,13 +22,13 @@

{% set breadcrumbs = [ - { label: 'sylius.ui.administration'|trans, url: path('sylius_admin_dashboard') }, - { label: 'setono_sylius_gift_card.ui.gift_cards'|trans, url: path('setono_sylius_gift_card_admin_gift_card_index') }, - { label: 'setono_sylius_gift_card.ui.balance'|trans } + { name: 'sylius.ui.administration'|trans, url: path('sylius_admin_dashboard') }, + { name: 'setono_sylius_gift_card.ui.gift_cards'|trans, url: path('setono_sylius_gift_card_admin_gift_card_index') }, + { name: 'setono_sylius_gift_card.ui.balance'|trans } ] %} - {{ breadcrumb.crumble(breadcrumbs) }} + {{ breadcrumb.breadcrumbs(breadcrumbs) }}
@@ -58,4 +60,5 @@
+
{% endblock %} diff --git a/src/Serializer/Normalizer/GiftCardConfigurationNormalizer.php b/src/Serializer/Normalizer/GiftCardConfigurationNormalizer.php index 79681248..804f3fd9 100644 --- a/src/Serializer/Normalizer/GiftCardConfigurationNormalizer.php +++ b/src/Serializer/Normalizer/GiftCardConfigurationNormalizer.php @@ -10,11 +10,11 @@ use Setono\SyliusGiftCardPlugin\Model\GiftCardConfigurationInterface; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\RequestStack; -use Symfony\Component\Serializer\Normalizer\ContextAwareNormalizerInterface; +use Symfony\Component\Serializer\Normalizer\NormalizerInterface; use Symfony\Component\Serializer\Normalizer\ObjectNormalizer; use Webmozart\Assert\Assert; -final class GiftCardConfigurationNormalizer implements ContextAwareNormalizerInterface +final class GiftCardConfigurationNormalizer implements NormalizerInterface { private readonly string $publicMediaDirectory; @@ -77,4 +77,11 @@ public function supportsNormalization($data, $format = null, array $context = [] true, ); } + + public function getSupportedTypes(?string $format): array + { + return [ + GiftCardConfigurationInterface::class => true, + ]; + } } diff --git a/src/Serializer/Normalizer/GiftCardNormalizer.php b/src/Serializer/Normalizer/GiftCardNormalizer.php index 8192a53b..1f32f906 100644 --- a/src/Serializer/Normalizer/GiftCardNormalizer.php +++ b/src/Serializer/Normalizer/GiftCardNormalizer.php @@ -8,14 +8,16 @@ use Setono\SyliusGiftCardPlugin\Exception\UnexpectedTypeException; use Setono\SyliusGiftCardPlugin\Model\GiftCardInterface; use Sylius\Bundle\MoneyBundle\Formatter\MoneyFormatterInterface; -use Symfony\Component\Serializer\Normalizer\ContextAwareNormalizerInterface; +use Symfony\Component\Serializer\Normalizer\NormalizerInterface; use Symfony\Component\Serializer\Normalizer\ObjectNormalizer; use Webmozart\Assert\Assert; -final class GiftCardNormalizer implements ContextAwareNormalizerInterface +final class GiftCardNormalizer implements NormalizerInterface { - public function __construct(private readonly ObjectNormalizer $objectNormalizer, private readonly MoneyFormatterInterface $moneyFormatter) - { + public function __construct( + private readonly ObjectNormalizer $objectNormalizer, + private readonly MoneyFormatterInterface $moneyFormatter + ) { } /** @@ -51,4 +53,11 @@ public function supportsNormalization($data, $format = null, array $context = [] return $data instanceof GiftCardInterface && in_array('setono:sylius-gift-card:render', $groups, true); } + + public function getSupportedTypes(?string $format): array + { + return [ + GiftCardInterface::class => true, + ]; + } } From e7e9cfaf69b50629b2eb677153f35fa1856acecb Mon Sep 17 00:00:00 2001 From: Marc Wieland Date: Mon, 7 Apr 2025 13:52:15 -0500 Subject: [PATCH 13/15] feat: update gift balance template for Sylius 2 --- .../views/Admin/giftCardBalance.html.twig | 47 ++++++++++--------- 1 file changed, 26 insertions(+), 21 deletions(-) diff --git a/src/Resources/views/Admin/giftCardBalance.html.twig b/src/Resources/views/Admin/giftCardBalance.html.twig index 8a4fbb76..88b15e60 100644 --- a/src/Resources/views/Admin/giftCardBalance.html.twig +++ b/src/Resources/views/Admin/giftCardBalance.html.twig @@ -4,36 +4,41 @@ {% import '@SyliusAdmin/shared/helper/breadcrumbs.html.twig' as breadcrumb %} {% import "@SyliusAdmin/shared/helper/money.html.twig" as money %} +{% import '@SyliusAdmin/shared/helper/header.html.twig' as header %} {% block title %}{{ 'setono_sylius_gift_card.ui.balance'|trans }} {{ parent() }}{% endblock %} {% block body %} {% hook 'add_admin.custom' %}
-
-
-

- -
- {{ 'setono_sylius_gift_card.ui.balance'|trans }} + +

+
+
- {% set breadcrumbs = [ - { name: 'sylius.ui.administration'|trans, url: path('sylius_admin_dashboard') }, - { name: 'setono_sylius_gift_card.ui.gift_cards'|trans, url: path('setono_sylius_gift_card_admin_gift_card_index') }, - { name: 'setono_sylius_gift_card.ui.balance'|trans } - ] - %} - - {{ breadcrumb.breadcrumbs(breadcrumbs) }} - -
-
-
- +
+
+
+
@@ -61,4 +66,4 @@ -{% endblock %} +{% endblock %} \ No newline at end of file From a355211e20618e7471c3b3e72de3def3abf320b4 Mon Sep 17 00:00:00 2001 From: Marc Wieland Date: Mon, 7 Apr 2025 14:34:08 -0500 Subject: [PATCH 14/15] feat: style grid and actions buttons on index --- .../Admin/GiftCard/Grid/Action/create.html.twig | 14 ++++++++------ .../Grid/Action/delete_conditional.html.twig | 2 -- .../Grid/Action/gift_card_balance.html.twig | 15 +++++++-------- .../Grid/Action/list_conditional.html.twig | 8 ++++++-- .../GiftCard/Grid/Action/resend_email.html.twig | 10 +++++++--- .../views/Admin/GiftCard/create.html.twig | 2 +- 6 files changed, 29 insertions(+), 22 deletions(-) diff --git a/src/Resources/views/Admin/GiftCard/Grid/Action/create.html.twig b/src/Resources/views/Admin/GiftCard/Grid/Action/create.html.twig index a3907282..e4428ea8 100644 --- a/src/Resources/views/Admin/GiftCard/Grid/Action/create.html.twig +++ b/src/Resources/views/Admin/GiftCard/Grid/Action/create.html.twig @@ -1,8 +1,10 @@ {# todo this should be a knp menu builder instead #} -
{{ 'setono_sylius_gift_card.ui.total'|trans }}