From 9d1a5f4520054c95005f6ed4693d2a985cc01d39 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joachim=20L=C3=B8vgaard?= Date: Fri, 6 May 2022 14:57:49 +0200 Subject: [PATCH] Make GiftCardConfigurationProvider always return GiftCardConfiguration --- composer.json | 1 + ...ftCardChannelConfigurationProviderSpec.php | 66 ------------- .../GiftCardConfigurationProviderSpec.php | 71 ++++++++++++++ .../Action/DownloadGiftCardPdfAction.php | 6 +- .../Action/DownloadGiftCardPdfAction.php | 6 +- src/DependencyInjection/Configuration.php | 3 +- .../ORM/GiftCardConfigurationRepository.php | 41 ++++++++ src/Factory/GiftCardFactory.php | 30 +++--- src/Model/GiftCardChannelConfiguration.php | 8 +- .../GiftCardChannelConfigurationProvider.php | 78 --------------- .../GiftCardConfigurationProvider.php | 97 +++++++++++++++++++ ...iftCardConfigurationProviderInterface.php} | 6 +- ...ftCardConfigurationRepositoryInterface.php | 17 ++++ src/Resources/config/services/provider.xml | 5 +- .../Action/DownloadGiftCardPdfActionTest.php | 26 +---- .../DependencyInjection/ConfigurationTest.php | 3 +- tests/Unit/Factory/GiftCardFactoryTest.php | 20 ++-- 17 files changed, 275 insertions(+), 209 deletions(-) delete mode 100644 spec/Provider/GiftCardChannelConfigurationProviderSpec.php create mode 100644 spec/Provider/GiftCardConfigurationProviderSpec.php create mode 100644 src/Doctrine/ORM/GiftCardConfigurationRepository.php delete mode 100644 src/Provider/GiftCardChannelConfigurationProvider.php create mode 100644 src/Provider/GiftCardConfigurationProvider.php rename src/Provider/{GiftCardChannelConfigurationProviderInterface.php => GiftCardConfigurationProviderInterface.php} (73%) create mode 100644 src/Repository/GiftCardConfigurationRepositoryInterface.php diff --git a/composer.json b/composer.json index 0f8bdb44..796fa586 100644 --- a/composer.json +++ b/composer.json @@ -17,6 +17,7 @@ "knplabs/knp-menu": "^3.2", "knplabs/knp-snappy": "^1.2", "knplabs/knp-snappy-bundle": "^1.7", + "setono/doctrine-object-manager-trait": "^1.1", "sylius/resource-bundle": "^1.6", "symfony/config": "^4.4 || ^5.0", "symfony/dependency-injection": "^4.4 || ^5.0", diff --git a/spec/Provider/GiftCardChannelConfigurationProviderSpec.php b/spec/Provider/GiftCardChannelConfigurationProviderSpec.php deleted file mode 100644 index 04b18a20..00000000 --- a/spec/Provider/GiftCardChannelConfigurationProviderSpec.php +++ /dev/null @@ -1,66 +0,0 @@ -beConstructedWith($configurationRepository, $defaultConfigurationRepository, $localeContext, $localeRepository); - } - - public function it_is_initializable(): void - { - $this->shouldBeAnInstanceOf(GiftCardChannelConfigurationProvider::class); - } - - public function it_implements_gift_card_channel_configuration_provider_interface(): void - { - $this->shouldImplement(GiftCardChannelConfigurationProviderInterface::class); - } - - public function it_provides_configuration_from_channel_and_locale( - RepositoryInterface $configurationRepository, - ChannelInterface $channel, - LocaleInterface $locale - ): void { - $configuration = new GiftCardConfiguration(); - $channelConfiguration = new GiftCardChannelConfiguration(); - $channelConfiguration->setConfiguration($configuration); - $configurationRepository->findOneBy(['channel' => $channel, 'locale' => $locale])->willReturn($channelConfiguration); - - $this->getConfiguration($channel, $locale)->shouldReturn($configuration); - } - - public function it_provides_default_configuration_if_none_found( - RepositoryInterface $configurationRepository, - RepositoryInterface $defaultConfigurationRepository, - ChannelInterface $channel, - LocaleInterface $locale - ) { - $configurationRepository->findOneBy(['channel' => $channel, 'locale' => $locale])->willReturn(null); - - $defaultConfiguration = new GiftCardConfiguration(); - $defaultChannelConfiguration = new GiftCardChannelConfiguration(); - $defaultChannelConfiguration->setConfiguration($defaultConfiguration); - $defaultConfigurationRepository->findOneBy(['default' => true])->willReturn($defaultConfiguration); - - $this->getConfiguration($channel, $locale)->shouldReturn($defaultConfiguration); - } -} diff --git a/spec/Provider/GiftCardConfigurationProviderSpec.php b/spec/Provider/GiftCardConfigurationProviderSpec.php new file mode 100644 index 00000000..682e51ec --- /dev/null +++ b/spec/Provider/GiftCardConfigurationProviderSpec.php @@ -0,0 +1,71 @@ +beConstructedWith($giftCardConfigurationRepository, $giftCardConfigurationFactory, $localeContext, $localeRepository, $managerRegistry); + } + + public function it_is_initializable(): void + { + $this->shouldBeAnInstanceOf(GiftCardConfigurationProvider::class); + } + + public function it_implements_gift_card_configuration_provider_interface(): void + { + $this->shouldImplement(GiftCardConfigurationProviderInterface::class); + } + + public function it_provides_configuration_from_channel_and_locale( + GiftCardConfigurationRepositoryInterface $giftCardConfigurationRepository, + ChannelInterface $channel, + LocaleInterface $locale + ): void { + $configuration = new GiftCardConfiguration(); + $giftCardConfigurationRepository->findOneByChannelAndLocale($channel, $locale)->willReturn($configuration); + + $this->getConfiguration($channel, $locale)->shouldReturn($configuration); + } + + public function it_provides_default_configuration_if_none_found( + GiftCardConfigurationRepositoryInterface $giftCardConfigurationRepository, + GiftCardConfigurationFactoryInterface $giftCardConfigurationFactory, + ChannelInterface $channel, + LocaleInterface $locale, + ManagerRegistry $managerRegistry, + EntityManagerInterface $entityManager + ) { + $managerRegistry->getManagerForClass(GiftCardConfiguration::class)->willReturn($entityManager); + $giftCardConfigurationRepository->findOneByChannelAndLocale($channel, $locale)->willReturn(null); + + $configuration = new GiftCardConfiguration(); + $configuration->addChannelConfiguration(new GiftCardChannelConfiguration()); + $giftCardConfigurationRepository->findDefault()->willReturn($configuration); + + $this->getConfiguration($channel, $locale)->shouldReturn($configuration); + } +} diff --git a/src/Api/Controller/Action/DownloadGiftCardPdfAction.php b/src/Api/Controller/Action/DownloadGiftCardPdfAction.php index 85c914af..586cf700 100644 --- a/src/Api/Controller/Action/DownloadGiftCardPdfAction.php +++ b/src/Api/Controller/Action/DownloadGiftCardPdfAction.php @@ -7,18 +7,18 @@ use Setono\SyliusGiftCardPlugin\Generator\GiftCardPdfGeneratorInterface; use Setono\SyliusGiftCardPlugin\Model\GiftCardConfigurationInterface; use Setono\SyliusGiftCardPlugin\Model\GiftCardInterface; -use Setono\SyliusGiftCardPlugin\Provider\GiftCardChannelConfigurationProviderInterface; +use Setono\SyliusGiftCardPlugin\Provider\GiftCardConfigurationProviderInterface; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; final class DownloadGiftCardPdfAction { - private GiftCardChannelConfigurationProviderInterface $configurationProvider; + private GiftCardConfigurationProviderInterface $configurationProvider; private GiftCardPdfGeneratorInterface $giftCardPdfGenerator; public function __construct( - GiftCardChannelConfigurationProviderInterface $configurationProvider, + GiftCardConfigurationProviderInterface $configurationProvider, GiftCardPdfGeneratorInterface $giftCardPdfGenerator ) { $this->configurationProvider = $configurationProvider; diff --git a/src/Controller/Action/DownloadGiftCardPdfAction.php b/src/Controller/Action/DownloadGiftCardPdfAction.php index eafc7064..d29d1d38 100644 --- a/src/Controller/Action/DownloadGiftCardPdfAction.php +++ b/src/Controller/Action/DownloadGiftCardPdfAction.php @@ -8,7 +8,7 @@ use Setono\SyliusGiftCardPlugin\Generator\GiftCardPdfGeneratorInterface; use Setono\SyliusGiftCardPlugin\Model\GiftCardConfigurationInterface; use Setono\SyliusGiftCardPlugin\Model\GiftCardInterface; -use Setono\SyliusGiftCardPlugin\Provider\GiftCardChannelConfigurationProviderInterface; +use Setono\SyliusGiftCardPlugin\Provider\GiftCardConfigurationProviderInterface; use Setono\SyliusGiftCardPlugin\Repository\GiftCardRepositoryInterface; use Setono\SyliusGiftCardPlugin\Security\GiftCardVoter; use Symfony\Component\HttpFoundation\RedirectResponse; @@ -26,7 +26,7 @@ final class DownloadGiftCardPdfAction private FlashBagInterface $flashBag; - private GiftCardChannelConfigurationProviderInterface $configurationProvider; + private GiftCardConfigurationProviderInterface $configurationProvider; private GiftCardPdfGeneratorInterface $giftCardPdfGenerator; @@ -36,7 +36,7 @@ public function __construct( GiftCardRepositoryInterface $giftCardRepository, AuthorizationCheckerInterface $authChecker, FlashBagInterface $flashBag, - GiftCardChannelConfigurationProviderInterface $configurationProvider, + GiftCardConfigurationProviderInterface $configurationProvider, GiftCardPdfGeneratorInterface $giftCardPdfGenerator, UrlGeneratorInterface $urlGenerator ) { diff --git a/src/DependencyInjection/Configuration.php b/src/DependencyInjection/Configuration.php index d6ffb1b5..d6502400 100644 --- a/src/DependencyInjection/Configuration.php +++ b/src/DependencyInjection/Configuration.php @@ -4,6 +4,7 @@ namespace Setono\SyliusGiftCardPlugin\DependencyInjection; +use Setono\SyliusGiftCardPlugin\Doctrine\ORM\GiftCardConfigurationRepository; use Setono\SyliusGiftCardPlugin\Doctrine\ORM\GiftCardRepository; use Setono\SyliusGiftCardPlugin\Form\Type\GiftCardChannelConfigurationType; use Setono\SyliusGiftCardPlugin\Form\Type\GiftCardConfigurationImageType; @@ -123,7 +124,7 @@ private function addGiftCardConfigurationSection(NodeBuilder $nodeBuilder): void ->scalarNode('model')->defaultValue(GiftCardConfiguration::class)->cannotBeEmpty()->end() ->scalarNode('interface')->defaultValue(GiftCardConfigurationInterface::class)->cannotBeEmpty()->end() ->scalarNode('controller')->defaultValue(ResourceController::class)->cannotBeEmpty()->end() - ->scalarNode('repository')->defaultValue(EntityRepository::class)->cannotBeEmpty()->end() + ->scalarNode('repository')->defaultValue(GiftCardConfigurationRepository::class)->cannotBeEmpty()->end() ->scalarNode('form')->defaultValue(GiftCardConfigurationType::class)->end() ->scalarNode('factory')->defaultValue(Factory::class)->end() ; diff --git a/src/Doctrine/ORM/GiftCardConfigurationRepository.php b/src/Doctrine/ORM/GiftCardConfigurationRepository.php new file mode 100644 index 00000000..123d33e7 --- /dev/null +++ b/src/Doctrine/ORM/GiftCardConfigurationRepository.php @@ -0,0 +1,41 @@ +createQueryBuilder('o') + ->join('o.channelConfigurations', 'c') + ->andWhere('c.channel = :channel') + ->andWhere('c.locale = :locale') + ->setParameters([ + 'channel' => $channel, + 'locale' => $locale, + ]) + ->getQuery() + ->getOneOrNullResult() + ; + + Assert::nullOrIsInstanceOf($obj, GiftCardConfigurationInterface::class); + + return $obj; + } + + public function findDefault(): ?GiftCardConfigurationInterface + { + return $this->findOneBy([ + 'default' => true, + ]); + } +} diff --git a/src/Factory/GiftCardFactory.php b/src/Factory/GiftCardFactory.php index 6b6974b6..4441ab85 100644 --- a/src/Factory/GiftCardFactory.php +++ b/src/Factory/GiftCardFactory.php @@ -9,7 +9,7 @@ use Setono\SyliusGiftCardPlugin\Generator\GiftCardCodeGeneratorInterface; use Setono\SyliusGiftCardPlugin\Model\GiftCardInterface; use Setono\SyliusGiftCardPlugin\Model\OrderItemUnitInterface; -use Setono\SyliusGiftCardPlugin\Provider\GiftCardChannelConfigurationProviderInterface; +use Setono\SyliusGiftCardPlugin\Provider\GiftCardConfigurationProviderInterface; use Sylius\Bundle\ShippingBundle\Provider\DateTimeProvider; use Sylius\Component\Core\Model\ChannelInterface; use Sylius\Component\Core\Model\CustomerInterface; @@ -24,7 +24,7 @@ final class GiftCardFactory implements GiftCardFactoryInterface private GiftCardCodeGeneratorInterface $giftCardCodeGenerator; - private GiftCardChannelConfigurationProviderInterface $giftCardChannelConfigurationProvider; + private GiftCardConfigurationProviderInterface $giftCardConfigurationProvider; private DateTimeProvider $dateTimeProvider; @@ -33,13 +33,13 @@ final class GiftCardFactory implements GiftCardFactoryInterface public function __construct( FactoryInterface $decoratedFactory, GiftCardCodeGeneratorInterface $giftCardCodeGenerator, - GiftCardChannelConfigurationProviderInterface $giftCardChannelConfigurationProvider, + GiftCardConfigurationProviderInterface $giftCardConfigurationProvider, DateTimeProvider $dateTimeProvider, CurrencyContextInterface $currencyContext ) { $this->decoratedFactory = $decoratedFactory; $this->giftCardCodeGenerator = $giftCardCodeGenerator; - $this->giftCardChannelConfigurationProvider = $giftCardChannelConfigurationProvider; + $this->giftCardConfigurationProvider = $giftCardConfigurationProvider; $this->dateTimeProvider = $dateTimeProvider; $this->currencyContext = $currencyContext; } @@ -58,18 +58,16 @@ public function createForChannel(ChannelInterface $channel): GiftCardInterface $giftCard = $this->createNew(); $giftCard->setChannel($channel); - $channelConfiguration = $this->giftCardChannelConfigurationProvider->getConfigurationForGiftCard($giftCard); - if (null !== $channelConfiguration) { - $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); - /** @var DateTimeInterface $today */ - $today = $today->modify('+' . $validityPeriod); - $giftCard->setExpiresAt($today); - } + $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); + /** @var DateTimeInterface $today */ + $today = $today->modify('+' . $validityPeriod); + $giftCard->setExpiresAt($today); } return $giftCard; diff --git a/src/Model/GiftCardChannelConfiguration.php b/src/Model/GiftCardChannelConfiguration.php index e37c6cad..46ade47e 100644 --- a/src/Model/GiftCardChannelConfiguration.php +++ b/src/Model/GiftCardChannelConfiguration.php @@ -4,7 +4,7 @@ namespace Setono\SyliusGiftCardPlugin\Model; -use Sylius\Component\Channel\Model\ChannelInterface as SyliusChannelInterface; +use Sylius\Component\Channel\Model\ChannelInterface; use Sylius\Component\Locale\Model\LocaleInterface; use Webmozart\Assert\Assert; @@ -12,7 +12,7 @@ class GiftCardChannelConfiguration implements GiftCardChannelConfigurationInterf { protected ?int $id = null; - protected ?SyliusChannelInterface $channel = null; + protected ?ChannelInterface $channel = null; protected ?LocaleInterface $locale = null; @@ -23,12 +23,12 @@ public function getId(): ?int return $this->id; } - public function getChannel(): ?SyliusChannelInterface + public function getChannel(): ?ChannelInterface { return $this->channel; } - public function setChannel(?SyliusChannelInterface $channel): void + public function setChannel(?ChannelInterface $channel): void { Assert::notNull($channel); $this->channel = $channel; diff --git a/src/Provider/GiftCardChannelConfigurationProvider.php b/src/Provider/GiftCardChannelConfigurationProvider.php deleted file mode 100644 index dcefffd8..00000000 --- a/src/Provider/GiftCardChannelConfigurationProvider.php +++ /dev/null @@ -1,78 +0,0 @@ -configurationRepository = $configurationRepository; - $this->defaultConfigurationRepository = $defaultConfigurationRepository; - $this->localeContext = $localeContext; - $this->localeRepository = $localeRepository; - } - - public function getConfiguration(ChannelInterface $channel, LocaleInterface $locale): ?GiftCardConfigurationInterface - { - /** @var GiftCardChannelConfigurationInterface|null $channelConfiguration */ - $channelConfiguration = $this->configurationRepository->findOneBy(['channel' => $channel, 'locale' => $locale]); - if ($channelConfiguration instanceof GiftCardChannelConfigurationInterface) { - $configuration = $channelConfiguration->getConfiguration(); - } else { - /** @var GiftCardConfigurationInterface $configuration */ - $configuration = $this->defaultConfigurationRepository->findOneBy(['default' => true]); - } - - return $configuration; - } - - public function getConfigurationForGiftCard(GiftCardInterface $giftCard): ?GiftCardConfigurationInterface - { - $channel = $giftCard->getChannel(); - Assert::isInstanceOf($channel, ChannelInterface::class); - - try { - $order = $giftCard->getOrder(); - if ($order instanceof OrderInterface) { - $localeCode = $order->getLocaleCode(); - } else { - $localeCode = $this->localeContext->getLocaleCode(); - } - $locale = $this->localeRepository->findOneBy(['code' => $localeCode]); - if (!$locale instanceof LocaleInterface) { - throw new LocaleNotFoundException(); - } - } catch (LocaleNotFoundException $exception) { - $locale = $channel->getDefaultLocale(); - } - - Assert::notNull($locale); - - return $this->getConfiguration($channel, $locale); - } -} diff --git a/src/Provider/GiftCardConfigurationProvider.php b/src/Provider/GiftCardConfigurationProvider.php new file mode 100644 index 00000000..50681658 --- /dev/null +++ b/src/Provider/GiftCardConfigurationProvider.php @@ -0,0 +1,97 @@ +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) { + return $configuration; + } + + $configuration = $this->giftCardConfigurationRepository->findDefault(); + if (null !== $configuration) { + return $configuration; + } + + // todo add notification feature where the shop owner receives an email to update this configuration + + $configuration = $this->giftCardConfigurationFactory->createNew(); + $configuration->setCode('default'); + $configuration->setDefault(true); + + $manager = $this->getManager($configuration); + $manager->persist($configuration); + $manager->flush(); + + return $configuration; + } + + public function getConfigurationForGiftCard(GiftCardInterface $giftCard): GiftCardConfigurationInterface + { + $channel = $giftCard->getChannel(); + Assert::isInstanceOf($channel, ChannelInterface::class); + + try { + $order = $giftCard->getOrder(); + if ($order instanceof OrderInterface) { + $localeCode = $order->getLocaleCode(); + } else { + $localeCode = $this->localeContext->getLocaleCode(); + } + $locale = $this->localeRepository->findOneBy(['code' => $localeCode]); + if (!$locale instanceof LocaleInterface) { + throw new LocaleNotFoundException(); + } + } catch (LocaleNotFoundException $exception) { + $locale = $channel->getDefaultLocale(); + } + + Assert::notNull($locale); + + return $this->getConfiguration($channel, $locale); + } +} diff --git a/src/Provider/GiftCardChannelConfigurationProviderInterface.php b/src/Provider/GiftCardConfigurationProviderInterface.php similarity index 73% rename from src/Provider/GiftCardChannelConfigurationProviderInterface.php rename to src/Provider/GiftCardConfigurationProviderInterface.php index 322b1b11..5a7ca868 100644 --- a/src/Provider/GiftCardChannelConfigurationProviderInterface.php +++ b/src/Provider/GiftCardConfigurationProviderInterface.php @@ -9,9 +9,9 @@ use Sylius\Component\Channel\Model\ChannelInterface; use Sylius\Component\Locale\Model\LocaleInterface; -interface GiftCardChannelConfigurationProviderInterface +interface GiftCardConfigurationProviderInterface { - public function getConfiguration(ChannelInterface $channel, LocaleInterface $locale): ?GiftCardConfigurationInterface; + public function getConfiguration(ChannelInterface $channel, LocaleInterface $locale): GiftCardConfigurationInterface; - public function getConfigurationForGiftCard(GiftCardInterface $giftCard): ?GiftCardConfigurationInterface; + public function getConfigurationForGiftCard(GiftCardInterface $giftCard): GiftCardConfigurationInterface; } diff --git a/src/Repository/GiftCardConfigurationRepositoryInterface.php b/src/Repository/GiftCardConfigurationRepositoryInterface.php new file mode 100644 index 00000000..c2c94725 --- /dev/null +++ b/src/Repository/GiftCardConfigurationRepositoryInterface.php @@ -0,0 +1,17 @@ + - + class="Setono\SyliusGiftCardPlugin\Provider\GiftCardConfigurationProvider"> + + Gift card content', 'gc.pdf'); - $configurationProvider = $this->prophesize(GiftCardChannelConfigurationProviderInterface::class); + $configurationProvider = $this->prophesize(GiftCardConfigurationProviderInterface::class); $giftCardPdfGenerator = $this->prophesize(GiftCardPdfGeneratorInterface::class); $configurationProvider->getConfigurationForGiftCard($giftCard)->willReturn($configuration); @@ -44,25 +43,4 @@ public function it_downloads_associated_pdf(): void $this->assertEquals($expectedPdfResponse, $response); } - - /** - * @test - */ - public function it_throws_error_if_configuration_not_found(): void - { - $giftCard = new GiftCard(); - - $configurationProvider = $this->prophesize(GiftCardChannelConfigurationProviderInterface::class); - $giftCardPdfGenerator = $this->prophesize(GiftCardPdfGeneratorInterface::class); - - $configurationProvider->getConfigurationForGiftCard($giftCard)->willReturn(null); - - $this->expectException(NotFoundHttpException::class); - - $downloadGiftCardPdfAction = new DownloadGiftCardPdfAction( - $configurationProvider->reveal(), - $giftCardPdfGenerator->reveal() - ); - $downloadGiftCardPdfAction($giftCard); - } } diff --git a/tests/Unit/DependencyInjection/ConfigurationTest.php b/tests/Unit/DependencyInjection/ConfigurationTest.php index df740200..5e1f9830 100644 --- a/tests/Unit/DependencyInjection/ConfigurationTest.php +++ b/tests/Unit/DependencyInjection/ConfigurationTest.php @@ -7,6 +7,7 @@ use Matthias\SymfonyConfigTest\PhpUnit\ConfigurationTestCaseTrait; use PHPUnit\Framework\TestCase; use Setono\SyliusGiftCardPlugin\DependencyInjection\Configuration; +use Setono\SyliusGiftCardPlugin\Doctrine\ORM\GiftCardConfigurationRepository; use Setono\SyliusGiftCardPlugin\Doctrine\ORM\GiftCardRepository; use Setono\SyliusGiftCardPlugin\Form\Type\GiftCardChannelConfigurationType; use Setono\SyliusGiftCardPlugin\Form\Type\GiftCardConfigurationImageType; @@ -100,7 +101,7 @@ public function processed_configuration_for_array_node_1(): void 'model' => GiftCardConfiguration::class, 'interface' => GiftCardConfigurationInterface::class, 'controller' => ResourceController::class, - 'repository' => EntityRepository::class, + 'repository' => GiftCardConfigurationRepository::class, 'form' => GiftCardConfigurationType::class, 'factory' => Factory::class, ], diff --git a/tests/Unit/Factory/GiftCardFactoryTest.php b/tests/Unit/Factory/GiftCardFactoryTest.php index 2f7fda8f..cda91668 100644 --- a/tests/Unit/Factory/GiftCardFactoryTest.php +++ b/tests/Unit/Factory/GiftCardFactoryTest.php @@ -11,7 +11,7 @@ use Setono\SyliusGiftCardPlugin\Model\GiftCard; use Setono\SyliusGiftCardPlugin\Model\GiftCardConfiguration; use Setono\SyliusGiftCardPlugin\Model\GiftCardInterface; -use Setono\SyliusGiftCardPlugin\Provider\GiftCardChannelConfigurationProviderInterface; +use Setono\SyliusGiftCardPlugin\Provider\GiftCardConfigurationProviderInterface; use Sylius\Bundle\ShippingBundle\Provider\Calendar; use Sylius\Bundle\ShippingBundle\Provider\DateTimeProvider; use Sylius\Component\Core\Model\Channel; @@ -35,7 +35,7 @@ public function it_creates_a_new_gift_card_with_code(): void $decoratedFactory = $this->prophesize(FactoryInterface::class); $giftCardCodeGenerator = $this->prophesize(GiftCardCodeGeneratorInterface::class); - $configurationProvider = $this->prophesize(GiftCardChannelConfigurationProviderInterface::class); + $configurationProvider = $this->prophesize(GiftCardConfigurationProviderInterface::class); $currencyContext = $this->prophesize(CurrencyContextInterface::class); $decoratedFactory->createNew()->willReturn($giftCard); @@ -64,11 +64,12 @@ public function it_creates_a_new_gift_card_for_channel(): void $decoratedFactory = $this->prophesize(FactoryInterface::class); $giftCardCodeGenerator = $this->prophesize(GiftCardCodeGeneratorInterface::class); - $configurationProvider = $this->prophesize(GiftCardChannelConfigurationProviderInterface::class); + $configurationProvider = $this->prophesize(GiftCardConfigurationProviderInterface::class); $currencyContext = $this->prophesize(CurrencyContextInterface::class); $decoratedFactory->createNew()->willReturn($giftCard); $giftCardCodeGenerator->generate()->willReturn('super-code'); + $configurationProvider->getConfigurationForGiftCard($giftCard)->willReturn(new GiftCardConfiguration()); $factory = new GiftCardFactory( $decoratedFactory->reveal(), @@ -97,7 +98,7 @@ public function it_creates_a_new_gift_card_for_channel_with_expiration_date(): v $decoratedFactory = $this->prophesize(FactoryInterface::class); $giftCardCodeGenerator = $this->prophesize(GiftCardCodeGeneratorInterface::class); - $configurationProvider = $this->prophesize(GiftCardChannelConfigurationProviderInterface::class); + $configurationProvider = $this->prophesize(GiftCardConfigurationProviderInterface::class); $calendar = $this->prophesize(DateTimeProvider::class); $currencyContext = $this->prophesize(CurrencyContextInterface::class); @@ -130,11 +131,12 @@ public function it_creates_a_new_gift_card_for_channel_from_admin(): void $decoratedFactory = $this->prophesize(FactoryInterface::class); $giftCardCodeGenerator = $this->prophesize(GiftCardCodeGeneratorInterface::class); - $configurationProvider = $this->prophesize(GiftCardChannelConfigurationProviderInterface::class); + $configurationProvider = $this->prophesize(GiftCardConfigurationProviderInterface::class); $currencyContext = $this->prophesize(CurrencyContextInterface::class); $decoratedFactory->createNew()->willReturn($giftCard); $giftCardCodeGenerator->generate()->willReturn('super-code'); + $configurationProvider->getConfigurationForGiftCard($giftCard)->willReturn(new GiftCardConfiguration()); $factory = new GiftCardFactory( $decoratedFactory->reveal(), @@ -166,11 +168,12 @@ public function it_creates_a_new_gift_card_for_order_item_unit_and_cart(): void $decoratedFactory = $this->prophesize(FactoryInterface::class); $giftCardCodeGenerator = $this->prophesize(GiftCardCodeGeneratorInterface::class); - $configurationProvider = $this->prophesize(GiftCardChannelConfigurationProviderInterface::class); + $configurationProvider = $this->prophesize(GiftCardConfigurationProviderInterface::class); $currencyContext = $this->prophesize(CurrencyContextInterface::class); $decoratedFactory->createNew()->willReturn($giftCard); $giftCardCodeGenerator->generate()->willReturn('super-code'); + $configurationProvider->getConfigurationForGiftCard($giftCard)->willReturn(new GiftCardConfiguration()); $factory = new GiftCardFactory( $decoratedFactory->reveal(), @@ -212,11 +215,12 @@ public function it_creates_a_new_gift_card_for_order_item_unit(): void $decoratedFactory = $this->prophesize(FactoryInterface::class); $giftCardCodeGenerator = $this->prophesize(GiftCardCodeGeneratorInterface::class); - $configurationProvider = $this->prophesize(GiftCardChannelConfigurationProviderInterface::class); + $configurationProvider = $this->prophesize(GiftCardConfigurationProviderInterface::class); $currencyContext = $this->prophesize(CurrencyContextInterface::class); $decoratedFactory->createNew()->willReturn($giftCard); $giftCardCodeGenerator->generate()->willReturn('super-code'); + $configurationProvider->getConfigurationForGiftCard($giftCard)->willReturn(new GiftCardConfiguration()); $factory = new GiftCardFactory( $decoratedFactory->reveal(), @@ -245,7 +249,7 @@ public function it_creates_example_gift_card(): void { $decoratedFactory = $this->prophesize(FactoryInterface::class); $giftCardCodeGenerator = $this->prophesize(GiftCardCodeGeneratorInterface::class); - $configurationProvider = $this->prophesize(GiftCardChannelConfigurationProviderInterface::class); + $configurationProvider = $this->prophesize(GiftCardConfigurationProviderInterface::class); $currencyContext = $this->prophesize(CurrencyContextInterface::class); $giftCard = new GiftCard();