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