From d0b2c1d9c8be2adedb8581e2c631b8d6aadf279d Mon Sep 17 00:00:00 2001 From: Grzegorz Sadowski Date: Fri, 28 Jan 2022 07:19:35 +0100 Subject: [PATCH] [Promotion] Use sylius/calendar instead of the existing Calendar --- composer.json | 1 + config/bundles.php | 1 + .../Behat/Resources/config/services.xml | 6 ---- .../Behat/Service/Provider/Calendar.php | 3 +- .../Bundle/ApiBundle/test/config/bundles.php | 1 + .../Announcer/CatalogPromotionAnnouncer.php | 17 +++-------- .../CoreBundle/Resources/config/services.xml | 2 +- .../Bundle/CoreBundle/Tests/TestKernel.php | 2 ++ .../CatalogPromotionAnnouncerSpec.php | 2 +- .../PromotionBundle/Criteria/DateRange.php | 7 ++--- .../Resources/config/services.xml | 2 -- .../Resources/config/services/criteria.xml | 2 +- .../Bundle/PromotionBundle/composer.json | 1 + .../spec/Criteria/DateRangeSpec.php | 2 +- .../PromotionBundle/test/app/AppKernel.php | 1 + .../Component/Promotion/Provider/Calendar.php | 22 -------------- .../Provider/DateTimeProviderInterface.php | 10 ------- .../Promotion/spec/Provider/CalendarSpec.php | 30 ------------------- 18 files changed, 18 insertions(+), 94 deletions(-) delete mode 100644 src/Sylius/Component/Promotion/Provider/Calendar.php delete mode 100644 src/Sylius/Component/Promotion/Provider/DateTimeProviderInterface.php delete mode 100644 src/Sylius/Component/Promotion/spec/Provider/CalendarSpec.php diff --git a/composer.json b/composer.json index 0990b8bb79..ddee530d75 100644 --- a/composer.json +++ b/composer.json @@ -59,6 +59,7 @@ "sylius-labs/polyfill-symfony-event-dispatcher": "^1.0.1", "sylius-labs/polyfill-symfony-framework-bundle": "^1.0", "sylius-labs/polyfill-symfony-security": "^1.0", + "sylius/calendar": "^0.2", "sylius/fixtures-bundle": "^1.6.1", "sylius/grid": "^1.8", "sylius/grid-bundle": "^1.8", diff --git a/config/bundles.php b/config/bundles.php index 250ba2a08b..180f77e843 100644 --- a/config/bundles.php +++ b/config/bundles.php @@ -7,6 +7,7 @@ return [ Symfony\Bundle\SwiftmailerBundle\SwiftmailerBundle::class => ['all' => true], Symfony\Bundle\TwigBundle\TwigBundle::class => ['all' => true], Doctrine\Bundle\DoctrineBundle\DoctrineBundle::class => ['all' => true], + Sylius\Calendar\SyliusCalendarBundle::class => ['all' => true], Sylius\Bundle\OrderBundle\SyliusOrderBundle::class => ['all' => true], Sylius\Bundle\MoneyBundle\SyliusMoneyBundle::class => ['all' => true], Sylius\Bundle\CurrencyBundle\SyliusCurrencyBundle::class => ['all' => true], diff --git a/src/Sylius/Behat/Resources/config/services.xml b/src/Sylius/Behat/Resources/config/services.xml index 86802f82a5..b455e5c553 100644 --- a/src/Sylius/Behat/Resources/config/services.xml +++ b/src/Sylius/Behat/Resources/config/services.xml @@ -89,11 +89,5 @@ %kernel.project_dir% - - %kernel.project_dir% - diff --git a/src/Sylius/Behat/Service/Provider/Calendar.php b/src/Sylius/Behat/Service/Provider/Calendar.php index 372dc5999a..9569bbbd78 100644 --- a/src/Sylius/Behat/Service/Provider/Calendar.php +++ b/src/Sylius/Behat/Service/Provider/Calendar.php @@ -14,9 +14,8 @@ declare(strict_types=1); namespace Sylius\Behat\Service\Provider; use Sylius\Bundle\ShippingBundle\Provider\DateTimeProvider; -use Sylius\Component\Promotion\Provider\DateTimeProviderInterface; -final class Calendar implements DateTimeProvider, DateTimeProviderInterface +final class Calendar implements DateTimeProvider { private string $projectDirectory; diff --git a/src/Sylius/Bundle/ApiBundle/test/config/bundles.php b/src/Sylius/Bundle/ApiBundle/test/config/bundles.php index cb8b95b12d..60c20145e2 100644 --- a/src/Sylius/Bundle/ApiBundle/test/config/bundles.php +++ b/src/Sylius/Bundle/ApiBundle/test/config/bundles.php @@ -17,6 +17,7 @@ return [ Symfony\Bundle\SwiftmailerBundle\SwiftmailerBundle::class => ['all' => true], Symfony\Bundle\TwigBundle\TwigBundle::class => ['all' => true], Doctrine\Bundle\DoctrineBundle\DoctrineBundle::class => ['all' => true], + Sylius\Calendar\SyliusCalendarBundle::class => ['all' => true], Sylius\Bundle\OrderBundle\SyliusOrderBundle::class => ['all' => true], Sylius\Bundle\MoneyBundle\SyliusMoneyBundle::class => ['all' => true], Sylius\Bundle\CurrencyBundle\SyliusCurrencyBundle::class => ['all' => true], diff --git a/src/Sylius/Bundle/CoreBundle/Announcer/CatalogPromotionAnnouncer.php b/src/Sylius/Bundle/CoreBundle/Announcer/CatalogPromotionAnnouncer.php index cd9239cf13..b13c91de3a 100644 --- a/src/Sylius/Bundle/CoreBundle/Announcer/CatalogPromotionAnnouncer.php +++ b/src/Sylius/Bundle/CoreBundle/Announcer/CatalogPromotionAnnouncer.php @@ -14,29 +14,20 @@ declare(strict_types=1); namespace Sylius\Bundle\CoreBundle\Announcer; use Sylius\Bundle\CoreBundle\Calculator\DelayStampCalculatorInterface; +use Sylius\Calendar\Provider\DateTimeProviderInterface; use Sylius\Component\Core\Model\CatalogPromotionInterface; use Sylius\Component\Promotion\Event\CatalogPromotionCreated; use Sylius\Component\Promotion\Event\CatalogPromotionEnded; use Sylius\Component\Promotion\Event\CatalogPromotionUpdated; -use Sylius\Component\Promotion\Provider\DateTimeProviderInterface; use Symfony\Component\Messenger\MessageBusInterface; final class CatalogPromotionAnnouncer implements CatalogPromotionAnnouncerInterface { - private MessageBusInterface $eventBus; - - private DelayStampCalculatorInterface $delayStampCalculator; - - private DateTimeProviderInterface $dateTimeProvider; - public function __construct( - MessageBusInterface $eventBus, - DelayStampCalculatorInterface $delayStampCalculator, - DateTimeProviderInterface $dateTimeProvider + private MessageBusInterface $eventBus, + private DelayStampCalculatorInterface $delayStampCalculator, + private DateTimeProviderInterface $dateTimeProvider ) { - $this->eventBus = $eventBus; - $this->delayStampCalculator = $delayStampCalculator; - $this->dateTimeProvider = $dateTimeProvider; } public function dispatchCatalogPromotionCreatedEvent(CatalogPromotionInterface $catalogPromotion): void diff --git a/src/Sylius/Bundle/CoreBundle/Resources/config/services.xml b/src/Sylius/Bundle/CoreBundle/Resources/config/services.xml index e9ebda17f0..c5487cb413 100644 --- a/src/Sylius/Bundle/CoreBundle/Resources/config/services.xml +++ b/src/Sylius/Bundle/CoreBundle/Resources/config/services.xml @@ -312,7 +312,7 @@ > - + diff --git a/src/Sylius/Bundle/CoreBundle/Tests/TestKernel.php b/src/Sylius/Bundle/CoreBundle/Tests/TestKernel.php index dc2c55bf48..c8fbcb9f17 100644 --- a/src/Sylius/Bundle/CoreBundle/Tests/TestKernel.php +++ b/src/Sylius/Bundle/CoreBundle/Tests/TestKernel.php @@ -49,6 +49,7 @@ 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 Symfony\Bundle\FrameworkBundle\FrameworkBundle; use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait; @@ -74,6 +75,7 @@ final class TestKernel extends BaseKernel new SwiftmailerBundle(), new TwigBundle(), new DoctrineBundle(), + new SyliusCalendarBundle(), new SyliusOrderBundle(), new SyliusMoneyBundle(), new SyliusCurrencyBundle(), diff --git a/src/Sylius/Bundle/CoreBundle/spec/Announcer/CatalogPromotionAnnouncerSpec.php b/src/Sylius/Bundle/CoreBundle/spec/Announcer/CatalogPromotionAnnouncerSpec.php index fd94679205..dd2942a4a0 100644 --- a/src/Sylius/Bundle/CoreBundle/spec/Announcer/CatalogPromotionAnnouncerSpec.php +++ b/src/Sylius/Bundle/CoreBundle/spec/Announcer/CatalogPromotionAnnouncerSpec.php @@ -17,11 +17,11 @@ use PhpSpec\ObjectBehavior; use Prophecy\Argument; use Sylius\Bundle\CoreBundle\Announcer\CatalogPromotionAnnouncerInterface; use Sylius\Bundle\CoreBundle\Calculator\DelayStampCalculatorInterface; +use Sylius\Calendar\Provider\DateTimeProviderInterface; use Sylius\Component\Core\Model\CatalogPromotionInterface; use Sylius\Component\Promotion\Event\CatalogPromotionCreated; use Sylius\Component\Promotion\Event\CatalogPromotionEnded; use Sylius\Component\Promotion\Event\CatalogPromotionUpdated; -use Sylius\Component\Promotion\Provider\DateTimeProviderInterface; use Symfony\Component\Messenger\Envelope; use Symfony\Component\Messenger\MessageBusInterface; use Symfony\Component\Messenger\Stamp\DelayStamp; diff --git a/src/Sylius/Bundle/PromotionBundle/Criteria/DateRange.php b/src/Sylius/Bundle/PromotionBundle/Criteria/DateRange.php index 6d8114007c..269afe4d19 100644 --- a/src/Sylius/Bundle/PromotionBundle/Criteria/DateRange.php +++ b/src/Sylius/Bundle/PromotionBundle/Criteria/DateRange.php @@ -14,15 +14,12 @@ declare(strict_types=1); namespace Sylius\Bundle\PromotionBundle\Criteria; use Doctrine\ORM\QueryBuilder; -use Sylius\Component\Promotion\Provider\DateTimeProviderInterface; +use Sylius\Calendar\Provider\DateTimeProviderInterface; final class DateRange implements CriteriaInterface { - private DateTimeProviderInterface $calendar; - - public function __construct(DateTimeProviderInterface $calendar) + public function __construct(private DateTimeProviderInterface $calendar) { - $this->calendar = $calendar; } public function filterQueryBuilder(QueryBuilder $queryBuilder): QueryBuilder diff --git a/src/Sylius/Bundle/PromotionBundle/Resources/config/services.xml b/src/Sylius/Bundle/PromotionBundle/Resources/config/services.xml index 6df7f3f023..91c563d8e8 100644 --- a/src/Sylius/Bundle/PromotionBundle/Resources/config/services.xml +++ b/src/Sylius/Bundle/PromotionBundle/Resources/config/services.xml @@ -80,7 +80,5 @@ - - diff --git a/src/Sylius/Bundle/PromotionBundle/Resources/config/services/criteria.xml b/src/Sylius/Bundle/PromotionBundle/Resources/config/services/criteria.xml index 800fb268be..4ec21a591f 100644 --- a/src/Sylius/Bundle/PromotionBundle/Resources/config/services/criteria.xml +++ b/src/Sylius/Bundle/PromotionBundle/Resources/config/services/criteria.xml @@ -19,7 +19,7 @@ - + diff --git a/src/Sylius/Bundle/PromotionBundle/composer.json b/src/Sylius/Bundle/PromotionBundle/composer.json index a230cced57..f474fef4f4 100644 --- a/src/Sylius/Bundle/PromotionBundle/composer.json +++ b/src/Sylius/Bundle/PromotionBundle/composer.json @@ -29,6 +29,7 @@ "require": { "php": "^8.0", "stof/doctrine-extensions-bundle": "^1.4", + "sylius/calendar": "^0.2", "sylius/money-bundle": "^1.6", "sylius/promotion": "^1.6", "sylius/registry": "^1.5", diff --git a/src/Sylius/Bundle/PromotionBundle/spec/Criteria/DateRangeSpec.php b/src/Sylius/Bundle/PromotionBundle/spec/Criteria/DateRangeSpec.php index e56df7563d..e9ea6b9294 100644 --- a/src/Sylius/Bundle/PromotionBundle/spec/Criteria/DateRangeSpec.php +++ b/src/Sylius/Bundle/PromotionBundle/spec/Criteria/DateRangeSpec.php @@ -16,7 +16,7 @@ namespace spec\Sylius\Bundle\PromotionBundle\Criteria; use Doctrine\ORM\QueryBuilder; use PhpSpec\ObjectBehavior; use Sylius\Bundle\PromotionBundle\Criteria\CriteriaInterface; -use Sylius\Component\Promotion\Provider\DateTimeProviderInterface; +use Sylius\Calendar\Provider\DateTimeProviderInterface; final class DateRangeSpec extends ObjectBehavior { diff --git a/src/Sylius/Bundle/PromotionBundle/test/app/AppKernel.php b/src/Sylius/Bundle/PromotionBundle/test/app/AppKernel.php index 29680e901f..10500d458d 100644 --- a/src/Sylius/Bundle/PromotionBundle/test/app/AppKernel.php +++ b/src/Sylius/Bundle/PromotionBundle/test/app/AppKernel.php @@ -26,6 +26,7 @@ class AppKernel extends Kernel new JMS\SerializerBundle\JMSSerializerBundle(), new BabDev\PagerfantaBundle\BabDevPagerfantaBundle(), new Doctrine\Bundle\DoctrineBundle\DoctrineBundle(), + new Sylius\Calendar\SyliusCalendarBundle(), new Sylius\Bundle\PromotionBundle\SyliusPromotionBundle(), new Sylius\Bundle\ResourceBundle\SyliusResourceBundle(), new Symfony\Bundle\TwigBundle\TwigBundle(), diff --git a/src/Sylius/Component/Promotion/Provider/Calendar.php b/src/Sylius/Component/Promotion/Provider/Calendar.php deleted file mode 100644 index 0a1a8f886c..0000000000 --- a/src/Sylius/Component/Promotion/Provider/Calendar.php +++ /dev/null @@ -1,22 +0,0 @@ -shouldImplement(DateTimeProviderInterface::class); - } - - function it_provides_a_date(): void - { - $this->now()->shouldBeAnInstanceOf(\DateTimeInterface::class); - } -}