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 ( fb8f78...f9a184 )
by Andreas
03:45
created

SyncCustomerConsumerTest::testConsumeCreate()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 37
Code Lines 27

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 27
nc 1
nop 0
dl 0
loc 37
rs 9.488
c 1
b 0
f 1
1
<?php
2
declare(strict_types=1);
3
/**
4
 */
5
6
namespace CommerceLeague\ActiveCampaign\Test\Unit\MessageQueue;
7
8
use CommerceLeague\ActiveCampaign\Api\CustomerRepositoryInterface;
9
use CommerceLeague\ActiveCampaign\Api\Data\CustomerInterface;
10
use CommerceLeague\ActiveCampaign\Helper\Client as ClientHelper;
11
use CommerceLeague\ActiveCampaign\Logger\Logger;
12
use CommerceLeague\ActiveCampaign\MessageQueue\SyncCustomerConsumer;
13
use CommerceLeague\ActiveCampaignApi\Api\CustomerApiResourceInterface;
14
use CommerceLeague\ActiveCampaignApi\Exception\HttpException;
15
use PHPUnit\Framework\MockObject\MockObject;
16
use PHPUnit\Framework\TestCase;
17
18
class SyncCustomerConsumerTest extends TestCase
19
{
20
    /**
21
     * @var MockObject|CustomerRepositoryInterface
22
     */
23
    protected $customerRepository;
24
25
    /**
26
     * @var MockObject|Logger
27
     */
28
    protected $logger;
29
30
    /**
31
     * @var MockObject|ClientHelper
32
     */
33
    protected $clientHelper;
34
35
    /**
36
     * @var MockObject|CustomerInterface
37
     */
38
    protected $customer;
39
40
    /**
41
     * @var MockObject|CustomerApiResourceInterface
42
     */
43
    protected $customerApi;
44
45
    /**
46
     * @var SyncCustomerConsumer
47
     */
48
    protected $syncCustomerConsumer;
49
50
    protected function setUp()
51
    {
52
        $this->customerRepository = $this->createMock(CustomerRepositoryInterface::class);
53
        $this->logger = $this->createMock(Logger::class);
54
        $this->clientHelper = $this->createMock(ClientHelper::class);
55
        $this->customer = $this->createMock(CustomerInterface::class);
56
        $this->customerApi = $this->createMock(CustomerApiResourceInterface::class);
57
58
        $this->syncCustomerConsumer = new SyncCustomerConsumer(
59
            $this->customerRepository,
60
            $this->logger,
61
            $this->clientHelper
62
        );
63
    }
64
65
    public function testConsumeApiResponseException()
66
    {
67
        $magentoCustomerId = 123;
68
69
        $this->customerRepository->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not exist on CommerceLeague\ActiveCam...omerRepositoryInterface. ( Ignorable by Annotation )

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

69
        $this->customerRepository->/** @scrutinizer ignore-call */ 
70
                                   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...
70
            ->method('getOrCreateByMagentoCustomerId')
71
            ->with($magentoCustomerId)
72
            ->willReturn($this->customer);
73
74
        $this->clientHelper->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not exist on CommerceLeague\ActiveCampaign\Helper\Client. ( Ignorable by Annotation )

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

74
        $this->clientHelper->/** @scrutinizer ignore-call */ 
75
                             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...
75
            ->method('getCustomerApi')
76
            ->willReturn($this->customerApi);
77
78
        /** @var MockObject|HttpException $httpException */
79
        $httpException = $this->createMock(HttpException::class);
80
81
        $this->customerApi->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not exist on CommerceLeague\ActiveCam...merApiResourceInterface. ( Ignorable by Annotation )

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

81
        $this->customerApi->/** @scrutinizer ignore-call */ 
82
                            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...
82
            ->method('create')
83
            ->with(['ecomCustomer' => []])
84
            ->willThrowException($httpException);
85
86
        $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

86
        $this->logger->/** @scrutinizer ignore-call */ 
87
                       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...
87
            ->method('error');
88
89
        $this->customer->expects($this->never())
0 ignored issues
show
Bug introduced by
The method expects() does not exist on CommerceLeague\ActiveCam...\Data\CustomerInterface. Since it exists in all sub-types, consider adding an abstract or default implementation to CommerceLeague\ActiveCam...\Data\CustomerInterface. ( Ignorable by Annotation )

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

89
        $this->customer->/** @scrutinizer ignore-call */ 
90
                         expects($this->never())
Loading history...
90
            ->method('setActiveCampaignId');
91
92
        $this->syncCustomerConsumer->consume(
93
            json_encode(['magento_customer_id' => $magentoCustomerId, 'request' => []])
94
        );
95
    }
96
97
    public function testConsumeUpdate()
98
    {
99
        $magentoCustomerId = 123;
100
        $activeCampaignId = 123;
101
        $response = [
102
            'ecomCustomer' => ['id' => $activeCampaignId]
103
        ];
104
105
        $this->customerRepository->expects($this->once())
106
            ->method('getOrCreateByMagentoCustomerId')
107
            ->with($magentoCustomerId)
108
            ->willReturn($this->customer);
109
110
        $this->clientHelper->expects($this->once())
111
            ->method('getCustomerApi')
112
            ->willReturn($this->customerApi);
113
114
        $this->customer->expects($this->once())
115
            ->method('getActiveCampaignId')
116
            ->willReturn($activeCampaignId);
117
118
        $this->customerApi->expects($this->once())
119
            ->method('update')
120
            ->with($activeCampaignId, ['ecomCustomer' => []])
121
            ->willReturn($response);
122
123
        $this->customer->expects($this->once())
124
            ->method('setActiveCampaignId')
125
            ->with($activeCampaignId)
126
            ->willReturnSelf();
127
128
        $this->customerRepository->expects($this->once())
129
            ->method('save')
130
            ->with($this->customer);
131
132
        $this->syncCustomerConsumer->consume(
133
            json_encode(['magento_customer_id' => $magentoCustomerId, 'request' => []])
134
        );
135
    }
136
137
    public function testConsumeCreate()
138
    {
139
        $magentoCustomerId = 123;
140
        $activeCampaignId = 123;
141
        $response = [
142
            'ecomCustomer' => ['id' => $activeCampaignId]
143
        ];
144
145
        $this->customerRepository->expects($this->once())
146
            ->method('getOrCreateByMagentoCustomerId')
147
            ->with($magentoCustomerId)
148
            ->willReturn($this->customer);
149
150
        $this->clientHelper->expects($this->once())
151
            ->method('getCustomerApi')
152
            ->willReturn($this->customerApi);
153
154
        $this->customer->expects($this->once())
155
            ->method('getActiveCampaignId')
156
            ->willReturn(null);
157
158
        $this->customerApi->expects($this->once())
159
            ->method('create')
160
            ->with(['ecomCustomer' => []])
161
            ->willReturn($response);
162
163
        $this->customer->expects($this->once())
164
            ->method('setActiveCampaignId')
165
            ->with($activeCampaignId)
166
            ->willReturnSelf();
167
168
        $this->customerRepository->expects($this->once())
169
            ->method('save')
170
            ->with($this->customer);
171
172
        $this->syncCustomerConsumer->consume(
173
            json_encode(['magento_customer_id' => $magentoCustomerId, 'request' => []])
174
        );
175
    }
176
}
177