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

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

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

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

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

126
            ->/** @scrutinizer ignore-call */ with('customer')

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...
127
            ->willReturn($this->customer);
128
129
        $exception = new CouldNotSaveException(new Phrase(''));
130
131
        $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

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

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

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

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