1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file has been created by developers from BitBag. |
5
|
|
|
* Feel free to contact us once you face any issues or want to start |
6
|
|
|
* another great project. |
7
|
|
|
* You can find more information about us on https://bitbag.shop and write us |
8
|
|
|
* an email on [email protected]. |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
declare(strict_types=1); |
12
|
|
|
|
13
|
|
|
namespace spec\BitBag\SyliusMolliePlugin\Action\StateMachine; |
14
|
|
|
|
15
|
|
|
use BitBag\SyliusMolliePlugin\Action\Api\BaseApiAwareAction; |
16
|
|
|
use BitBag\SyliusMolliePlugin\Action\StateMachine\StatusRecurringSubscriptionAction; |
17
|
|
|
use BitBag\SyliusMolliePlugin\Client\MollieApiClient; |
18
|
|
|
use BitBag\SyliusMolliePlugin\Entity\SubscriptionInterface; |
19
|
|
|
use BitBag\SyliusMolliePlugin\Request\StateMachine\StatusRecurringSubscription; |
20
|
|
|
use BitBag\SyliusMolliePlugin\Transitions\SubscriptionTransitions; |
21
|
|
|
use Doctrine\ORM\EntityManagerInterface; |
22
|
|
|
use Mollie\Api\Endpoints\CustomerEndpoint; |
23
|
|
|
use Mollie\Api\Resources\Customer; |
24
|
|
|
use Mollie\Api\Resources\Subscription; |
25
|
|
|
use Mollie\Api\Types\SubscriptionStatus; |
26
|
|
|
use Payum\Core\Action\ActionInterface; |
27
|
|
|
use Payum\Core\ApiAwareInterface; |
28
|
|
|
use PhpSpec\ObjectBehavior; |
29
|
|
|
use SM\Factory\FactoryInterface; |
30
|
|
|
use SM\StateMachine\StateMachineInterface; |
31
|
|
|
|
32
|
|
|
final class StatusRecurringSubscriptionActionSpec extends ObjectBehavior |
33
|
|
|
{ |
34
|
|
|
function let( |
|
|
|
|
35
|
|
|
EntityManagerInterface $subscriptionManager, |
36
|
|
|
FactoryInterface $subscriptionSateMachineFactory |
37
|
|
|
): void { |
38
|
|
|
$this->beConstructedWith( |
39
|
|
|
$subscriptionManager, |
40
|
|
|
$subscriptionSateMachineFactory |
41
|
|
|
); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
function it_is_initializable(): void |
|
|
|
|
45
|
|
|
{ |
46
|
|
|
$this->shouldHaveType(StatusRecurringSubscriptionAction::class); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
function it_implements_action_interface(): void |
50
|
|
|
{ |
51
|
|
|
$this->shouldHaveType(ActionInterface::class); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
function it_implements_api_aware_interface(): void |
55
|
|
|
{ |
56
|
|
|
$this->shouldHaveType(ApiAwareInterface::class); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
function it_extends_base_api_aware(): void |
60
|
|
|
{ |
61
|
|
|
$this->shouldHaveType(BaseApiAwareAction::class); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
function it_executes( |
65
|
|
|
StatusRecurringSubscription $request, |
66
|
|
|
MollieApiClient $mollieApiClient, |
67
|
|
|
SubscriptionInterface $subscription, |
68
|
|
|
CustomerEndpoint $customerEndpoint, |
69
|
|
|
Customer $customer, |
70
|
|
|
FactoryInterface $subscriptionSateMachineFactory, |
71
|
|
|
StateMachineInterface $stateMachine, |
72
|
|
|
Subscription $subscriptionApi |
73
|
|
|
): void { |
74
|
|
|
$this->setApi($mollieApiClient); |
|
|
|
|
75
|
|
|
$stateMachine->can(SubscriptionTransitions::TRANSITION_ACTIVATE)->willReturn(); |
76
|
|
|
$subscriptionApi->status = SubscriptionStatus::STATUS_ACTIVE; |
77
|
|
|
$subscriptionSateMachineFactory->get($subscription, SubscriptionTransitions::GRAPH)->willReturn($stateMachine); |
|
|
|
|
78
|
|
|
$subscription->getSubscriptionId()->willReturn('id_1'); |
79
|
|
|
$subscription->getCustomerId()->willReturn('id_1'); |
80
|
|
|
$customer->getSubscription('id_1')->willReturn($subscriptionApi); |
|
|
|
|
81
|
|
|
$customerEndpoint->get('id_1')->willReturn($customer); |
|
|
|
|
82
|
|
|
$mollieApiClient->customers = $customerEndpoint; |
83
|
|
|
$request->getModel()->willReturn($subscription); |
84
|
|
|
|
85
|
|
|
$this->execute($request); |
|
|
|
|
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
function it_supports_status_recurring_subscription_request_and_subscription_model( |
89
|
|
|
StatusRecurringSubscription $request, |
90
|
|
|
SubscriptionInterface $subscription |
91
|
|
|
): void { |
92
|
|
|
$request->getModel()->willReturn($subscription); |
93
|
|
|
|
94
|
|
|
$this->supports($request)->shouldReturn(true); |
|
|
|
|
95
|
|
|
} |
96
|
|
|
} |
97
|
|
|
|
Adding explicit visibility (
private
,protected
, orpublic
) is generally recommend to communicate to other developers how, and from where this method is intended to be used.