From 18d5547246d35a04ac89d6081229f54028e3db39 Mon Sep 17 00:00:00 2001
From: Dariusz Rup <dariusz.rup@icloud.com>
Date: Mon, 13 Jan 2025 08:27:56 +0100
Subject: [PATCH] OP-558 - update plugin to Sylius 2 - fix phpspec tests

---
 .../CustomerStateResolverSpec.php             | 48 +++++++++++--------
 1 file changed, 27 insertions(+), 21 deletions(-)

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 @@
 <?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
@@ -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);
+    }
 }