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 ( c8c4e6...db9143 )
by Andreas
03:30
created

ExportOrderObserverTest   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 149
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 82
dl 0
loc 149
rs 10
c 1
b 0
f 0
wmc 5

5 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 11 1
A testExecuteWithIncompleteOrder() 0 23 1
A testExecute() 0 37 1
A testExecuteWithGuestOrder() 0 27 1
A testExecuteApiDisabled() 0 10 1
1
<?php
2
declare(strict_types=1);
3
/**
4
 */
5
6
namespace CommerceLeague\ActiveCampaign\Test\Unit\Observer\Sales;
7
8
use CommerceLeague\ActiveCampaign\Helper\Config as ConfigHelper;
9
use CommerceLeague\ActiveCampaign\MessageQueue\Topics;
10
use CommerceLeague\ActiveCampaign\Observer\Sales\ExportOrderObserver;
11
use Magento\Framework\Event;
12
use Magento\Framework\Event\Observer;
13
use Magento\Framework\MessageQueue\PublisherInterface;
14
use Magento\Sales\Model\Order as MagentoOrder;
15
use PHPUnit\Framework\MockObject\MockObject;
16
use PHPUnit\Framework\TestCase;
17
18
class ExportOrderObserverTest extends TestCase
19
{
20
    /**
21
     * @var MockObject|ConfigHelper
22
     */
23
    protected $configHelper;
24
25
    /**
26
     * @var MockObject|PublisherInterface
27
     */
28
    protected $publisher;
29
30
    /**
31
     * @var MockObject|Observer
32
     */
33
    protected $observer;
34
35
    /**
36
     * @var MockObject|Event
37
     */
38
    protected $event;
39
40
    /**
41
     * @var MockObject|MagentoOrder
42
     */
43
    protected $magentoOrder;
44
45
    /**
46
     * @var ExportOrderObserver
47
     */
48
    protected $exportOrderObserver;
49
50
    protected function setUp()
51
    {
52
        $this->configHelper = $this->createMock(ConfigHelper::class);
53
        $this->publisher = $this->createMock(PublisherInterface::class);
54
        $this->observer = $this->createMock(Observer::class);
55
        $this->event = $this->createMock(Event::class);
56
        $this->magentoOrder = $this->createMock(MagentoOrder::class);
57
58
        $this->exportOrderObserver = new ExportOrderObserver(
59
            $this->configHelper,
60
            $this->publisher
61
        );
62
    }
63
64
    public function testExecuteApiDisabled()
65
    {
66
        $this->configHelper->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not exist on CommerceLeague\ActiveCampaign\Helper\Config. ( Ignorable by Annotation )

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

66
        $this->configHelper->/** @scrutinizer ignore-call */ 
67
                             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...
67
            ->method('isApiEnabled')
68
            ->willReturn(false);
69
70
        $this->observer->expects($this->never())
71
            ->method('getEvent');
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

71
            ->/** @scrutinizer ignore-call */ method('getEvent');

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...
72
73
        $this->exportOrderObserver->execute($this->observer);
74
    }
75
76
    public function testExecuteWithIncompleteOrder()
77
    {
78
        $this->configHelper->expects($this->once())
79
            ->method('isApiEnabled')
80
            ->willReturn(true);
81
82
        $this->observer->expects($this->once())
83
            ->method('getEvent')
84
            ->willReturn($this->event);
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

84
            ->/** @scrutinizer ignore-call */ willReturn($this->event);

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...
85
86
        $this->event->expects($this->once())
87
            ->method('getData')
88
            ->with('order')
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

88
            ->/** @scrutinizer ignore-call */ with('order')

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...
89
            ->willReturn($this->magentoOrder);
90
91
        $this->magentoOrder->expects($this->once())
92
            ->method('getStatus')
93
            ->willReturn('pending');
94
95
        $this->publisher->expects($this->never())
0 ignored issues
show
Bug introduced by
The method expects() does not exist on Magento\Framework\MessageQueue\PublisherInterface. ( Ignorable by Annotation )

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

95
        $this->publisher->/** @scrutinizer ignore-call */ 
96
                          expects($this->never())

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...
96
            ->method('publish');
97
98
        $this->exportOrderObserver->execute($this->observer);
99
    }
100
101
    public function testExecuteWithGuestOrder()
102
    {
103
        $this->configHelper->expects($this->once())
104
            ->method('isApiEnabled')
105
            ->willReturn(true);
106
107
        $this->observer->expects($this->once())
108
            ->method('getEvent')
109
            ->willReturn($this->event);
110
111
        $this->event->expects($this->once())
112
            ->method('getData')
113
            ->with('order')
114
            ->willReturn($this->magentoOrder);
115
116
        $this->magentoOrder->expects($this->once())
117
            ->method('getStatus')
118
            ->willReturn('complete');
119
120
        $this->magentoOrder->expects($this->once())
121
            ->method('getCustomerIsGuest')
122
            ->willReturn(true);
123
124
        $this->publisher->expects($this->never())
125
            ->method('publish');
126
127
        $this->exportOrderObserver->execute($this->observer);
128
    }
129
130
    public function testExecute()
131
    {
132
        $magentoOrderId = 123;
133
134
        $this->configHelper->expects($this->once())
135
            ->method('isApiEnabled')
136
            ->willReturn(true);
137
138
        $this->observer->expects($this->once())
139
            ->method('getEvent')
140
            ->willReturn($this->event);
141
142
        $this->event->expects($this->once())
143
            ->method('getData')
144
            ->with('order')
145
            ->willReturn($this->magentoOrder);
146
147
        $this->magentoOrder->expects($this->once())
148
            ->method('getStatus')
149
            ->willReturn('complete');
150
151
        $this->magentoOrder->expects($this->once())
152
            ->method('getCustomerIsGuest')
153
            ->willReturn(false);
154
155
        $this->magentoOrder->expects($this->once())
156
            ->method('getId')
157
            ->willReturn($magentoOrderId);
158
159
        $this->publisher->expects($this->once())
160
            ->method('publish')
161
            ->with(
162
                Topics::SALES_ORDER_EXPORT,
163
                json_encode(['magento_order_id' => $magentoOrderId])
164
            );
165
166
        $this->exportOrderObserver->execute($this->observer);
167
    }
168
169
170
171
}
172