[Promotion] Use sylius/calendar instead of the existing Calendar

This commit is contained in:
Grzegorz Sadowski 2022-01-28 07:19:35 +01:00
parent 894c6f1022
commit d0b2c1d9c8
No known key found for this signature in database
GPG key ID: EF87FF4E6E3BD364
18 changed files with 18 additions and 94 deletions

View file

@ -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",

View file

@ -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],

View file

@ -89,11 +89,5 @@
<service id="sylius.calendar" class="Sylius\Behat\Service\Provider\Calendar">
<argument>%kernel.project_dir%</argument>
</service>
<service
id="Sylius\Component\Promotion\Provider\DateTimeProviderInterface"
class="Sylius\Behat\Service\Provider\Calendar"
>
<argument>%kernel.project_dir%</argument>
</service>
</services>
</container>

View file

@ -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;

View file

@ -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],

View file

@ -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

View file

@ -312,7 +312,7 @@
>
<argument type="service" id="sylius.event_bus" />
<argument type="service" id="Sylius\Bundle\CoreBundle\Calculator\DelayStampCalculatorInterface" />
<argument type="service" id="Sylius\Component\Promotion\Provider\DateTimeProviderInterface" />
<argument type="service" id="Sylius\Calendar\Provider\DateTimeProviderInterface" />
</service>
</services>
</container>

View file

@ -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(),

View file

@ -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;

View file

@ -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

View file

@ -80,7 +80,5 @@
<argument type="service" id="sylius.repository.catalog_promotion" />
<argument type="tagged_iterator" tag="sylius.catalog_promotion.criteria" />
</service>
<service id="Sylius\Component\Promotion\Provider\DateTimeProviderInterface" class="Sylius\Component\Promotion\Provider\Calendar" />
</services>
</container>

View file

@ -19,7 +19,7 @@
<tag name="sylius.catalog_promotion.criteria" />
</service>
<service id="sylius.catalog_promotion.criteria.date_range" class="Sylius\Bundle\PromotionBundle\Criteria\DateRange">
<argument type="service" id="Sylius\Component\Promotion\Provider\DateTimeProviderInterface" />
<argument type="service" id="Sylius\Calendar\Provider\DateTimeProviderInterface" />
<tag name="sylius.catalog_promotion.criteria" />
</service>
</services>

View file

@ -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",

View file

@ -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
{

View file

@ -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(),

View file

@ -1,22 +0,0 @@
<?php
/*
* This file is part of the Sylius package.
*
* (c) Paweł Jędrzejewski
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
declare(strict_types=1);
namespace Sylius\Component\Promotion\Provider;
final class Calendar implements DateTimeProviderInterface
{
public function now(): \DateTimeInterface
{
return new \DateTimeImmutable();
}
}

View file

@ -1,10 +0,0 @@
<?php
declare(strict_types=1);
namespace Sylius\Component\Promotion\Provider;
interface DateTimeProviderInterface
{
public function now(): \DateTimeInterface;
}

View file

@ -1,30 +0,0 @@
<?php
/*
* This file is part of the Sylius package.
*
* (c) Paweł Jędrzejewski
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
declare(strict_types=1);
namespace spec\Sylius\Component\Promotion\Provider;
use PhpSpec\ObjectBehavior;
use Sylius\Component\Promotion\Provider\DateTimeProviderInterface;
final class CalendarSpec extends ObjectBehavior
{
function it_implements_a_date_time_provider(): void
{
$this->shouldImplement(DateTimeProviderInterface::class);
}
function it_provides_a_date(): void
{
$this->now()->shouldBeAnInstanceOf(\DateTimeInterface::class);
}
}