Skip to content

Commit

Permalink
minor #15605 [Workflow] Add catalog promotion state machine config (W…
Browse files Browse the repository at this point in the history
…ojdylak)

This PR was merged into the 1.13 branch.

Discussion
----------

| Q               | A                                                            |
|-----------------|--------------------------------------------------------------|
| Branch?         | 1.13
| Bug fix?        | no
| New feature?    | yes
| BC breaks?      | no
| Deprecations?   | no
| Related tickets | N/A
| License         | MIT


Commits
-------
  [CoreBundle][Workflow] Add catalog promotion state machine config
  • Loading branch information
NoResponseMate committed Dec 6, 2023
2 parents 1b255b4 + b63aebb commit 5b0bb78
Show file tree
Hide file tree
Showing 2 changed files with 100 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
framework:
workflows:
!php/const Sylius\Component\Promotion\Model\CatalogPromotionTransitions::GRAPH:
type: state_machine
marking_store:
type: method
property: state
supports:
- Sylius\Component\Core\Model\CatalogPromotionInterface
initial_marking: !php/const Sylius\Component\Promotion\Model\CatalogPromotionStates::STATE_INACTIVE
places:
- !php/const Sylius\Component\Promotion\Model\CatalogPromotionStates::STATE_INACTIVE
- !php/const Sylius\Component\Promotion\Model\CatalogPromotionStates::STATE_PROCESSING
- !php/const Sylius\Component\Promotion\Model\CatalogPromotionStates::STATE_ACTIVE
transitions:
!php/const Sylius\Component\Promotion\Model\CatalogPromotionTransitions::TRANSITION_PROCESS:
from:
- !php/const Sylius\Component\Promotion\Model\CatalogPromotionStates::STATE_INACTIVE
- !php/const Sylius\Component\Promotion\Model\CatalogPromotionStates::STATE_ACTIVE
to: !php/const Sylius\Component\Promotion\Model\CatalogPromotionStates::STATE_PROCESSING
!php/const Sylius\Component\Promotion\Model\CatalogPromotionTransitions::TRANSITION_ACTIVATE:
from: !php/const Sylius\Component\Promotion\Model\CatalogPromotionStates::STATE_PROCESSING
to: !php/const Sylius\Component\Promotion\Model\CatalogPromotionStates::STATE_ACTIVE
!php/const Sylius\Component\Promotion\Model\CatalogPromotionTransitions::TRANSITION_DEACTIVATE:
from: !php/const Sylius\Component\Promotion\Model\CatalogPromotionStates::STATE_PROCESSING
to: !php/const Sylius\Component\Promotion\Model\CatalogPromotionStates::STATE_INACTIVE
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<?php

/*
* This file is part of the Sylius package.
*
* (c) Sylius Sp. z o.o.
*
* 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\Tests\Functional\StateMachine;

use Sylius\Bundle\CoreBundle\StateMachine\StateMachineInterface;
use Sylius\Component\Core\Model\CatalogPromotion;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;

final class CatalogPromotionWorkflowTest extends KernelTestCase
{
/** @test */
public function it_applies_available_transition_for_catalog_promotion_inactive_status(): void
{
$stateMachine = $this->getStateMachine();
$catalogPromotion = new CatalogPromotion();

$stateMachine->apply($catalogPromotion, 'sylius_catalog_promotion', 'process');

$this->assertSame('processing', $catalogPromotion->getState());
}

/** @test */
public function it_applies_available_transition_for_catalog_promotion_active_status(): void
{
$stateMachine = $this->getStateMachine();
$catalogPromotion = new CatalogPromotion();
$catalogPromotion->setState('active');

$stateMachine->apply($catalogPromotion, 'sylius_catalog_promotion', 'process');

$this->assertSame('processing', $catalogPromotion->getState());
}

/**
* @test
*
* @dataProvider availableTransitionsForProcessingState
*/
public function it_applies_all_available_transition_for_catalog_promotion_processing_status(
string $transition,
string $expectedStatus,
): void
{
$stateMachine = $this->getStateMachine();
$catalogPromotion = new CatalogPromotion();
$catalogPromotion->setState('processing');

$stateMachine->apply($catalogPromotion, 'sylius_catalog_promotion', $transition);

$this->assertSame($expectedStatus, $catalogPromotion->getState());
}

public function availableTransitionsForProcessingState(): iterable
{
yield ['activate', 'active'];
yield ['deactivate', 'inactive'];
}

private function getStateMachine(): StateMachineInterface
{
return self::getContainer()->get('sylius.state_machine.adapter.symfony_workflow');
}
}

0 comments on commit 5b0bb78

Please sign in to comment.