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 ( c3352e...e935d9 )
by Andreas
04:05
created

CreateUpdateContactObserverTest::testExecute()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 35
Code Lines 26

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 26
nc 1
nop 0
dl 0
loc 35
rs 9.504
c 0
b 0
f 0
1
<?php
2
declare(strict_types=1);
3
/**
4
 */
5
6
namespace CommerceLeague\ActiveCampaign\Test\Unit\Observer\Newsletter;
7
8
use CommerceLeague\ActiveCampaign\Api\ContactRepositoryInterface;
9
use CommerceLeague\ActiveCampaign\Api\Data\ContactInterface;
10
use CommerceLeague\ActiveCampaign\Helper\Config as ConfigHelper;
11
use CommerceLeague\ActiveCampaign\Logger\Logger;
12
use CommerceLeague\ActiveCampaign\MessageQueue\Contact\CreateUpdateMessage;
13
use CommerceLeague\ActiveCampaign\MessageQueue\Contact\CreateUpdateMessageBuilder;
14
use CommerceLeague\ActiveCampaign\MessageQueue\Contact\CreateUpdatePublisher;
15
use CommerceLeague\ActiveCampaign\Observer\Newsletter\CreateUpdateContactObserver;
16
use Magento\Framework\Event;
17
use Magento\Framework\Event\Observer;
18
use Magento\Framework\Exception\CouldNotSaveException;
19
use Magento\Framework\Phrase;
20
use Magento\Newsletter\Model\Subscriber;
21
use PHPUnit\Framework\MockObject\MockObject;
22
use PHPUnit\Framework\TestCase;
23
24
class CreateUpdateContactObserverTest extends TestCase
25
{
26
    /**
27
     * @var MockObject|ConfigHelper
28
     */
29
    protected $configHelper;
30
31
    /**
32
     * @var MockObject|ContactRepositoryInterface
33
     */
34
    protected $contactRepository;
35
36
    /**
37
     * @var MockObject|Logger
38
     */
39
    protected $logger;
40
41
    /**
42
     * @var MockObject|CreateUpdateMessageBuilder
43
     */
44
    protected $createUpdateMessageBuilder;
45
46
    /**
47
     * @var MockObject|CreateUpdatePublisher
48
     */
49
    protected $createUpdatePublisher;
50
51
    /**
52
     * @var MockObject|Observer
53
     */
54
    protected $observer;
55
56
    /**
57
     * @var MockObject|Event
58
     */
59
    protected $event;
60
61
    /**
62
     * @var MockObject|Subscriber
63
     */
64
    protected $subscriber;
65
66
    /**
67
     * @var MockObject|ContactInterface
68
     */
69
    protected $contact;
70
71
    /**
72
     * @var MockObject|CreateUpdateMessage
73
     */
74
    protected $createUpdateMessage;
75
76
    /**
77
     * @var CreateUpdateContactObserver
78
     */
79
    protected $newsletterSubscriberSaveAfterObserver;
80
81
    protected function setUp()
82
    {
83
        $this->configHelper = $this->createMock(ConfigHelper::class);
84
        $this->contactRepository = $this->createMock(ContactRepositoryInterface::class);
85
        $this->logger = $this->createMock(Logger::class);
86
        $this->createUpdateMessageBuilder = $this->createMock(CreateUpdateMessageBuilder::class);
87
        $this->createUpdatePublisher = $this->createMock(CreateUpdatePublisher::class);
88
        $this->observer = $this->createMock(Observer::class);
89
        $this->event = $this->createMock(Event::class);
90
        $this->subscriber = $this->createMock(Subscriber::class);
91
        $this->contact = $this->createMock(ContactInterface::class);
92
        $this->createUpdateMessage = $this->createMock(CreateUpdateMessage::class);
93
94
        $this->newsletterSubscriberSaveAfterObserver = new CreateUpdateContactObserver(
95
            $this->configHelper,
96
            $this->contactRepository,
97
            $this->logger,
98
            $this->createUpdateMessageBuilder,
99
            $this->createUpdatePublisher
100
        );
101
    }
102
103
    public function testExecuteApiNotEnabled()
104
    {
105
        $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

105
        $this->configHelper->/** @scrutinizer ignore-call */ 
106
                             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...
106
            ->method('isApiEnabled')
107
            ->willReturn(false);
108
109
        $this->observer->expects($this->never())
110
            ->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

110
            ->/** @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...
111
112
        $this->newsletterSubscriberSaveAfterObserver->execute($this->observer);
113
    }
114
115
    public function testExecuteWithCustomerAsSubscriber()
116
    {
117
        $this->configHelper->expects($this->once())
118
            ->method('isApiEnabled')
119
            ->willReturn(true);
120
121
        $this->observer->expects($this->once())
122
            ->method('getEvent')
123
            ->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

123
            ->/** @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...
124
125
        $this->event->expects($this->once())
126
            ->method('getData')
127
            ->with('subscriber')
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

127
            ->/** @scrutinizer ignore-call */ with('subscriber')

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...
128
            ->willReturn($this->subscriber);
129
130
        $this->subscriber->expects($this->once())
131
            ->method('getData')
132
            ->with('customer_id')
133
            ->willReturn(123);
134
135
        $this->contactRepository->expects($this->never())
0 ignored issues
show
Bug introduced by
The method expects() does not exist on CommerceLeague\ActiveCam...tactRepositoryInterface. ( Ignorable by Annotation )

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

135
        $this->contactRepository->/** @scrutinizer ignore-call */ 
136
                                  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...
136
            ->method('getOrCreateBySubscriber');
137
138
        $this->newsletterSubscriberSaveAfterObserver->execute($this->observer);
139
    }
140
141
    public function testExecuteWithException()
142
    {
143
        $this->configHelper->expects($this->once())
144
            ->method('isApiEnabled')
145
            ->willReturn(true);
146
147
        $this->observer->expects($this->once())
148
            ->method('getEvent')
149
            ->willReturn($this->event);
150
151
        $this->event->expects($this->once())
152
            ->method('getData')
153
            ->with('subscriber')
154
            ->willReturn($this->subscriber);
155
156
        $this->subscriber->expects($this->once())
157
            ->method('getData')
158
            ->with('customer_id')
159
            ->willReturn(null);
160
161
        $exception = new CouldNotSaveException(new Phrase(''));
162
163
        $this->contactRepository->expects($this->once())
164
            ->method('getOrCreateBySubscriber')
165
            ->with($this->subscriber)
166
            ->willThrowException($exception);
167
168
        $this->logger->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not exist on CommerceLeague\ActiveCampaign\Logger\Logger. ( Ignorable by Annotation )

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

168
        $this->logger->/** @scrutinizer ignore-call */ 
169
                       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...
169
            ->method('critical')
170
            ->with($exception);
171
172
        $this->createUpdatePublisher->expects($this->never())
0 ignored issues
show
Bug introduced by
The method expects() does not exist on CommerceLeague\ActiveCam...t\CreateUpdatePublisher. ( Ignorable by Annotation )

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

172
        $this->createUpdatePublisher->/** @scrutinizer ignore-call */ 
173
                                      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...
173
            ->method('publish');
174
175
        $this->newsletterSubscriberSaveAfterObserver->execute($this->observer);
176
    }
177
178
    public function testExecute()
179
    {
180
        $this->configHelper->expects($this->once())
181
            ->method('isApiEnabled')
182
            ->willReturn(true);
183
184
        $this->observer->expects($this->once())
185
            ->method('getEvent')
186
            ->willReturn($this->event);
187
188
        $this->event->expects($this->once())
189
            ->method('getData')
190
            ->with('subscriber')
191
            ->willReturn($this->subscriber);
192
193
        $this->subscriber->expects($this->once())
194
            ->method('getData')
195
            ->with('customer_id')
196
            ->willReturn(null);
197
198
        $this->contactRepository->expects($this->once())
199
            ->method('getOrCreateBySubscriber')
200
            ->with($this->subscriber)
201
            ->willReturn($this->contact);
202
203
        $this->createUpdateMessageBuilder->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not exist on CommerceLeague\ActiveCam...ateUpdateMessageBuilder. ( Ignorable by Annotation )

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

203
        $this->createUpdateMessageBuilder->/** @scrutinizer ignore-call */ 
204
                                           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...
204
            ->method('buildWithSubscriber')
205
            ->with($this->contact, $this->subscriber)
206
            ->willReturn($this->createUpdateMessage);
207
208
        $this->createUpdatePublisher->expects($this->once())
209
            ->method('publish')
210
            ->with($this->createUpdateMessage);
211
212
        $this->newsletterSubscriberSaveAfterObserver->execute($this->observer);
213
    }
214
}
215