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 ( 54b06f...c3352e )
by Andreas
05:28 queued 25s
created

CustomerRepositoryTest::testGetByMagentoCustomer()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 9
nc 1
nop 0
dl 0
loc 14
rs 9.9666
c 0
b 0
f 0
1
<?php
2
/**
3
 */
4
5
namespace CommerceLeague\ActiveCampaign\Test\Unit\Model;
6
7
use CommerceLeague\ActiveCampaign\Model\Customer;
8
use CommerceLeague\ActiveCampaign\Model\CustomerRepository;
9
use Magento\Customer\Model\Customer as MagentoCustomer;
10
use Magento\Framework\Exception\CouldNotDeleteException;
11
use Magento\Framework\Exception\CouldNotSaveException;
12
use Magento\Framework\Exception\NoSuchEntityException;
13
use Magento\Newsletter\Model\Subscriber;
14
use PHPUnit\Framework\MockObject\MockObject;
15
use PHPUnit\Framework\TestCase;
16
use CommerceLeague\ActiveCampaign\Model\ResourceModel\Customer as CustomerResource;
17
use CommerceLeague\ActiveCampaign\Model\CustomerFactory;
0 ignored issues
show
Bug introduced by
The type CommerceLeague\ActiveCam...n\Model\CustomerFactory 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...
18
19
class CustomerRepositoryTest extends TestCase
20
{
21
    /**
22
     * @var MockObject|CustomerResource
23
     */
24
    protected $customerResource;
25
26
    /**
27
     * @var MockObject|Customer
28
     */
29
    protected $customer;
30
31
    /**
32
     * @var MockObject|CustomerFactory
33
     */
34
    protected $customerFactory;
35
36
    /**
37
     * @var MockObject|MagentoCustomer
38
     */
39
    protected $magentoCustomer;
40
41
    /**
42
     * @var CustomerRepository
43
     */
44
    protected $customerRepository;
45
46
    protected function setUp()
47
    {
48
        $this->customerResource = $this->getMockBuilder(CustomerResource::class)
49
            ->disableOriginalConstructor()
50
            ->getMock();
51
52
        $this->customerFactory = $this->getMockBuilder(CustomerFactory::class)
53
            ->disableOriginalConstructor()
54
            ->setMethods(['create'])
55
            ->getMock();
56
57
        $this->customer = $this->getMockBuilder(Customer::class)
58
            ->disableOriginalConstructor()
59
            ->getMock();
60
61
        $this->customerFactory->expects($this->any())
62
            ->method('create')
63
            ->willReturn($this->customer);
64
65
        $this->magentoCustomer = $this->getMockBuilder(MagentoCustomer::class)
66
            ->disableOriginalConstructor()
67
            ->getMock();
68
69
        $this->customerRepository = new CustomerRepository(
70
            $this->customerResource,
71
            $this->customerFactory
72
        );
73
    }
74
75
    public function testSaveThrowsException()
76
    {
77
        $this->customerResource->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not exist on CommerceLeague\ActiveCam...\ResourceModel\Customer. ( Ignorable by Annotation )

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

77
        $this->customerResource->/** @scrutinizer ignore-call */ 
78
                                 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...
78
            ->method('save')
79
            ->with($this->customer)
80
            ->willThrowException(new \Exception('an exception message'));
81
82
        $this->expectException(CouldNotSaveException::class);
83
        $this->expectExceptionMessage('an exception message');
84
85
        $this->customerRepository->save($this->customer);
86
    }
87
88
    public function testSave()
89
    {
90
        $this->customerResource->expects($this->once())
91
            ->method('save')
92
            ->with($this->customer)
93
            ->willReturnSelf();
94
95
        $this->assertEquals($this->customer, $this->customerRepository->save($this->customer));
96
    }
97
98
    public function testGetById()
99
    {
100
        $entityId = 123;
101
        $this->assertEquals($this->customer, $this->customerRepository->getById($entityId));
102
    }
103
104
    public function testGetByMagentoCustomerWithUnknownMagentoCustomer()
105
    {
106
        $this->magentoCustomer->expects($this->once())
107
            ->method('getId')
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

107
            ->/** @scrutinizer ignore-call */ method('getId')

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...
108
            ->willReturn(null);
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

108
            ->/** @scrutinizer ignore-call */ willReturn(null);

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...
109
110
        $this->customerResource->expects($this->once())
111
            ->method('load')
112
            ->with($this->customer, null, 'magento_customer_id')
113
            ->willReturn($this->customer);
114
115
        $this->assertSame($this->customer, $this->customerRepository->getByMagentoCustomer($this->magentoCustomer));
116
    }
117
118
    public function testGetByMagentoCustomer()
119
    {
120
        $magentoCustomerId = 123;
121
122
        $this->magentoCustomer->expects($this->once())
123
            ->method('getId')
124
            ->willReturn($magentoCustomerId);
125
126
        $this->customerResource->expects($this->once())
127
            ->method('load')
128
            ->with($this->customer, $magentoCustomerId, 'magento_customer_id')
129
            ->willReturn($this->customer);
130
131
        $this->assertSame($this->customer, $this->customerRepository->getByMagentoCustomer($this->magentoCustomer));
132
    }
133
134
    public function testGetOrCreateByMagentoCustomerCreatesCustomer()
135
    {
136
        $magentoCustomerId = 123;
137
138
        $this->magentoCustomer->expects($this->any())
139
            ->method('getId')
140
            ->willReturn($magentoCustomerId);
141
142
        $this->customerResource->expects($this->once())
143
            ->method('load')
144
            ->with($this->customer, $magentoCustomerId, 'magento_customer_id')
145
            ->willReturn($this->customer);
146
147
        $this->customer->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not exist on CommerceLeague\ActiveCampaign\Model\Customer. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

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

147
        $this->customer->/** @scrutinizer ignore-call */ 
148
                         expects($this->once())
Loading history...
148
            ->method('getId')
0 ignored issues
show
Bug introduced by
The method method() does not exist on CommerceLeague\ActiveCampaign\Model\Customer. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

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

148
            ->/** @scrutinizer ignore-call */ method('getId')
Loading history...
149
            ->willReturn(null);
0 ignored issues
show
Bug introduced by
The method willReturn() does not exist on CommerceLeague\ActiveCampaign\Model\Customer. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

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

149
            ->/** @scrutinizer ignore-call */ willReturn(null);
Loading history...
150
151
        $this->customer->expects($this->once())
152
            ->method('setMagentoCustomerId')
153
            ->with($magentoCustomerId)
0 ignored issues
show
Bug introduced by
The method with() does not exist on CommerceLeague\ActiveCampaign\Model\Customer. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

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

153
            ->/** @scrutinizer ignore-call */ with($magentoCustomerId)
Loading history...
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

153
            ->/** @scrutinizer ignore-call */ with($magentoCustomerId)

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
            ->willReturnSelf();
0 ignored issues
show
Bug introduced by
The method willReturnSelf() 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

154
            ->/** @scrutinizer ignore-call */ willReturnSelf();

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...
Bug introduced by
The method willReturnSelf() does not exist on CommerceLeague\ActiveCampaign\Model\Customer. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

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

154
            ->/** @scrutinizer ignore-call */ willReturnSelf();
Loading history...
155
156
        $this->customerResource->expects($this->once())
157
            ->method('save')
158
            ->with($this->customer)
159
            ->willReturnSelf();
160
161
        $this->assertSame(
162
            $this->customer,
163
            $this->customerRepository->getOrCreateByMagentoCustomer($this->magentoCustomer)
164
        );
165
    }
166
167
    public function testGetOrCreateByMagentoCustomerLoadsCustomer()
168
    {
169
        $entityId = 678;
170
        $magentoCustomerId = 123;
171
172
        $this->magentoCustomer->expects($this->any())
173
            ->method('getId')
174
            ->willReturn($magentoCustomerId);
175
176
        $this->customerResource->expects($this->once())
177
            ->method('load')
178
            ->with($this->customer, $magentoCustomerId, 'magento_customer_id')
179
            ->willReturn($this->customer);
180
181
        $this->customer->expects($this->once())
182
            ->method('getId')
183
            ->willReturn($entityId);
184
185
        $this->customer->expects($this->never())
186
            ->method('setMagentoCustomerId');
187
188
        $this->customerResource->expects($this->never())
189
            ->method('save');
190
191
        $this->assertSame(
192
            $this->customer,
193
            $this->customerRepository->getOrCreateByMagentoCustomer($this->magentoCustomer)
194
        );
195
    }
196
197
    public function testDeleteThrowsException()
198
    {
199
        $this->customerResource->expects($this->once())
200
            ->method('delete')
201
            ->with($this->customer)
202
            ->willThrowException(new \Exception('an exception message'));
203
204
        $this->expectException(CouldNotDeleteException::class);
205
        $this->expectExceptionMessage('an exception message');
206
207
        $this->customerRepository->delete($this->customer);
208
    }
209
210
    public function testDelete()
211
    {
212
        $this->customerResource->expects($this->once())
213
            ->method('delete')
214
            ->with($this->customer)
215
            ->willReturnSelf();
216
217
        $this->assertTrue($this->customerRepository->delete($this->customer));
218
    }
219
220
    public function testDeleteByIdThrowsException()
221
    {
222
        $entityId = 123;
223
224
        $this->customer->expects($this->once())
225
            ->method('getId')
226
            ->willReturn(null);
227
228
        $this->customerResource->expects($this->once())
229
            ->method('load')
230
            ->with($this->customer, $entityId)
231
            ->willReturn($this->customer);
232
233
        $this->customerResource->expects($this->never())
234
            ->method('delete');
235
236
        $this->expectException(NoSuchEntityException::class);
237
        $this->expectExceptionMessage('The Customer with the "123" ID doesn\'t exist');
238
239
        $this->customerRepository->deleteById($entityId);
240
    }
241
242
    public function testDeleteById()
243
    {
244
        $entityId = 123;
245
246
        $this->customer->expects($this->once())
247
            ->method('getId')
248
            ->willReturn($entityId);
249
250
        $this->customerResource->expects($this->once())
251
            ->method('load')
252
            ->with($this->customer, $entityId)
253
            ->willReturn($this->customer);
254
255
        $this->customerResource->expects($this->once())
256
            ->method('delete')
257
            ->with($this->customer)
258
            ->willReturnSelf();
259
260
        $this->assertTrue($this->customerRepository->deleteById($entityId));
261
    }
262
}
263