diff --git a/spec/StateResolver/CustomerStateResolverSpec.php b/spec/StateResolver/CustomerStateResolverSpec.php index c1c5febb..f1d7f47f 100644 --- a/spec/StateResolver/CustomerStateResolverSpec.php +++ b/spec/StateResolver/CustomerStateResolverSpec.php @@ -1,27 +1,21 @@ beConstructedWith($stateMachineFactory, $customerManager); + $this->beConstructedWith($workflow, $customerManager); } function it_is_initializable(): void @@ -29,22 +23,34 @@ 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); + } }