-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
OP-558 - update plugin to Sylius 2 - fix phpspec tests
- Loading branch information
1 parent
4d13a78
commit 18d5547
Showing
1 changed file
with
27 additions
and
21 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -1,50 +1,56 @@ | ||
<?php | ||
|
||
/* | ||
* This file was created by developers working at BitBag | ||
* Do you need more information about us and what we do? Visit our https://bitbag.io website! | ||
* We are hiring developers from all over the world. Join us and start your new, exciting adventure and become part of us: https://bitbag.io/career | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace spec\BitBag\SyliusBlacklistPlugin\StateResolver; | ||
|
||
use BitBag\SyliusBlacklistPlugin\StateResolver\CustomerStateResolver; | ||
use BitBag\SyliusBlacklistPlugin\StateResolver\CustomerStateResolverInterface; | ||
use BitBag\SyliusBlacklistPlugin\Transitions\CustomerTransitions; | ||
use Doctrine\Persistence\ObjectManager; | ||
use PhpSpec\ObjectBehavior; | ||
use SM\Factory\FactoryInterface; | ||
use SM\StateMachine\StateMachineInterface; | ||
use Tests\BitBag\SyliusBlacklistPlugin\Entity\CustomerInterface; | ||
use Sylius\Component\Customer\Model\CustomerInterface; | ||
use Symfony\Component\Workflow\WorkflowInterface; | ||
|
||
final class CustomerStateResolverSpec extends ObjectBehavior | ||
{ | ||
function let(FactoryInterface $stateMachineFactory, ObjectManager $customerManager): void | ||
function let(WorkflowInterface $workflow, ObjectManager $customerManager): void | ||
{ | ||
$this->beConstructedWith($stateMachineFactory, $customerManager); | ||
$this->beConstructedWith($workflow, $customerManager); | ||
} | ||
|
||
function it_is_initializable(): void | ||
{ | ||
$this->shouldHaveType(CustomerStateResolver::class); | ||
} | ||
|
||
function it_implements_automatic_blacklisting_rule_checker_interface(): void | ||
function it_implements_customer_state_resolver_interface(): void | ||
{ | ||
$this->shouldHaveType(CustomerStateResolverInterface::class); | ||
$this->shouldImplement(CustomerStateResolverInterface::class); | ||
} | ||
|
||
function it_changes_fraud_status_of_customer(CustomerInterface $customer, FactoryInterface $stateMachineFactory, StateMachineInterface $stateMachine, ObjectManager $customerManager): void | ||
{ | ||
$stateMachineFactory->get($customer, CustomerTransitions::GRAPH)->willReturn($stateMachine); | ||
$stateMachine->can(CustomerTransitions::TRANSITION_BLACKLISTING_PROCESS)->willReturn(true); | ||
|
||
$stateMachineFactory->get($customer, CustomerTransitions::GRAPH)->shouldBeCalled(); | ||
$stateMachine->can(CustomerTransitions::TRANSITION_BLACKLISTING_PROCESS)->shouldBeCalled(); | ||
$stateMachine->apply(CustomerTransitions::TRANSITION_BLACKLISTING_PROCESS)->shouldBeCalled(); | ||
function it_changes_state_on_blacklisted( | ||
WorkflowInterface $workflow, | ||
ObjectManager $customerManager, | ||
CustomerInterface $customer | ||
): void { | ||
$workflow->can($customer, 'blacklisting')->willReturn(true); | ||
$workflow->apply($customer, 'blacklisting')->shouldBeCalled(); | ||
$customerManager->persist($customer)->shouldBeCalled(); | ||
$customerManager->flush()->shouldBeCalled(); | ||
|
||
$this->changeStateOnBlacklisted($customer); | ||
} | ||
|
||
function it_does_not_change_state_if_cannot_apply_blacklisting( | ||
WorkflowInterface $workflow, | ||
ObjectManager $customerManager, | ||
CustomerInterface $customer | ||
): void { | ||
$workflow->can($customer, 'blacklisting')->willReturn(false); | ||
$workflow->apply($customer, 'blacklisting')->shouldNotBeCalled(); | ||
$customerManager->persist($customer)->shouldNotBeCalled(); | ||
$customerManager->flush()->shouldNotBeCalled(); | ||
|
||
$this->changeStateOnBlacklisted($customer); | ||
} | ||
} |