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.
Passed
Push — master ( 08f33b...54b06f )
by Andreas
03:24
created

testDeleteThrowsException()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 7
c 1
b 0
f 1
nc 1
nop 0
dl 0
loc 11
rs 10
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\Framework\Exception\CouldNotDeleteException;
10
use Magento\Framework\Exception\CouldNotSaveException;
11
use Magento\Framework\Exception\NoSuchEntityException;
12
use Magento\Newsletter\Model\Subscriber;
13
use PHPUnit\Framework\MockObject\MockObject;
14
use PHPUnit\Framework\TestCase;
15
use CommerceLeague\ActiveCampaign\Model\ResourceModel\Customer as CustomerResource;
16
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...
17
18
class CustomerRepositoryTest extends TestCase
19
{
20
    /**
21
     * @var MockObject|CustomerResource
22
     */
23
    protected $customerResource;
24
25
    /**
26
     * @var MockObject|Customer
27
     */
28
    protected $customer;
29
30
    /**
31
     * @var MockObject|CustomerFactory
32
     */
33
    protected $customerFactory;
34
35
    /**
36
     * @var CustomerRepository
37
     */
38
    protected $customerRepository;
39
40
    protected function setUp()
41
    {
42
        $this->customerResource = $this->getMockBuilder(CustomerResource::class)
43
            ->disableOriginalConstructor()
44
            ->getMock();
45
46
        $this->customerFactory = $this->getMockBuilder(CustomerFactory::class)
47
            ->disableOriginalConstructor()
48
            ->setMethods(['create'])
49
            ->getMock();
50
51
        $this->customer = $this->getMockBuilder(Customer::class)
52
            ->disableOriginalConstructor()
53
            ->getMock();
54
55
        $this->customerFactory->expects($this->any())
56
            ->method('create')
57
            ->willReturn($this->customer);
58
59
        $this->customerRepository = new CustomerRepository(
60
            $this->customerResource,
61
            $this->customerFactory
62
        );
63
    }
64
65
    public function testSaveThrowsException()
66
    {
67
        $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

67
        $this->customerResource->/** @scrutinizer ignore-call */ 
68
                                 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...
68
            ->method('save')
69
            ->with($this->customer)
70
            ->willThrowException(new \Exception('an exception message'));
71
72
        $this->expectException(CouldNotSaveException::class);
73
        $this->expectExceptionMessage('an exception message');
74
75
        $this->customerRepository->save($this->customer);
76
    }
77
78
    public function testSave()
79
    {
80
        $this->customerResource->expects($this->once())
81
            ->method('save')
82
            ->with($this->customer)
83
            ->willReturnSelf();
84
85
        $this->assertEquals($this->customer, $this->customerRepository->save($this->customer));
86
    }
87
88
    public function testGetById()
89
    {
90
        $entityId = 123;
91
        $this->assertEquals($this->customer, $this->customerRepository->getById($entityId));
92
    }
93
94
    public function testGetByEmail()
95
    {
96
        $email = '[email protected]';
97
        $this->assertEquals($this->customer, $this->customerRepository->getByEmail($email));
98
    }
99
100
    public function testDeleteThrowsException()
101
    {
102
        $this->customerResource->expects($this->once())
103
            ->method('delete')
104
            ->with($this->customer)
105
            ->willThrowException(new \Exception('an exception message'));
106
107
        $this->expectException(CouldNotDeleteException::class);
108
        $this->expectExceptionMessage('an exception message');
109
110
        $this->customerRepository->delete($this->customer);
111
    }
112
113
    public function testDelete()
114
    {
115
        $this->customerResource->expects($this->once())
116
            ->method('delete')
117
            ->with($this->customer)
118
            ->willReturnSelf();
119
120
        $this->assertTrue($this->customerRepository->delete($this->customer));
121
    }
122
123
    public function testDeleteByIdThrowsException()
124
    {
125
        $entityId = 123;
126
127
        $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

127
        $this->customer->/** @scrutinizer ignore-call */ 
128
                         expects($this->once())
Loading history...
128
            ->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

128
            ->/** @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...
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

128
            ->/** @scrutinizer ignore-call */ method('getId')
Loading history...
129
            ->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

129
            ->/** @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...
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

129
            ->/** @scrutinizer ignore-call */ willReturn(null);
Loading history...
130
131
        $this->customerResource->expects($this->once())
132
            ->method('load')
133
            ->with($this->customer, $entityId)
134
            ->willReturn($this->customer);
135
136
        $this->customerResource->expects($this->never())
137
            ->method('delete');
138
139
        $this->expectException(NoSuchEntityException::class);
140
        $this->expectExceptionMessage('The Customer with the "123" ID doesn\'t exist');
141
142
        $this->customerRepository->deleteById($entityId);
143
    }
144
145
    public function testDeleteById()
146
    {
147
        $entityId = 123;
148
149
        $this->customer->expects($this->once())
150
            ->method('getId')
151
            ->willReturn($entityId);
152
153
        $this->customerResource->expects($this->once())
154
            ->method('load')
155
            ->with($this->customer, $entityId)
156
            ->willReturn($this->customer);
157
158
        $this->customerResource->expects($this->once())
159
            ->method('delete')
160
            ->with($this->customer)
161
            ->willReturnSelf();
162
163
        $this->assertTrue($this->customerRepository->deleteById($entityId));
164
    }
165
}
166