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 ( 3bfcba...f91474 )
by Andreas
04:15
created

testExecute()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 30
Code Lines 22

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 22
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 30
rs 9.568
1
<?php
2
declare(strict_types=1);
3
/**
4
 */
5
6
namespace CommerceLeague\ActiveCampaign\Test\Unit\Observer\Customer;
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\NewsletterSubscriberSaveAfterObserver;
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 NewsletterSubscriberSaveAfterObserverTest 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 NewsletterSubscriberSaveAfterObserver
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 NewsletterSubscriberSaveAfterObserver(
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 testExecuteWithException()
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
        $exception = new CouldNotSaveException(new Phrase(''));
131
132
        $this->contactRepository->expects($this->once())
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

132
        $this->contactRepository->/** @scrutinizer ignore-call */ 
133
                                  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...
133
            ->method('getOrCreateBySubscriber')
134
            ->with($this->subscriber)
135
            ->willThrowException($exception);
136
137
        $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

137
        $this->logger->/** @scrutinizer ignore-call */ 
138
                       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...
138
            ->method('critical')
139
            ->with($exception);
140
141
        $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

141
        $this->createUpdatePublisher->/** @scrutinizer ignore-call */ 
142
                                      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...
142
            ->method('publish');
143
144
        $this->newsletterSubscriberSaveAfterObserver->execute($this->observer);
145
    }
146
147
    public function testExecute()
148
    {
149
        $this->configHelper->expects($this->once())
150
            ->method('isApiEnabled')
151
            ->willReturn(true);
152
153
        $this->observer->expects($this->once())
154
            ->method('getEvent')
155
            ->willReturn($this->event);
156
157
        $this->event->expects($this->once())
158
            ->method('getData')
159
            ->with('subscriber')
160
            ->willReturn($this->subscriber);
161
162
        $this->contactRepository->expects($this->once())
163
            ->method('getOrCreateBySubscriber')
164
            ->with($this->subscriber)
165
            ->willReturn($this->contact);
166
167
        $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

167
        $this->createUpdateMessageBuilder->/** @scrutinizer ignore-call */ 
168
                                           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...
168
            ->method('buildWithSubscriber')
169
            ->with($this->contact, $this->subscriber)
170
            ->willReturn($this->createUpdateMessage);
171
172
        $this->createUpdatePublisher->expects($this->once())
173
            ->method('publish')
174
            ->with($this->createUpdateMessage);
175
176
        $this->newsletterSubscriberSaveAfterObserver->execute($this->observer);
177
    }
178
}
179