Test Failed
Push — master ( e23a22...aeb0a0 )
by Francis
09:50
created

testSupports()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 21
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 14
nc 1
nop 0
dl 0
loc 21
rs 9.7998
c 1
b 0
f 0
1
<?php
2
3
namespace Tests\FluxSE\PayumStripe\Action\Api\WebhookEvent;
4
5
use FluxSE\PayumStripe\Action\Api\WebhookEvent\AbstractPaymentAction;
6
use FluxSE\PayumStripe\Action\Api\WebhookEvent\AbstractPaymentIntentAction;
7
use FluxSE\PayumStripe\Action\Api\WebhookEvent\AbstractWebhookEventAction;
8
use FluxSE\PayumStripe\Action\Api\WebhookEvent\PaymentIntentSucceededFromAuthorizeAction;
9
use FluxSE\PayumStripe\Request\Api\WebhookEvent\WebhookEvent;
10
use FluxSE\PayumStripe\Wrapper\EventWrapper;
11
use Payum\Core\Action\ActionInterface;
12
use Payum\Core\ApiAwareInterface;
13
use Payum\Core\GatewayAwareInterface;
14
use Payum\Core\Model\Token;
15
use Payum\Core\Request\GetToken;
16
use Payum\Core\Request\Notify;
17
use PHPUnit\Framework\TestCase;
18
use Stripe\Event;
19
use Tests\FluxSE\PayumStripe\Action\GatewayAwareTestTrait;
20
21
final class PaymentIntentSucceededFromAuthorizeActionTest extends TestCase
22
{
23
    use GatewayAwareTestTrait;
24
25
    public function testShouldImplements(): void
26
    {
27
        $action = new PaymentIntentSucceededFromAuthorizeAction();
28
29
        $this->assertNotInstanceOf(ApiAwareInterface::class, $action);
30
        $this->assertInstanceOf(ActionInterface::class, $action);
31
        $this->assertInstanceOf(GatewayAwareInterface::class, $action);
32
33
        $this->assertInstanceOf(AbstractPaymentIntentAction::class, $action);
34
        $this->assertInstanceOf(AbstractPaymentAction::class, $action);
35
        $this->assertInstanceOf(AbstractWebhookEventAction::class, $action);
36
    }
37
38
    public function provideNotSupportedModels(): array
39
    {
40
        return [
41
            [[
42
                'id' => 'event_1',
43
                'data' => [
44
                    'object' => [],
45
                ],
46
                'type' => Event::PAYMENT_INTENT_SUCCEEDED,
47
            ]],
48
            [[
49
                'id' => 'event_1',
50
                'data' => [
51
                    'object' => [
52
                        'metadata' => [
53
                            'token_hash' => 'test_hash',
54
                        ],
55
                    ],
56
                ],
57
                'type' => Event::PAYMENT_INTENT_SUCCEEDED,
58
            ]],
59
            [[
60
                'id' => 'event_1',
61
                'data' => [
62
                    'object' => [
63
                        'capture_method' => 'automatic',
64
                        'metadata' => [
65
                            'token_hash' => 'test_hash',
66
                        ],
67
                    ],
68
                ],
69
                'type' => Event::PAYMENT_INTENT_SUCCEEDED,
70
            ]],
71
        ];
72
    }
73
74
    /** @dataProvider provideNotSupportedModels */
75
    public function testDoNotSupports(array $model): void
76
    {
77
        $action = new PaymentIntentSucceededFromAuthorizeAction();
78
79
        $event = Event::constructFrom($model);
80
        $eventWrapper = new EventWrapper('', $event);
81
        $webhookEvent = new WebhookEvent($eventWrapper);
82
        $supports = $action->supports($webhookEvent);
83
        $this->assertFalse($supports);
84
    }
85
86
    public function testSupports(): void
87
    {
88
        $action = new PaymentIntentSucceededAction();
89
90
        $model = [
91
            'id' => 'event_1',
92
            'data' => [
93
                'object' => [
94
                    'capture_method' => 'manual',
95
                    'metadata' => [
96
                        'token_hash' => 'test_hash',
97
                    ],
98
                ],
99
            ],
100
            'type' => Event::PAYMENT_INTENT_SUCCEEDED,
101
        ];
102
        $event = Event::constructFrom($model);
103
        $eventWrapper = new EventWrapper('', $event);
104
        $webhookEvent = new WebhookEvent($eventWrapper);
105
        $supports = $action->supports($webhookEvent);
106
        $this->assertTrue($supports);
107
    }
108
109
    public function testShouldConsumeAWebhookEvent(): void
110
    {
111
        $model = [
112
            'id' => 'event_1',
113
            'data' => [
114
                'object' => [
115
                    'capture_method' => 'manual',
116
                    'metadata' => [
117
                        'token_hash' => 'test_hash',
118
                    ],
119
                ],
120
            ],
121
            'type' => Event::PAYMENT_INTENT_SUCCEEDED,
122
        ];
123
124
        $event = Event::constructFrom($model);
125
        $token = new Token();
126
127
        $gatewayMock = $this->createGatewayMock();
128
        $gatewayMock
129
            ->expects($this->exactly(2))
0 ignored issues
show
Bug introduced by
The method expects() does not exist on Payum\Core\GatewayInterface. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

129
            ->/** @scrutinizer ignore-call */ 
130
              expects($this->exactly(2))

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
130
            ->method('execute')
131
            ->withConsecutive(
132
                [$this->isInstanceOf(GetToken::class)],
133
                [$this->isInstanceOf(Notify::class)]
134
            )
135
            ->willReturnOnConsecutiveCalls(
136
                $this->returnCallback(function (GetToken $request) use ($token) {
137
                    $this->assertEquals('test_hash', $request->getHash());
138
                    $request->setToken($token);
139
                }),
140
                $this->returnCallback(function (Notify $request) use ($token) {
141
                    $this->assertEquals($token, $request->getToken());
142
                })
143
            );
144
145
        $action = new PaymentIntentSucceededFromAuthorizeAction();
146
        $action->setGateway($gatewayMock);
147
        $eventWrapper = new EventWrapper('', $event);
148
        $webhookEvent = new WebhookEvent($eventWrapper);
149
150
        $supports = $action->supports($webhookEvent);
151
        $this->assertTrue($supports);
152
153
        $action->execute($webhookEvent);
154
    }
155
}
156