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 ( 468920...acc64b )
by Andreas
04:19
created

OrderRepositoryTest::setUp()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 22
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 16
nc 1
nop 0
dl 0
loc 22
rs 9.7333
c 0
b 0
f 0
1
<?php
2
declare(strict_types=1);
3
/**
4
 */
5
6
namespace CommerceLeague\ActiveCampaign\Test\Unit\Model\ActiveCampaign;
7
8
use CommerceLeague\ActiveCampaign\Api\Data\OrderInterface;
9
use CommerceLeague\ActiveCampaign\Model\ActiveCampaign\Order;
10
use CommerceLeague\ActiveCampaign\Model\ActiveCampaign\OrderFactory;
0 ignored issues
show
Bug introduced by
The type CommerceLeague\ActiveCam...veCampaign\OrderFactory 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...
11
use CommerceLeague\ActiveCampaign\Model\ActiveCampaign\OrderRepository;
12
use CommerceLeague\ActiveCampaign\Model\ResourceModel\ActiveCampaign\Order as OrderResource;
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 OrderRepositoryTest extends TestCase
20
{
21
    /**
22
     * @var MockObject|OrderResource
23
     */
24
    protected $orderResource;
25
26
    /**
27
     * @var MockObject|Order
28
     */
29
    protected $order;
30
31
    /**
32
     * @var MockObject|OrderFactory
33
     */
34
    protected $orderFactory;
35
36
    /**
37
     * @var OrderRepository
38
     */
39
    protected $orderRepository;
40
41
    protected function setUp()
42
    {
43
        $this->orderResource = $this->getMockBuilder(OrderResource::class)
44
            ->disableOriginalConstructor()
45
            ->getMock();
46
47
        $this->orderFactory = $this->getMockBuilder(OrderFactory::class)
48
            ->disableOriginalConstructor()
49
            ->setMethods(['create'])
50
            ->getMock();
51
52
        $this->order = $this->getMockBuilder(Order::class)
53
            ->disableOriginalConstructor()
54
            ->getMock();
55
56
        $this->orderFactory->expects($this->any())
57
            ->method('create')
58
            ->willReturn($this->order);
59
60
        $this->orderRepository = new OrderRepository(
61
            $this->orderResource,
62
            $this->orderFactory
63
        );
64
    }
65
66
    public function testSaveThrowsException()
67
    {
68
        $this->orderResource->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not exist on CommerceLeague\ActiveCam...el\ActiveCampaign\Order. ( 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->orderResource->/** @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->order)
71
            ->willThrowException(new \Exception('an exception message'));
72
73
        $this->expectException(CouldNotSaveException::class);
74
        $this->expectExceptionMessage('an exception message');
75
76
        $this->orderRepository->save($this->order);
77
    }
78
79
80
    public function testSave()
81
    {
82
        $this->orderResource->expects($this->once())
83
            ->method('save')
84
            ->with($this->order)
85
            ->willReturnSelf();
86
87
        $this->assertSame($this->order, $this->orderRepository->save($this->order));
88
    }
89
90
    public function testGetById()
91
    {
92
        $entityId = 123;
93
94
        $this->orderResource->expects($this->once())
95
            ->method('load')
96
            ->with($this->order, $entityId)
97
            ->willReturn($this->order);
98
99
        $this->assertSame($this->order, $this->orderRepository->getById($entityId));
100
    }
101
102
    public function testGetByMagentoCustomerId()
103
    {
104
        $magentoOrderId = 123;
105
106
        $this->orderResource->expects($this->once())
107
            ->method('load')
108
            ->with($this->order, $magentoOrderId, OrderInterface::MAGENTO_ORDER_ID)
109
            ->willReturn($this->order);
110
111
        $this->assertSame($this->order, $this->orderRepository->getByMagentoOrderId($magentoOrderId));
112
    }
113
114
115
    public function testGetOrCreateByMagentoOrderIdWithKnownMagentoCustomer()
116
    {
117
        $magentoOrderId = 123;
118
119
        $this->orderResource->expects($this->once())
120
            ->method('load')
121
            ->with($this->order, $magentoOrderId, OrderInterface::MAGENTO_ORDER_ID)
122
            ->willReturn($this->order);
123
124
        $this->order->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not exist on CommerceLeague\ActiveCam...el\ActiveCampaign\Order. 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
        $this->order->/** @scrutinizer ignore-call */ 
125
                      expects($this->once())
Loading history...
125
            ->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

125
            ->/** @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\ActiveCam...el\ActiveCampaign\Order. 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

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

126
            ->/** @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\ActiveCam...el\ActiveCampaign\Order. 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

126
            ->/** @scrutinizer ignore-call */ willReturn(123);
Loading history...
127
128
        $this->order->expects($this->never())
129
            ->method('setMagentoOrderId');
130
131
        $this->assertSame($this->order, $this->orderRepository->getOrCreateByMagentoOrderId($magentoOrderId));
132
    }
133
134
    public function testGetOrCreateByMagentoOrderId()
135
    {
136
        $magentoOrderId = 123;
137
138
        $this->orderResource->expects($this->once())
139
            ->method('load')
140
            ->with($this->order, $magentoOrderId, OrderInterface::MAGENTO_ORDER_ID)
141
            ->willReturn($this->order);
142
143
        $this->order->expects($this->once())
144
            ->method('getId')
145
            ->willReturn(null);
146
147
        $this->order->expects($this->once())
148
            ->method('setMagentoOrderId')
149
            ->with($magentoOrderId)
0 ignored issues
show
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

149
            ->/** @scrutinizer ignore-call */ with($magentoOrderId)

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 with() does not exist on CommerceLeague\ActiveCam...el\ActiveCampaign\Order. 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 */ with($magentoOrderId)
Loading history...
150
            ->willReturnSelf();
0 ignored issues
show
Bug introduced by
The method willReturnSelf() does not exist on CommerceLeague\ActiveCam...el\ActiveCampaign\Order. 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

150
            ->/** @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

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