GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( a4bd13...c92bdf )
by Andreas
03:29
created

testConsumeApiRequestException()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 43
Code Lines 30

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 30
c 1
b 0
f 1
nc 1
nop 0
dl 0
loc 43
rs 9.44
1
<?php
2
declare(strict_types=1);
3
/**
4
 */
5
6
namespace CommerceLeague\ActiveCampaign\Test\Unit\MessageQueue\Quote;
7
8
use CommerceLeague\ActiveCampaign\Api\Data\OrderInterface;
9
use CommerceLeague\ActiveCampaign\Api\OrderRepositoryInterface;
10
use CommerceLeague\ActiveCampaign\Gateway\Client;
11
use CommerceLeague\ActiveCampaign\Gateway\Request\AbandonedCartBuilder as AbandonedCartRequestBuilder;
12
use CommerceLeague\ActiveCampaign\Logger\Logger;
13
use CommerceLeague\ActiveCampaign\MessageQueue\Quote\ExportAbandonedCartConsumer;
14
use CommerceLeague\ActiveCampaignApi\Api\OrderApiResourceInterface;
15
use CommerceLeague\ActiveCampaignApi\Exception\HttpException;
16
use Magento\Quote\Model\Quote;
17
use PHPUnit\Framework\MockObject\MockObject;
18
use PHPUnit\Framework\TestCase;
19
use Magento\Quote\Model\QuoteFactory;
0 ignored issues
show
Bug introduced by
The type Magento\Quote\Model\QuoteFactory was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
20
21
class ExportAbandonedCartConsumerTest extends TestCase
22
{
23
    /**
24
     * @var MockObject|QuoteFactory
25
     */
26
    protected $quoteFactory;
27
28
    /**
29
     * @var MockObject|Quote
30
     */
31
    protected $quote;
32
33
    /**
34
     * @var MockObject|Logger
35
     */
36
    protected $logger;
37
38
    /**
39
     * @var MockObject|OrderRepositoryInterface
40
     */
41
    protected $orderRepository;
42
43
    /**
44
     * @var MockObject|AbandonedCartRequestBuilder
45
     */
46
    protected $abandonedCartRequestBuilder;
47
48
    /**
49
     * @var MockObject|Client
50
     */
51
    protected $client;
52
53
    /**
54
     * @var MockObject|OrderApiResourceInterface
55
     */
56
    protected $orderApi;
57
58
    /**
59
     * @var MockObject|OrderInterface
60
     */
61
    protected $order;
62
63
    /**
64
     * @var ExportAbandonedCartConsumer
65
     */
66
    protected $exportAbandonedCartConsumer;
67
68
    protected function setUp()
69
    {
70
        $this->quoteFactory = $this->getMockBuilder(QuoteFactory::class)
71
            ->disableOriginalConstructor()
72
            ->setMethods(['create'])
73
            ->getMock();
74
75
        $this->quote = $this->createMock(Quote::class);
76
77
        $this->quoteFactory->expects($this->any())
78
            ->method('create')
79
            ->willReturn($this->quote);
80
81
        $this->logger = $this->createMock(Logger::class);
82
        $this->orderRepository = $this->createMock(OrderRepositoryInterface::class);
83
        $this->abandonedCartRequestBuilder = $this->createMock(AbandonedCartRequestBuilder::class);
84
        $this->client = $this->createMock(Client::class);
85
        $this->orderApi = $this->createMock(OrderApiResourceInterface::class);
86
        $this->order = $this->createMock(OrderInterface::class);
87
88
        $this->exportAbandonedCartConsumer = new ExportAbandonedCartConsumer(
89
            $this->quoteFactory,
90
            $this->logger,
91
            $this->orderRepository,
92
            $this->abandonedCartRequestBuilder,
93
            $this->client
94
        );
95
    }
96
97
    public function testConsumeWithAbsentQuote()
98
    {
99
        $quoteId = 123;
100
101
        $this->quote->expects($this->once())
102
            ->method('loadByIdWithoutStore')
0 ignored issues
show
Bug introduced by
The method method() does not exist on PHPUnit\Framework\MockObject\MockObject. ( Ignorable by Annotation )

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

102
            ->/** @scrutinizer ignore-call */ method('loadByIdWithoutStore')

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...
103
            ->with(123)
0 ignored issues
show
Bug introduced by
The method with() does not exist on PHPUnit\Framework\MockObject\MockObject. ( Ignorable by Annotation )

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

103
            ->/** @scrutinizer ignore-call */ with(123)

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...
104
            ->willReturn($this->quote);
0 ignored issues
show
Bug introduced by
The method willReturn() does not exist on PHPUnit\Framework\MockObject\MockObject. ( Ignorable by Annotation )

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

104
            ->/** @scrutinizer ignore-call */ willReturn($this->quote);

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...
105
106
        $this->quote->expects($this->once())
107
            ->method('getId')
108
            ->willReturn(null);
109
110
        $this->logger->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not exist on CommerceLeague\ActiveCampaign\Logger\Logger. ( Ignorable by Annotation )

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

110
        $this->logger->/** @scrutinizer ignore-call */ 
111
                       expects($this->once())

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...
111
            ->method('error')
112
            ->with(__('The Quote with the "%1" ID doesn\'t exist', $quoteId));
113
114
        $this->orderRepository->expects($this->never())
0 ignored issues
show
Bug introduced by
The method expects() does not exist on CommerceLeague\ActiveCam...rderRepositoryInterface. ( Ignorable by Annotation )

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

114
        $this->orderRepository->/** @scrutinizer ignore-call */ 
115
                                expects($this->never())

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...
115
            ->method('getOrCreateByMagentoQuoteId');
116
117
        $this->exportAbandonedCartConsumer->consume(
118
            json_encode(['quote_id' => $quoteId])
119
        );
120
    }
121
122
    public function testConsumeApiRequestException()
123
    {
124
        $quoteId = 123;
125
        $request = ['request'];
126
127
        $this->quote->expects($this->once())
128
            ->method('loadByIdWithoutStore')
129
            ->with(123)
130
            ->willReturn($this->quote);
131
132
        $this->quote->expects($this->any())
133
            ->method('getId')
134
            ->willReturn($quoteId);
135
136
        $this->orderRepository->expects($this->once())
137
            ->method('getOrCreateByMagentoQuoteId')
138
            ->with($quoteId)
139
            ->willReturn($this->order);
140
141
        $this->abandonedCartRequestBuilder->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not exist on CommerceLeague\ActiveCam...st\AbandonedCartBuilder. ( Ignorable by Annotation )

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

141
        $this->abandonedCartRequestBuilder->/** @scrutinizer ignore-call */ 
142
                                            expects($this->once())

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...
142
            ->method('build')
143
            ->with($this->quote)
144
            ->willReturn($request);
145
146
        $this->client->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not exist on CommerceLeague\ActiveCampaign\Gateway\Client. ( Ignorable by Annotation )

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

146
        $this->client->/** @scrutinizer ignore-call */ 
147
                       expects($this->once())

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...
147
            ->method('getOrderApi')
148
            ->willReturn($this->orderApi);
149
150
        /** @var MockObject|HttpException $httpException */
151
        $httpException = $this->createMock(HttpException::class);
152
153
        $this->orderApi->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not exist on CommerceLeague\ActiveCam...derApiResourceInterface. ( Ignorable by Annotation )

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

153
        $this->orderApi->/** @scrutinizer ignore-call */ 
154
                         expects($this->once())

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...
154
            ->method('create')
155
            ->with(['ecomOrder' => $request])
156
            ->willThrowException($httpException);
157
158
        $this->logger->expects($this->once())
159
            ->method('error');
160
161
        $this->order->expects($this->never())
0 ignored issues
show
Bug introduced by
The method expects() does not exist on CommerceLeague\ActiveCam...Api\Data\OrderInterface. Since it exists in all sub-types, consider adding an abstract or default implementation to CommerceLeague\ActiveCam...Api\Data\OrderInterface. ( Ignorable by Annotation )

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

161
        $this->order->/** @scrutinizer ignore-call */ 
162
                      expects($this->never())
Loading history...
162
            ->method('setActiveCampaignId');
163
164
        $this->exportAbandonedCartConsumer->consume(json_encode(['quote_id' => $quoteId]));
165
    }
166
167
    public function testConsume()
168
    {
169
        $quoteId = 123;
170
        $request = ['request'];
171
        $activeCampaignId = 789;
172
        $response = ['ecomOrder' => ['id' => $activeCampaignId]];
173
174
        $this->quote->expects($this->once())
175
            ->method('loadByIdWithoutStore')
176
            ->with(123)
177
            ->willReturn($this->quote);
178
179
        $this->quote->expects($this->any())
180
            ->method('getId')
181
            ->willReturn($quoteId);
182
183
        $this->orderRepository->expects($this->once())
184
            ->method('getOrCreateByMagentoQuoteId')
185
            ->with($quoteId)
186
            ->willReturn($this->order);
187
188
        $this->abandonedCartRequestBuilder->expects($this->once())
189
            ->method('build')
190
            ->with($this->quote)
191
            ->willReturn($request);
192
193
        $this->client->expects($this->once())
194
            ->method('getOrderApi')
195
            ->willReturn($this->orderApi);
196
197
        $this->orderApi->expects($this->once())
198
            ->method('create')
199
            ->with(['ecomOrder' => $request])
200
            ->willReturn($response);
201
202
        $this->order->expects($this->once())
203
            ->method('setActiveCampaignId')
204
            ->with($activeCampaignId)
205
            ->willReturnSelf();
206
207
        $this->orderRepository->expects($this->once())
208
            ->method('save')
209
            ->with($this->order);
210
211
        $this->exportAbandonedCartConsumer->consume(json_encode(['quote_id' => $quoteId]));
212
    }
213
}
214