-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor #13624 [CatalogPromotions] Refactor processing catalog promo…
…tions states to use commands (GSadee) This PR was merged into the 1.11 branch. Discussion ---------- | Q | A | --------------- | ----- | Branch? | 1.11 | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | no | Related tickets | | License | MIT <!-- - 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 ------- 7249a33 [CatalogPromotions] Refactor processing catalog promotions states to use commands
- Loading branch information
Showing
11 changed files
with
199 additions
and
95 deletions.
There are no files selected for viewing
21 changes: 21 additions & 0 deletions
21
src/Sylius/Bundle/CoreBundle/CatalogPromotion/Command/UpdateCatalogPromotionState.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?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\Bundle\CoreBundle\CatalogPromotion\Command; | ||
|
||
final class UpdateCatalogPromotionState | ||
{ | ||
public function __construct(public string $code) | ||
{ | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
.../Bundle/CoreBundle/CatalogPromotion/CommandHandler/UpdateCatalogPromotionStateHandler.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?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\Bundle\CoreBundle\CatalogPromotion\CommandHandler; | ||
|
||
use Sylius\Bundle\CoreBundle\CatalogPromotion\Command\UpdateCatalogPromotionState; | ||
use Sylius\Bundle\CoreBundle\Processor\CatalogPromotionStateProcessorInterface; | ||
use Sylius\Component\Core\Model\CatalogPromotionInterface; | ||
use Sylius\Component\Resource\Repository\RepositoryInterface; | ||
|
||
final class UpdateCatalogPromotionStateHandler | ||
{ | ||
public function __construct( | ||
private CatalogPromotionStateProcessorInterface $catalogPromotionStateProcessor, | ||
private RepositoryInterface $catalogPromotionRepository | ||
) { | ||
} | ||
|
||
public function __invoke(UpdateCatalogPromotionState $command): void | ||
{ | ||
/** @var CatalogPromotionInterface|null $catalogPromotion */ | ||
$catalogPromotion = $this->catalogPromotionRepository->findOneBy(['code' => $command->code]); | ||
if (null === $catalogPromotion) { | ||
return; | ||
} | ||
|
||
$this->catalogPromotionStateProcessor->process($catalogPromotion); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 79 additions & 0 deletions
79
...oreBundle/spec/CatalogPromotion/CommandHandler/UpdateCatalogPromotionStateHandlerSpec.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
<?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\Bundle\CoreBundle\CatalogPromotion\CommandHandler; | ||
|
||
use PhpSpec\ObjectBehavior; | ||
use Prophecy\Argument; | ||
use Sylius\Bundle\CoreBundle\CatalogPromotion\Command\UpdateCatalogPromotionState; | ||
use Sylius\Bundle\CoreBundle\Processor\CatalogPromotionStateProcessorInterface; | ||
use Sylius\Component\Core\Model\CatalogPromotionInterface; | ||
use Sylius\Component\Resource\Repository\RepositoryInterface; | ||
|
||
final class UpdateCatalogPromotionStateHandlerSpec extends ObjectBehavior | ||
{ | ||
function let( | ||
CatalogPromotionStateProcessorInterface $catalogPromotionStateProcessor, | ||
RepositoryInterface $catalogPromotionRepository | ||
): void { | ||
$this->beConstructedWith($catalogPromotionStateProcessor, $catalogPromotionRepository); | ||
} | ||
|
||
function it_processes_catalog_promotion_that_has_just_been_created( | ||
CatalogPromotionStateProcessorInterface $catalogPromotionStateProcessor, | ||
RepositoryInterface $catalogPromotionRepository, | ||
CatalogPromotionInterface $catalogPromotion | ||
): void { | ||
$catalogPromotionRepository->findOneBy(['code' => 'WINTER_MUGS_SALE'])->willReturn($catalogPromotion); | ||
|
||
$catalogPromotionStateProcessor->process($catalogPromotion)->shouldBeCalled(); | ||
|
||
$this(new UpdateCatalogPromotionState('WINTER_MUGS_SALE')); | ||
} | ||
|
||
function it_processes_catalog_promotion_that_has_just_been_updated( | ||
CatalogPromotionStateProcessorInterface $catalogPromotionStateProcessor, | ||
RepositoryInterface $catalogPromotionRepository, | ||
CatalogPromotionInterface $catalogPromotion | ||
): void { | ||
$catalogPromotionRepository->findOneBy(['code' => 'WINTER_MUGS_SALE'])->willReturn($catalogPromotion); | ||
|
||
$catalogPromotionStateProcessor->process($catalogPromotion)->shouldBeCalled(); | ||
|
||
$this(new UpdateCatalogPromotionState('WINTER_MUGS_SALE')); | ||
} | ||
|
||
function it_processes_catalog_promotion_that_has_just_been_ended( | ||
CatalogPromotionStateProcessorInterface $catalogPromotionStateProcessor, | ||
RepositoryInterface $catalogPromotionRepository, | ||
CatalogPromotionInterface $catalogPromotion | ||
): void { | ||
$catalogPromotionRepository->findOneBy(['code' => 'WINTER_MUGS_SALE'])->willReturn($catalogPromotion); | ||
|
||
$catalogPromotionStateProcessor->process($catalogPromotion)->shouldBeCalled(); | ||
|
||
$this(new UpdateCatalogPromotionState('WINTER_MUGS_SALE')); | ||
} | ||
|
||
function it_does_nothing_if_there_is_no_catalog_promotion_with_given_code( | ||
CatalogPromotionStateProcessorInterface $catalogPromotionStateProcessor, | ||
RepositoryInterface $catalogPromotionRepository | ||
): void { | ||
$catalogPromotionRepository->findOneBy(['code' => 'WINTER_MUGS_SALE'])->willReturn(null); | ||
$catalogPromotionRepository->findAll()->shouldNotBeCalled(); | ||
|
||
$catalogPromotionStateProcessor->process(Argument::any())->shouldNotBeCalled(); | ||
|
||
$this(new UpdateCatalogPromotionState('WINTER_MUGS_SALE')); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.