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 ( ea09f8...f51f95 )
by Andreas
03:33
created

AbandonedRepositoryTest::setUp()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 22
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 16
c 1
b 0
f 1
nc 1
nop 0
dl 0
loc 22
rs 9.7333
1
<?php
2
declare(strict_types=1);
3
/**
4
 */
5
6
namespace CommerceLeague\ActiveCampaign\Test\Unit\Model;
7
8
use CommerceLeague\ActiveCampaign\Api\Data\AbandonedInterface;
9
use CommerceLeague\ActiveCampaign\Model\AbandonedRepository;
10
use CommerceLeague\ActiveCampaign\Model\ResourceModel\Abandoned as AbandonedResource;
11
use CommerceLeague\ActiveCampaign\Model\AbandonedFactory as AbandonedFactory;
0 ignored issues
show
Bug introduced by
The type CommerceLeague\ActiveCam...\Model\AbandonedFactory 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...
12
use CommerceLeague\ActiveCampaign\Model\Abandoned;
13
use Magento\Framework\Exception\CouldNotDeleteException;
14
use Magento\Framework\Exception\CouldNotSaveException;
15
use Magento\Framework\Exception\NoSuchEntityException;
16
use PHPUnit\Framework\MockObject\MockObject;
17
use PHPUnit\Framework\TestCase;
18
19
class AbandonedRepositoryTest extends TestCase
20
{
21
    /**
22
     * @var MockObject|AbandonedResource
23
     */
24
    protected $abandonedResource;
25
26
    /**
27
     * @var MockObject|AbandonedFactory
28
     */
29
    protected $abandonedFactory;
30
31
    /**
32
     * @var MockObject|Abandoned
33
     */
34
    protected $abandoned;
35
36
    /**
37
     * @var AbandonedRepository
38
     */
39
    protected $abandonedRepository;
40
41
    protected function setUp()
42
    {
43
        $this->abandonedResource = $this->getMockBuilder(AbandonedResource::class)
44
            ->disableOriginalConstructor()
45
            ->getMock();
46
47
        $this->abandonedFactory = $this->getMockBuilder(AbandonedFactory::class)
48
            ->disableOriginalConstructor()
49
            ->setMethods(['create'])
50
            ->getMock();
51
52
        $this->abandoned = $this->getMockBuilder(Abandoned::class)
53
            ->disableOriginalConstructor()
54
            ->getMock();
55
56
        $this->abandonedFactory->expects($this->any())
57
            ->method('create')
58
            ->willReturn($this->abandoned);
59
60
        $this->abandonedRepository = new AbandonedRepository(
61
            $this->abandonedResource,
62
            $this->abandonedFactory
63
        );
64
    }
65
66
    public function testSaveThrowsException()
67
    {
68
        $this->abandonedResource->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not exist on CommerceLeague\ActiveCam...ResourceModel\Abandoned. ( Ignorable by Annotation )

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

68
        $this->abandonedResource->/** @scrutinizer ignore-call */ 
69
                                  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...
69
            ->method('save')
70
            ->with($this->abandoned)
71
            ->willThrowException(new \Exception('an exception message'));
72
73
        $this->expectException(CouldNotSaveException::class);
74
        $this->expectExceptionMessage('an exception message');
75
76
        $this->abandonedRepository->save($this->abandoned);
77
    }
78
79
    public function testSave()
80
    {
81
        $this->abandonedResource->expects($this->once())
82
            ->method('save')
83
            ->with($this->abandoned)
84
            ->willReturnSelf();
85
86
        $this->assertSame($this->abandoned, $this->abandonedRepository->save($this->abandoned));
87
    }
88
89
    public function testGetById()
90
    {
91
        $entityId = 123;
92
93
        $this->abandonedResource->expects($this->once())
94
            ->method('load')
95
            ->with($this->abandoned, $entityId)
96
            ->willReturn($this->abandoned);
97
98
        $this->assertSame($this->abandoned, $this->abandonedRepository->getById($entityId));
99
    }
100
101
    public function testGetByQuoteId()
102
    {
103
        $quoteId = 123;
104
105
        $this->abandonedResource->expects($this->once())
106
            ->method('load')
107
            ->with($this->abandoned, $quoteId, AbandonedInterface::QUOTE_ID)
108
            ->willReturn($this->abandoned);
109
110
        $this->assertSame($this->abandoned, $this->abandonedRepository->getByQuoteId($quoteId));
111
    }
112
113
    public function testGetOrCreateByQuoteIdWithKnownQuote()
114
    {
115
        $quoteId = 123;
116
117
        $this->abandonedResource->expects($this->once())
118
            ->method('load')
119
            ->with($this->abandoned, $quoteId, AbandonedInterface::QUOTE_ID)
120
            ->willReturn($this->abandoned);
121
122
        $this->abandoned->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not exist on CommerceLeague\ActiveCampaign\Model\Abandoned. 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

122
        $this->abandoned->/** @scrutinizer ignore-call */ 
123
                          expects($this->once())
Loading history...
123
            ->method('getId')
0 ignored issues
show
Bug introduced by
The method method() does not exist on CommerceLeague\ActiveCampaign\Model\Abandoned. 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

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

123
            ->/** @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...
124
            ->willReturn(123);
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

124
            ->/** @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...
Bug introduced by
The method willReturn() does not exist on CommerceLeague\ActiveCampaign\Model\Abandoned. 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

124
            ->/** @scrutinizer ignore-call */ willReturn(123);
Loading history...
125
126
        $this->abandoned->expects($this->never())
127
            ->method('setQuoteId');
128
129
        $this->assertSame($this->abandoned, $this->abandonedRepository->getOrCreateByQuoteId($quoteId));
130
    }
131
132
    public function testGetOrCreateByQuoteId()
133
    {
134
        $quoteId = 123;
135
136
        $this->abandonedResource->expects($this->once())
137
            ->method('load')
138
            ->with($this->abandoned, $quoteId, AbandonedInterface::QUOTE_ID)
139
            ->willReturn($this->abandoned);
140
141
        $this->abandoned->expects($this->once())
142
            ->method('getId')
143
            ->willReturn(null);
144
145
        $this->abandoned->expects($this->once())
146
            ->method('setQuoteId')
147
            ->with($quoteId)
0 ignored issues
show
Bug introduced by
The method with() does not exist on CommerceLeague\ActiveCampaign\Model\Abandoned. 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
            ->/** @scrutinizer ignore-call */ with($quoteId)
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

147
            ->/** @scrutinizer ignore-call */ with($quoteId)

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...
148
            ->willReturnSelf();
0 ignored issues
show
Bug introduced by
The method willReturnSelf() does not exist on CommerceLeague\ActiveCampaign\Model\Abandoned. 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 */ willReturnSelf();
Loading history...
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

148
            ->/** @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...
149
150
        $this->abandonedResource->expects($this->once())
151
            ->method('save')
152
            ->with($this->abandoned)
153
            ->willReturn($this->abandoned);
154
155
        $this->assertSame($this->abandoned, $this->abandonedRepository->getOrCreateByQuoteId($quoteId));
156
    }
157
158
    public function testDeleteThrowsException()
159
    {
160
        $this->abandonedResource->expects($this->once())
161
            ->method('delete')
162
            ->with($this->abandoned)
163
            ->willThrowException(new \Exception('an exception message'));
164
165
        $this->expectException(CouldNotDeleteException::class);
166
        $this->expectExceptionMessage('an exception message');
167
168
        $this->abandonedRepository->delete($this->abandoned);
169
    }
170
171
    public function testDelete()
172
    {
173
        $this->abandonedResource->expects($this->once())
174
            ->method('delete')
175
            ->with($this->abandoned)
176
            ->willReturnSelf();
177
178
        $this->assertTrue($this->abandonedRepository->delete($this->abandoned));
179
    }
180
181
182
    public function testDeleteByIdThrowsException()
183
    {
184
        $entityId = 123;
185
186
        $this->abandoned->expects($this->once())
187
            ->method('getId')
188
            ->willReturn(null);
189
190
        $this->abandonedResource->expects($this->once())
191
            ->method('load')
192
            ->with($this->abandoned, $entityId)
193
            ->willReturn($this->abandoned);
194
195
        $this->abandonedResource->expects($this->never())
196
            ->method('delete');
197
198
        $this->expectException(NoSuchEntityException::class);
199
        $this->expectExceptionMessage('The Abandoned Cart with the "123" ID doesn\'t exist');
200
201
        $this->abandonedRepository->deleteById($entityId);
202
    }
203
204
    public function testDeleteById()
205
    {
206
        $entityId = 123;
207
208
        $this->abandoned->expects($this->once())
209
            ->method('getId')
210
            ->willReturn($entityId);
211
212
        $this->abandonedResource->expects($this->once())
213
            ->method('load')
214
            ->with($this->abandoned, $entityId)
215
            ->willReturn($this->abandoned);
216
217
        $this->abandonedResource->expects($this->once())
218
            ->method('delete')
219
            ->with($this->abandoned)
220
            ->willReturnSelf();
221
222
        $this->assertTrue($this->abandonedRepository->deleteById($entityId));
223
    }
224
}
225