| {{ 'setono_sylius_gift_card.ui.total'|trans }} | @@ -58,4 +65,5 @@ -{% endblock %} + +{% endblock %} \ No newline at end of file diff --git a/src/Resources/views/Shop/Account/GiftCard/index.html.twig b/src/Resources/views/Shop/Account/GiftCard/index.html.twig index 04f74852..f55c4619 100644 --- a/src/Resources/views/Shop/Account/GiftCard/index.html.twig +++ b/src/Resources/views/Shop/Account/GiftCard/index.html.twig @@ -1,4 +1,4 @@ -{% extends '@SyliusShop/Account/layout.html.twig' %} +{% extends '@SyliusShop/account/layout.html.twig' %} {% block breadcrumb %} {% include '@SetonoSyliusGiftCardPlugin/Shop/Account/GiftCard/Index/_breadcrumb.html.twig' %} diff --git a/src/Security/GiftCardVoter.php b/src/Security/GiftCardVoter.php index 2ae72cb4..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; @@ -17,24 +18,16 @@ 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; } - if (!$subject instanceof GiftCardInterface) { - return false; - } - - return true; + return $subject instanceof GiftCardInterface; } - /** - * @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 +40,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); @@ -58,7 +52,7 @@ protected function voteOnAttribute($attribute, $subject, TokenInterface $token): 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..804f3fd9 100644 --- a/src/Serializer/Normalizer/GiftCardConfigurationNormalizer.php +++ b/src/Serializer/Normalizer/GiftCardConfigurationNormalizer.php @@ -4,29 +4,25 @@ namespace Setono\SyliusGiftCardPlugin\Serializer\Normalizer; +use Setono\SyliusGiftCardPlugin\Model\GiftCardConfigurationImageInterface; use ArrayObject; use Setono\SyliusGiftCardPlugin\Exception\UnexpectedTypeException; 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 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); } @@ -81,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 403eb7d6..1f32f906 100644 --- a/src/Serializer/Normalizer/GiftCardNormalizer.php +++ b/src/Serializer/Normalizer/GiftCardNormalizer.php @@ -8,20 +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 { - private ObjectNormalizer $objectNormalizer; - - private MoneyFormatterInterface $moneyFormatter; - - public function __construct(ObjectNormalizer $objectNormalizer, MoneyFormatterInterface $moneyFormatter) - { - $this->objectNormalizer = $objectNormalizer; - $this->moneyFormatter = $moneyFormatter; + public function __construct( + private readonly ObjectNormalizer $objectNormalizer, + private readonly MoneyFormatterInterface $moneyFormatter + ) { } /** @@ -57,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, + ]; + } } 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..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/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/Model/Order.php b/tests/Application/Model/Order.php index 3a482a03..1b150281 100644 --- a/tests/Application/Model/Order.php +++ b/tests/Application/Model/Order.php @@ -5,24 +5,22 @@ 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; -/** - * @ORM\Entity - * - * @ORM\Table(name="sylius_order") - */ -class Order extends BaseOrder implements SetonoSyliusGiftCardOrderInterface + +#[ORM\Entity] +#[ORM\Table(name: 'sylius_order')] +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..3a9ddc5c 100644 --- a/tests/Application/Model/OrderItem.php +++ b/tests/Application/Model/OrderItem.php @@ -5,18 +5,11 @@ 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() - */ + +#[ORM\Entity] +#[ORM\Table(name: 'sylius_order_item')] class OrderItem extends BaseOrderItem { - use OrderItemTrait; } 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/api_platform/.gitignore b/tests/Application/config/api_platform/.gitignore deleted file mode 100644 index e69de29b..00000000 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 fdf32a28..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 - 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], - 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], + 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/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/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 2ef92e00..414e05e7 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; @@ -16,20 +16,8 @@ final class ManagingGiftCardConfigurationsContext 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, private readonly RequestFactoryInterface $requestFactory) + { } /** @@ -37,7 +25,7 @@ public function __construct( */ public function iBrowseGiftCardConfigurations(): void { - $this->client->index(); + $this->client->index('gift-card-configuration'); } /** @@ -45,7 +33,7 @@ public function iBrowseGiftCardConfigurations(): void */ public function iWantToCreateGiftCardConfiguration(): void { - $this->client->buildCreateRequest(); + $this->client->buildCreateRequest('gift-card-configurations'); } /** @@ -53,7 +41,7 @@ public function iWantToCreateGiftCardConfiguration(): void */ public function iWantToUpdateGiftCardConfiguration(string $code): void { - $this->client->buildUpdateRequest($code); + $this->client->buildUpdateRequest('gift-card-configurations', $code); } /** @@ -64,7 +52,7 @@ public function iAssociateGiftCardConfigurationToChannelAndLocale( ChannelInterface $channel, string $localeCode, ): void { - $request = Request::customItemAction( + $request = $this->requestFactory->customItemAction( 'admin', 'gift-card-configurations', $code, @@ -101,7 +89,7 @@ public function iSaveMyChanges(): void */ public function iDeleteGiftCardConfiguration(string $code): void { - $this->client->delete($code); + $this->client->delete('gift-card-configurations', $code); } /** @@ -109,7 +97,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 +107,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 +194,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..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) + { } /** @@ -29,7 +21,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..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) + { } /** @@ -37,7 +25,7 @@ public function __construct( */ public function iBrowseGiftCards(): void { - $this->client->index(); + $this->client->index('gift-cards'); } /** @@ -45,7 +33,7 @@ public function iBrowseGiftCards(): void */ public function iWantToCreateGiftCard(): void { - $this->client->buildCreateRequest(); + $this->client->buildCreateRequest('gift-cards'); } /** @@ -61,7 +49,7 @@ public function iAddIt(): void */ public function iOpenGiftCardPage(string $code): void { - $this->client->show($code); + $this->client->show('gift-cards', $code); } /** @@ -69,7 +57,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 +73,7 @@ public function iSaveMyChanges(): void */ public function iDeleteGiftCard(string $code): void { - $this->client->delete($code); + $this->client->delete('gift-cards', $code); } /** @@ -94,9 +82,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 +102,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 +111,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), @@ -135,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 f4f9f05d..2fd793ce 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; @@ -16,28 +16,8 @@ final class CartContext implements Context { - private ApiClientInterface $cartsClient; - - private ResponseCheckerInterface $responseChecker; - - private SharedStorageInterface $sharedStorage; - - private ProductVariantResolverInterface $productVariantResolver; - - private IriConverterInterface $iriConverter; - - public function __construct( - ApiClientInterface $cartsClient, - ResponseCheckerInterface $responseChecker, - SharedStorageInterface $sharedStorage, - ProductVariantResolverInterface $productVariantResolver, - IriConverterInterface $iriConverter, - ) { - $this->cartsClient = $cartsClient; - $this->responseChecker = $responseChecker; - $this->sharedStorage = $sharedStorage; - $this->productVariantResolver = $productVariantResolver; - $this->iriConverter = $iriConverter; + 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) + { } /** @@ -45,9 +25,9 @@ public function __construct( */ public function iAddProductWithAmountAndMessage(ProductInterface $product, int $amount, string $message): void { - $tokenValue = $tokenValue ?? $this->pickupCart(); + $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 +39,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..abfb227f 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; @@ -15,20 +15,8 @@ final class ManagingGiftCardsContext implements Context { - private ApiClientInterface $client; - - private ResponseCheckerInterface $responseChecker; - - private SharedStorageInterface $sharedStorage; - - public function __construct( - ApiClientInterface $client, - ResponseCheckerInterface $responseChecker, - SharedStorageInterface $sharedStorage, - ) { - $this->client = $client; - $this->responseChecker = $responseChecker; - $this->sharedStorage = $sharedStorage; + public function __construct(private readonly ApiClientInterface $client, private readonly ResponseCheckerInterface $responseChecker, private readonly SharedStorageInterface $sharedStorage, private readonly RequestFactoryInterface $requestFactory) + { } /** @@ -36,7 +24,7 @@ public function __construct( */ public function iBrowseGiftCards(): void { - $this->client->index(); + $this->client->index('gift-cards'); } /** @@ -44,7 +32,7 @@ public function iBrowseGiftCards(): void */ public function iOpenGiftCardPage(string $code): void { - $this->client->show($code); + $this->client->show('gift-cards', $code); } /** @@ -68,7 +56,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 +66,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 +100,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 +110,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/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..d029fc9d 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'); } @@ -115,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); 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/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 @@ - - -
|---|