|
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\Api; |
|
14
|
|
|
|
|
15
|
|
|
use BitBag\SyliusMolliePlugin\Action\Api\BaseApiAwareAction; |
|
16
|
|
|
use BitBag\SyliusMolliePlugin\Action\Api\CreateRecurringSubscriptionAction; |
|
17
|
|
|
use BitBag\SyliusMolliePlugin\Client\MollieApiClient; |
|
18
|
|
|
use BitBag\SyliusMolliePlugin\Entity\SubscriptionInterface; |
|
19
|
|
|
use BitBag\SyliusMolliePlugin\Request\Api\CreateRecurringSubscription; |
|
20
|
|
|
use Doctrine\ORM\EntityManagerInterface; |
|
21
|
|
|
use Payum\Core\Action\ActionInterface; |
|
22
|
|
|
use Payum\Core\ApiAwareInterface; |
|
23
|
|
|
use Payum\Core\Bridge\Spl\ArrayObject; |
|
24
|
|
|
use Payum\Core\GatewayAwareInterface; |
|
25
|
|
|
use Payum\Core\GatewayInterface; |
|
26
|
|
|
use PhpSpec\ObjectBehavior; |
|
27
|
|
|
use SM\Factory\FactoryInterface as SateMachineFactoryInterface; |
|
28
|
|
|
use Sylius\Component\Core\Model\OrderInterface; |
|
29
|
|
|
use Sylius\Component\Core\Repository\OrderRepositoryInterface; |
|
30
|
|
|
use Sylius\Component\Resource\Factory\FactoryInterface; |
|
31
|
|
|
|
|
32
|
|
|
final class CreateRecurringSubscriptionActionSpec extends ObjectBehavior |
|
33
|
|
|
{ |
|
34
|
|
|
function let( |
|
|
|
|
|
|
35
|
|
|
FactoryInterface $subscriptionFactory, |
|
36
|
|
|
EntityManagerInterface $subscriptionManager, |
|
37
|
|
|
SateMachineFactoryInterface $subscriptionSateMachineFactory, |
|
38
|
|
|
OrderRepositoryInterface $orderRepository |
|
39
|
|
|
): void { |
|
40
|
|
|
$this->beConstructedWith( |
|
41
|
|
|
$subscriptionFactory, |
|
42
|
|
|
$subscriptionManager, |
|
43
|
|
|
$subscriptionSateMachineFactory, |
|
44
|
|
|
$orderRepository |
|
45
|
|
|
); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
function it_is_initializable(): void |
|
|
|
|
|
|
49
|
|
|
{ |
|
50
|
|
|
$this->shouldHaveType(CreateRecurringSubscriptionAction::class); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
function it_implements_action_interface(): void |
|
54
|
|
|
{ |
|
55
|
|
|
$this->shouldHaveType(ActionInterface::class); |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
function it_implements_api_aware_interface(): void |
|
59
|
|
|
{ |
|
60
|
|
|
$this->shouldHaveType(ApiAwareInterface::class); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
function it_implements_gateway_aware_interface(): void |
|
64
|
|
|
{ |
|
65
|
|
|
$this->shouldHaveType(GatewayAwareInterface::class); |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
function it_extends_base_api_aware(): void |
|
69
|
|
|
{ |
|
70
|
|
|
$this->shouldHaveType(BaseApiAwareAction::class); |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
function it_executes( |
|
74
|
|
|
CreateRecurringSubscription $request, |
|
75
|
|
|
MollieApiClient $mollieApiClient, |
|
76
|
|
|
ArrayObject $arrayObject, |
|
77
|
|
|
\Mollie_API_Resource_Customers_Subscriptions $subscriptions, |
|
78
|
|
|
\Mollie_API_Object_Customer_Subscription $customerSubscription, |
|
79
|
|
|
\Mollie_API_Resource_Base $resourceBase, |
|
80
|
|
|
FactoryInterface $subscriptionFactory, |
|
81
|
|
|
SubscriptionInterface $subscription, |
|
82
|
|
|
OrderInterface $order, |
|
83
|
|
|
OrderRepositoryInterface $orderRepository, |
|
84
|
|
|
GatewayInterface $gateway |
|
85
|
|
|
): void { |
|
86
|
|
|
$this->setApi($mollieApiClient); |
|
|
|
|
|
|
87
|
|
|
$this->setGateway($gateway); |
|
|
|
|
|
|
88
|
|
|
$mollieApiClient->customers_subscriptions = $subscriptions; |
|
89
|
|
|
$orderRepository->find(1)->willReturn($order); |
|
90
|
|
|
$subscriptionFactory->createNew()->willReturn($subscription); |
|
91
|
|
|
$arrayObject->offsetGet('customer_mollie_id')->willReturn('id_1'); |
|
92
|
|
|
$arrayObject->offsetGet('interval')->willReturn('3 days'); |
|
93
|
|
|
$arrayObject->offsetGet('description')->willReturn(''); |
|
94
|
|
|
$arrayObject->offsetGet('webhookUrl')->willReturn('www.example.com/webhookUrl'); |
|
95
|
|
|
$arrayObject->offsetGet('metadata')->willReturn(['order_id' => 1]); |
|
96
|
|
|
$arrayObject->offsetGet('amount')->willReturn(100); |
|
97
|
|
|
$resourceBase->create([ |
|
98
|
|
|
'amount' => 100, |
|
99
|
|
|
'interval' => '3 days', |
|
100
|
|
|
'description' => '', |
|
101
|
|
|
'method' => 'directdebit', |
|
102
|
|
|
'webhookUrl' => 'www.example.com/webhookUrl', |
|
103
|
|
|
'metadata' => ['order_id' => 1], |
|
104
|
|
|
])->willReturn($customerSubscription); |
|
105
|
|
|
$subscriptions->withParentId('id_1')->willReturn($resourceBase); |
|
|
|
|
|
|
106
|
|
|
$request->getModel()->willReturn($arrayObject); |
|
107
|
|
|
|
|
108
|
|
|
$arrayObject->offsetExists('subscription_id')->shouldBeCalled(); |
|
109
|
|
|
$arrayObject->offsetSet('subscription_mollie_id', null)->shouldBeCalled(); |
|
|
|
|
|
|
110
|
|
|
|
|
111
|
|
|
$this->execute($request); |
|
|
|
|
|
|
112
|
|
|
} |
|
113
|
|
|
|
|
114
|
|
|
function it_supports_only_create_recurring_subscription_request_and_array_access( |
|
115
|
|
|
CreateRecurringSubscription $request, |
|
116
|
|
|
\ArrayAccess $arrayAccess |
|
117
|
|
|
): void { |
|
118
|
|
|
$request->getModel()->willReturn($arrayAccess); |
|
119
|
|
|
|
|
120
|
|
|
$this->supports($request)->shouldReturn(true); |
|
|
|
|
|
|
121
|
|
|
} |
|
122
|
|
|
} |
|
123
|
|
|
|
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.