Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 0dbb05b

Browse files
authored
refactor #13579 [Catalog Promotion] Move catalog promotion processing after the fixture execution (lchrusciel)
This PR was merged into the 1.11 branch. Discussion ---------- | Q | A | --------------- | ----- | Branch? | 1.11 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Related tickets | | License | MIT Previous: ~With clearing entity manger we don't need to trace that many objects in UnitOfWork, therefore we are not calculating that much changes and we save ton of memory.~ ~Ref. https://blackfire.io/profiles/compare/7c9cb9fd-c43f-4420-8e0a-0af2a7b4b000/graph~ Now: Just a refactor of CP fixtures. The EntityManager will be cleared with https://github.com/symfony/doctrine-bridge/blob/5.4/Messenger/DoctrineClearEntityManagerWorkerSubscriber.php just by the fact, that it will be processed asynced. Which will be done in #13578. #13578 vs previous implementation -https://blackfire.io/profiles/compare/f560f723-f970-41b3-ac1a-7fe3a8858d77/graph <!-- - Bug fixes must be submitted against the 1.10 or 1.11 branch(the lowest possible) - Features and deprecations must be submitted against the master branch - Make sure that the correct base branch is set To be sure you are not breaking any Backward Compatibilities, check the documentation: https://docs.sylius.com/en/latest/book/organization/backward-compatibility-promise.html --> Commits ------- ee3a2da [Catalog Promotion] Move catalog promotion processing after the fixture execution
2 parents 60e0dba + ee3a2da commit 0dbb05b

7 files changed

Lines changed: 127 additions & 8 deletions

File tree

src/Sylius/Bundle/CoreBundle/Fixture/Factory/CatalogPromotionExampleFactory.php

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,6 @@ class CatalogPromotionExampleFactory extends AbstractExampleFactory implements E
4040

4141
private ExampleFactoryInterface $catalogPromotionActionExampleFactory;
4242

43-
private AllProductVariantsCatalogPromotionsProcessorInterface $allProductVariantsCatalogPromotionsProcessor;
44-
4543
private Generator $faker;
4644

4745
private OptionsResolver $optionsResolver;
@@ -51,15 +49,13 @@ public function __construct(
5149
RepositoryInterface $localeRepository,
5250
ChannelRepositoryInterface $channelRepository,
5351
ExampleFactoryInterface $catalogPromotionScopeExampleFactory,
54-
ExampleFactoryInterface $catalogPromotionActionExampleFactory,
55-
AllProductVariantsCatalogPromotionsProcessorInterface $allProductVariantsCatalogPromotionsProcessor
52+
ExampleFactoryInterface $catalogPromotionActionExampleFactory
5653
) {
5754
$this->catalogPromotionFactory = $catalogPromotionFactory;
5855
$this->localeRepository = $localeRepository;
5956
$this->channelRepository = $channelRepository;
6057
$this->catalogPromotionScopeExampleFactory = $catalogPromotionScopeExampleFactory;
6158
$this->catalogPromotionActionExampleFactory = $catalogPromotionActionExampleFactory;
62-
$this->allProductVariantsCatalogPromotionsProcessor = $allProductVariantsCatalogPromotionsProcessor;
6359
$this->faker = Factory::create();
6460
$this->optionsResolver = new OptionsResolver();
6561

@@ -110,8 +106,6 @@ public function create(array $options = []): CatalogPromotionInterface
110106
}
111107
}
112108

113-
$this->allProductVariantsCatalogPromotionsProcessor->process();
114-
115109
return $catalogPromotion;
116110
}
117111

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Sylius package.
5+
*
6+
* (c) Paweł Jędrzejewski
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
declare(strict_types=1);
13+
14+
namespace Sylius\Bundle\CoreBundle\Fixture\Listener;
15+
16+
use Sylius\Bundle\CoreBundle\Fixture\CatalogPromotionFixture;
17+
use Sylius\Bundle\CoreBundle\Processor\AllProductVariantsCatalogPromotionsProcessorInterface;
18+
use Sylius\Bundle\FixturesBundle\Listener\AbstractListener;
19+
use Sylius\Bundle\FixturesBundle\Listener\AfterFixtureListenerInterface;
20+
use Sylius\Bundle\FixturesBundle\Listener\FixtureEvent;
21+
22+
final class CatalogPromotionExecutorListener extends AbstractListener implements AfterFixtureListenerInterface
23+
{
24+
public function __construct(private AllProductVariantsCatalogPromotionsProcessorInterface $allCatalogPromotionsProcessor)
25+
{
26+
}
27+
28+
public function afterFixture(FixtureEvent $fixtureEvent, array $options): void
29+
{
30+
if ($fixtureEvent->fixture() instanceof CatalogPromotionFixture) {
31+
$this->allCatalogPromotionsProcessor->process();
32+
}
33+
}
34+
35+
public function getName(): string
36+
{
37+
return 'catalog_promotion_processor_executor';
38+
}
39+
}

src/Sylius/Bundle/CoreBundle/Resources/config/app/fixtures/promotion.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
sylius_fixtures:
55
suites:
66
default:
7+
listeners:
8+
catalog_promotion_processor_executor: ~
79
fixtures:
810
promotion:
911
options:

src/Sylius/Bundle/CoreBundle/Resources/config/services.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
<import resource="services/dashboard.xml" />
2222
<import resource="services/emails.xml" />
2323
<import resource="services/fixtures.xml" />
24+
<import resource="services/fixtures_listeners.xml" />
2425
<import resource="services/fixtures_factories.xml" />
2526
<import resource="services/form.xml" />
2627
<import resource="services/installer.xml" />

src/Sylius/Bundle/CoreBundle/Resources/config/services/fixtures_factories.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
<argument type="service" id="sylius.repository.channel" />
2222
<argument type="service" id="Sylius\Bundle\CoreBundle\Fixture\Factory\CatalogPromotionScopeExampleFactory" />
2323
<argument type="service" id="Sylius\Bundle\CoreBundle\Fixture\Factory\CatalogPromotionActionExampleFactory" />
24-
<argument type="service" id="Sylius\Bundle\CoreBundle\Processor\AllProductVariantsCatalogPromotionsProcessorInterface" />
2524
</service>
2625

2726
<service id="Sylius\Bundle\CoreBundle\Fixture\Factory\CatalogPromotionScopeExampleFactory">
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
<!--
4+
5+
This file is part of the Sylius package.
6+
7+
(c) Paweł Jędrzejewski
8+
9+
For the full copyright and license information, please view the LICENSE
10+
file that was distributed with this source code.
11+
12+
-->
13+
14+
<container xmlns="http://symfony.com/schema/dic/services" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
15+
<services>
16+
<defaults public="true" />
17+
18+
<service id="sylius_fixtures.listener.catalog_promotion_executor" class="Sylius\Bundle\CoreBundle\Fixture\Listener\CatalogPromotionExecutorListener" public="false">
19+
<argument type="service" id="Sylius\Bundle\CoreBundle\Processor\AllProductVariantsCatalogPromotionsProcessorInterface" />
20+
<tag name="sylius_fixtures.listener" />
21+
</service>
22+
</services>
23+
</container>
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Sylius package.
5+
*
6+
* (c) Paweł Jędrzejewski
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
declare(strict_types=1);
13+
14+
namespace spec\Sylius\Bundle\CoreBundle\Fixture\Listener;
15+
16+
use PhpSpec\ObjectBehavior;
17+
use Sylius\Bundle\CoreBundle\Fixture\CatalogPromotionFixture;
18+
use Sylius\Bundle\CoreBundle\Processor\AllProductVariantsCatalogPromotionsProcessorInterface;
19+
use Sylius\Bundle\FixturesBundle\Fixture\FixtureInterface;
20+
use Sylius\Bundle\FixturesBundle\Listener\AfterFixtureListenerInterface;
21+
use Sylius\Bundle\FixturesBundle\Listener\FixtureEvent;
22+
use Sylius\Bundle\FixturesBundle\Listener\ListenerInterface;
23+
use Sylius\Bundle\FixturesBundle\Suite\SuiteInterface;
24+
25+
final class CatalogPromotionExecutorListenerSpec extends ObjectBehavior
26+
{
27+
function let(AllProductVariantsCatalogPromotionsProcessorInterface $allCatalogPromotionsProcessor): void
28+
{
29+
$this->beConstructedWith($allCatalogPromotionsProcessor);
30+
}
31+
32+
function it_implements_listener_interface(): void
33+
{
34+
$this->shouldImplement(ListenerInterface::class);
35+
}
36+
37+
function it_listens_for_after_fixture_events(): void
38+
{
39+
$this->shouldImplement(AfterFixtureListenerInterface::class);
40+
}
41+
42+
function it_triggers_catalog_promotion_processing_after_catalog_promotion_fixture_execution(
43+
AllProductVariantsCatalogPromotionsProcessorInterface $allCatalogPromotionsProcessor,
44+
SuiteInterface $suite,
45+
CatalogPromotionFixture $catalogPromotionFixture
46+
): void {
47+
$this->afterFixture(new FixtureEvent($suite->getWrappedObject(), $catalogPromotionFixture->getWrappedObject(), []), []);
48+
49+
$allCatalogPromotionsProcessor->process()->shouldBeCalled();
50+
}
51+
52+
function it_does_not_trigger_catalog_promotion_processing_after_any_other_fixture_execution(
53+
AllProductVariantsCatalogPromotionsProcessorInterface $allCatalogPromotionsProcessor,
54+
SuiteInterface $suite,
55+
FixtureInterface $fixture
56+
): void {
57+
$this->afterFixture(new FixtureEvent($suite->getWrappedObject(), $fixture->getWrappedObject(), []), []);
58+
59+
$allCatalogPromotionsProcessor->process()->shouldNotBeCalled();
60+
}
61+
}

0 commit comments

Comments
 (0)