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.

Issues (203)

Model/ActiveCampaign/CustomerRepositoryTest.php (11 issues)

Labels
Severity
1
<?php
2
/**
3
 */
4
5
namespace CommerceLeague\ActiveCampaign\Test\Unit\Model\ActiveCampaign;
6
7
use CommerceLeague\ActiveCampaign\Api\Data\CustomerInterface;
8
use CommerceLeague\ActiveCampaign\Model\ActiveCampaign\Customer;
9
use CommerceLeague\ActiveCampaign\Model\ActiveCampaign\CustomerRepository;
10
use Magento\Customer\Model\Customer as MagentoCustomer;
11
use Magento\Framework\Exception\CouldNotDeleteException;
12
use Magento\Framework\Exception\CouldNotSaveException;
13
use Magento\Framework\Exception\NoSuchEntityException;
14
use PHPUnit\Framework\MockObject\MockObject;
15
use PHPUnit\Framework\TestCase;
16
use CommerceLeague\ActiveCampaign\Model\ResourceModel\ActiveCampaign\Customer as CustomerResource;
17
use CommerceLeague\ActiveCampaign\Model\ActiveCampaign\CustomerFactory;
0 ignored issues
show
The type CommerceLeague\ActiveCam...ampaign\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
The method expects() does not exist on CommerceLeague\ActiveCam...ActiveCampaign\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->assertSame($this->customer, $this->customerRepository->save($this->customer));
96
    }
97
98
    public function testGetById()
99
    {
100
        $entityId = 123;
101
102
        $this->customerResource->expects($this->once())
103
            ->method('load')
104
            ->with($this->customer, $entityId)
105
            ->willReturn($this->customer);
106
107
        $this->assertSame($this->customer, $this->customerRepository->getById($entityId));
108
    }
109
110
    public function testGetByMagentoCustomerId()
111
    {
112
        $magentoCustomerId = 123;
113
114
        $this->customerResource->expects($this->once())
115
            ->method('load')
116
            ->with($this->customer, $magentoCustomerId, CustomerInterface::MAGENTO_CUSTOMER_ID)
117
            ->willReturn($this->customer);
118
119
        $this->assertSame($this->customer, $this->customerRepository->getByMagentoCustomerId($magentoCustomerId));
120
    }
121
122
    public function testGetOrCreateByMagentoCustomerIdWithKnownMagentoCustomer()
123
    {
124
        $magentoCustomerId = 123;
125
126
        $this->customerResource->expects($this->once())
127
            ->method('load')
128
            ->with($this->customer, $magentoCustomerId, CustomerInterface::MAGENTO_CUSTOMER_ID)
129
            ->willReturn($this->customer);
130
131
        $this->customer->expects($this->once())
0 ignored issues
show
The method expects() does not exist on CommerceLeague\ActiveCam...ActiveCampaign\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

131
        $this->customer->/** @scrutinizer ignore-call */ 
132
                         expects($this->once())
Loading history...
132
            ->method('getId')
0 ignored issues
show
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

132
            ->/** @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...
The method method() does not exist on CommerceLeague\ActiveCam...ActiveCampaign\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

132
            ->/** @scrutinizer ignore-call */ method('getId')
Loading history...
133
            ->willReturn(123);
0 ignored issues
show
The method willReturn() does not exist on CommerceLeague\ActiveCam...ActiveCampaign\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

133
            ->/** @scrutinizer ignore-call */ willReturn(123);
Loading history...
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

133
            ->/** @scrutinizer ignore-call */ willReturn(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...
134
135
        $this->customer->expects($this->never())
136
            ->method('setMagentoCustomerId');
137
138
        $this->assertSame($this->customer, $this->customerRepository->getOrCreateByMagentoCustomerId($magentoCustomerId));
139
    }
140
141
    public function testGetOrCreateByMagentoCustomerId()
142
    {
143
        $magentoCustomerId = 123;
144
145
        $this->customerResource->expects($this->once())
146
            ->method('load')
147
            ->with($this->customer, $magentoCustomerId, CustomerInterface::MAGENTO_CUSTOMER_ID)
148
            ->willReturn($this->customer);
149
150
        $this->customer->expects($this->once())
151
            ->method('getId')
152
            ->willReturn(null);
153
154
        $this->customer->expects($this->once())
155
            ->method('setMagentoCustomerId')
156
            ->with($magentoCustomerId)
0 ignored issues
show
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

156
            ->/** @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...
The method with() does not exist on CommerceLeague\ActiveCam...ActiveCampaign\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

156
            ->/** @scrutinizer ignore-call */ with($magentoCustomerId)
Loading history...
157
            ->willReturnSelf();
0 ignored issues
show
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

157
            ->/** @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...
The method willReturnSelf() does not exist on CommerceLeague\ActiveCam...ActiveCampaign\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

157
            ->/** @scrutinizer ignore-call */ willReturnSelf();
Loading history...
158
159
        $this->customerResource->expects($this->once())
160
            ->method('save')
161
            ->with($this->customer)
162
            ->willReturn($this->customer);
163
164
        $this->assertSame($this->customer, $this->customerRepository->getOrCreateByMagentoCustomerId($magentoCustomerId));
165
    }
166
167
    public function testDeleteThrowsException()
168
    {
169
        $this->customerResource->expects($this->once())
170
            ->method('delete')
171
            ->with($this->customer)
172
            ->willThrowException(new \Exception('an exception message'));
173
174
        $this->expectException(CouldNotDeleteException::class);
175
        $this->expectExceptionMessage('an exception message');
176
177
        $this->customerRepository->delete($this->customer);
178
    }
179
180
    public function testDelete()
181
    {
182
        $this->customerResource->expects($this->once())
183
            ->method('delete')
184
            ->with($this->customer)
185
            ->willReturnSelf();
186
187
        $this->assertTrue($this->customerRepository->delete($this->customer));
188
    }
189
190
    public function testDeleteByIdThrowsException()
191
    {
192
        $entityId = 123;
193
194
        $this->customer->expects($this->once())
195
            ->method('getId')
196
            ->willReturn(null);
197
198
        $this->customerResource->expects($this->once())
199
            ->method('load')
200
            ->with($this->customer, $entityId)
201
            ->willReturn($this->customer);
202
203
        $this->customerResource->expects($this->never())
204
            ->method('delete');
205
206
        $this->expectException(NoSuchEntityException::class);
207
        $this->expectExceptionMessage('The Customer with the "123" ID doesn\'t exist');
208
209
        $this->customerRepository->deleteById($entityId);
210
    }
211
212
    public function testDeleteById()
213
    {
214
        $entityId = 123;
215
216
        $this->customer->expects($this->once())
217
            ->method('getId')
218
            ->willReturn($entityId);
219
220
        $this->customerResource->expects($this->once())
221
            ->method('load')
222
            ->with($this->customer, $entityId)
223
            ->willReturn($this->customer);
224
225
        $this->customerResource->expects($this->once())
226
            ->method('delete')
227
            ->with($this->customer)
228
            ->willReturnSelf();
229
230
        $this->assertTrue($this->customerRepository->deleteById($entityId));
231
    }
232
}
233