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\CreateSepaMandateAction; |
17
|
|
|
use BitBag\SyliusMolliePlugin\Client\MollieApiClient; |
18
|
|
|
use BitBag\SyliusMolliePlugin\Request\Api\CreateSepaMandate; |
19
|
|
|
use Mollie\Api\Endpoints\CustomerEndpoint; |
20
|
|
|
use Mollie\Api\Resources\Customer; |
21
|
|
|
use Mollie\Api\Resources\Mandate; |
22
|
|
|
use Payum\Core\Action\ActionInterface; |
23
|
|
|
use Payum\Core\ApiAwareInterface; |
24
|
|
|
use Payum\Core\Bridge\Spl\ArrayObject; |
25
|
|
|
use Payum\Core\GatewayAwareInterface; |
26
|
|
|
use Payum\Core\GatewayInterface; |
27
|
|
|
use PhpSpec\ObjectBehavior; |
28
|
|
|
use Symfony\Component\HttpFoundation\Session\SessionInterface; |
29
|
|
|
|
30
|
|
|
final class CreateSepaMandateActionSpec extends ObjectBehavior |
31
|
|
|
{ |
32
|
|
|
function let(SessionInterface $session): void |
|
|
|
|
33
|
|
|
{ |
34
|
|
|
$this->beConstructedWith( |
35
|
|
|
$session |
36
|
|
|
); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
function it_is_initializable(): void |
|
|
|
|
40
|
|
|
{ |
41
|
|
|
$this->shouldHaveType(CreateSepaMandateAction::class); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
function it_implements_action_interface(): void |
45
|
|
|
{ |
46
|
|
|
$this->shouldHaveType(ActionInterface::class); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
function it_implements_api_aware_interface(): void |
50
|
|
|
{ |
51
|
|
|
$this->shouldHaveType(ApiAwareInterface::class); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
function it_implements_gateway_aware_interface(): void |
55
|
|
|
{ |
56
|
|
|
$this->shouldHaveType(GatewayAwareInterface::class); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
function it_extends_base_api_aware(): void |
60
|
|
|
{ |
61
|
|
|
$this->shouldHaveType(BaseApiAwareAction::class); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
function it_executes( |
65
|
|
|
CreateSepaMandate $request, |
66
|
|
|
MollieApiClient $mollieApiClient, |
67
|
|
|
ArrayObject $arrayObject, |
68
|
|
|
GatewayInterface $gateway, |
69
|
|
|
SessionInterface $session, |
70
|
|
|
CustomerEndpoint $customerEndpoint, |
71
|
|
|
Customer $customer, |
72
|
|
|
Mandate $mandate |
73
|
|
|
): void { |
74
|
|
|
$this->setApi($mollieApiClient); |
|
|
|
|
75
|
|
|
$this->setGateway($gateway); |
|
|
|
|
76
|
|
|
$mollieApiClient->customers = $customerEndpoint; |
77
|
|
|
$mandate->id = 'id_1'; |
78
|
|
|
$customer->createMandate([ |
79
|
|
|
'consumerAccount' => '57357086404', |
80
|
|
|
'consumerName' => 'Example', |
81
|
|
|
'method' => 'directdebit', |
82
|
|
|
])->willReturn($mandate); |
|
|
|
|
83
|
|
|
$customerEndpoint->get('id_1')->willReturn($customer); |
|
|
|
|
84
|
|
|
$session->get('mollie_direct_debit_data', null)->willReturn([ |
85
|
|
|
'iban' => '57357086404', |
86
|
|
|
'consumerName' => 'Example', |
87
|
|
|
]); |
88
|
|
|
$arrayObject->offsetGet('customer_mollie_id')->willReturn('id_1'); |
89
|
|
|
$request->getModel()->willReturn($arrayObject); |
90
|
|
|
|
91
|
|
|
$arrayObject->offsetSet('mandate_mollie_id', 'id_1')->shouldBeCalled(); |
|
|
|
|
92
|
|
|
|
93
|
|
|
$this->execute($request); |
|
|
|
|
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
function it_supports_only_create_sepa_mandate_request_and_array_access( |
97
|
|
|
CreateSepaMandate $request, |
98
|
|
|
\ArrayAccess $arrayAccess |
99
|
|
|
): void { |
100
|
|
|
$request->getModel()->willReturn($arrayAccess); |
101
|
|
|
|
102
|
|
|
$this->supports($request)->shouldReturn(true); |
|
|
|
|
103
|
|
|
} |
104
|
|
|
} |
105
|
|
|
|
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.