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 ( ad4463...4d14c7 )
by Andreas
03:15
created

CreateUpdateContactServiceTest::testExecute()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 22
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 15
c 1
b 0
f 0
dl 0
loc 22
rs 9.7666
cc 1
nc 1
nop 0
1
<?php
2
/**
3
 */
4
5
namespace CommerceLeague\ActiveCampaign\Test\Unit\Service\Contact;
6
7
use CommerceLeague\ActiveCampaign\Api\ContactRepositoryInterface;
8
use CommerceLeague\ActiveCampaign\Api\Data\ContactInterface;
9
use CommerceLeague\ActiveCampaign\Gateway\Request\ContactRequestBuilder;
10
use CommerceLeague\ActiveCampaign\Logger\Logger;
11
use CommerceLeague\ActiveCampaign\MessageQueue\Contact\CreateUpdateMessage;
12
use CommerceLeague\ActiveCampaign\MessageQueue\Contact\CreateUpdatePublisher;
13
use CommerceLeague\ActiveCampaign\Service\Contact\CreateUpdateContactService;
14
use Magento\Customer\Model\Customer;
15
use Magento\Framework\Exception\CouldNotSaveException;
16
use Magento\Framework\Phrase;
17
use Magento\Newsletter\Model\Subscriber;
18
use PHPUnit\Framework\MockObject\MockObject;
19
use PHPUnit\Framework\TestCase;
20
21
class CreateUpdateContactServiceTest extends TestCase
22
{
23
    /**
24
     * @var MockObject|ContactRepositoryInterface
25
     */
26
    protected $contactRepository;
27
28
    /**
29
     * @var MockObject|Logger
30
     */
31
    protected $logger;
32
33
    /**
34
     * @var MockObject|ContactRequestBuilder
35
     */
36
    protected $contactRequestBuilder;
37
38
    /**
39
     * @var MockObject|CreateUpdatePublisher
40
     */
41
    protected $createUpdatePublisher;
42
43
    /**
44
     * @var MockObject|Customer
45
     */
46
    protected $customer;
47
48
    /**
49
     * @var MockObject|Subscriber
50
     */
51
    protected $subscriber;
52
53
    /**
54
     * @var MockObject|ContactInterface
55
     */
56
    protected $contact;
57
58
    /**
59
     * @var CreateUpdateContactService
60
     */
61
    protected $createUpdateContactService;
62
63
    protected function setUp()
64
    {
65
        $this->contactRepository = $this->createMock(ContactRepositoryInterface::class);
66
        $this->logger = $this->createMock(Logger::class);
67
        $this->contactRequestBuilder = $this->createMock(ContactRequestBuilder::class);
68
        $this->createUpdatePublisher = $this->createMock(CreateUpdatePublisher::class);
69
        $this->customer = $this->createMock(Customer::class);
70
        $this->subscriber = $this->createMock(Subscriber::class);
71
        $this->contact = $this->createMock(ContactInterface::class);
72
73
        $this->createUpdateContactService = new CreateUpdateContactService(
74
            $this->contactRepository,
75
            $this->logger,
76
            $this->contactRequestBuilder,
77
            $this->createUpdatePublisher
78
        );
79
    }
80
81
    public function testExecuteWithCustomerContactCouldNotSave()
82
    {
83
        $exception = new CouldNotSaveException(new Phrase('an exception'));
84
85
        $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

85
        $this->contactRepository->/** @scrutinizer ignore-call */ 
86
                                  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...
86
            ->method('getOrCreateByCustomer')
87
            ->willThrowException($exception);
88
89
        $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

89
        $this->logger->/** @scrutinizer ignore-call */ 
90
                       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...
90
            ->method('critical')
91
            ->with($exception);
92
93
        $this->contactRequestBuilder->expects($this->never())
0 ignored issues
show
Bug introduced by
The method expects() does not exist on CommerceLeague\ActiveCam...t\ContactRequestBuilder. ( Ignorable by Annotation )

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

93
        $this->contactRequestBuilder->/** @scrutinizer ignore-call */ 
94
                                      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...
94
            ->method('buildWithCustomer');
95
96
        $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

96
        $this->createUpdatePublisher->/** @scrutinizer ignore-call */ 
97
                                      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...
97
            ->method('publish');
98
99
        $this->createUpdateContactService->executeWithCustomer($this->customer);
100
    }
101
102
    public function testExecuteWithCustomer()
103
    {
104
        $contactId = 123;
105
106
        $this->contactRepository->expects($this->once())
107
            ->method('getOrCreateByCustomer')
108
            ->willReturn($this->contact);
109
110
        $this->contact->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not exist on CommerceLeague\ActiveCam...i\Data\ContactInterface. Since it exists in all sub-types, consider adding an abstract or default implementation to CommerceLeague\ActiveCam...i\Data\ContactInterface. ( Ignorable by Annotation )

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

110
        $this->contact->/** @scrutinizer ignore-call */ 
111
                        expects($this->once())
Loading history...
111
            ->method('getId')
112
            ->willReturn($contactId);
113
114
        $this->contactRequestBuilder->expects($this->once())
115
            ->method('buildWithCustomer')
116
            ->with($this->customer)
117
            ->willReturn(['request']);
118
119
        $this->createUpdatePublisher->expects($this->once())
120
            ->method('publish')
121
            ->with($this->isInstanceOf(CreateUpdateMessage::class));
122
123
        $this->createUpdateContactService->executeWithCustomer($this->customer);
124
    }
125
126
    public function testExecuteWithSubscriberContactCouldNotSave()
127
    {
128
        $exception = new CouldNotSaveException(new Phrase('an exception'));
129
130
        $this->contactRepository->expects($this->once())
131
            ->method('getOrCreateBySubscriber')
132
            ->willThrowException($exception);
133
134
        $this->logger->expects($this->once())
135
            ->method('critical')
136
            ->with($exception);
137
138
        $this->contactRequestBuilder->expects($this->never())
139
            ->method('buildWithSubscriber');
140
141
        $this->createUpdatePublisher->expects($this->never())
142
            ->method('publish');
143
144
        $this->createUpdateContactService->executeWithSubscriber($this->subscriber);
145
    }
146
147
    public function testExecuteWithSubscriber()
148
    {
149
        $contactId = 123;
150
151
        $this->contactRepository->expects($this->once())
152
            ->method('getOrCreateBySubscriber')
153
            ->willReturn($this->contact);
154
155
        $this->contact->expects($this->once())
156
            ->method('getId')
157
            ->willReturn($contactId);
158
159
        $this->contactRequestBuilder->expects($this->once())
160
            ->method('buildWithSubscriber')
161
            ->with($this->subscriber)
162
            ->willReturn(['request']);
163
164
        $this->createUpdatePublisher->expects($this->once())
165
            ->method('publish')
166
            ->with($this->isInstanceOf(CreateUpdateMessage::class));
167
168
        $this->createUpdateContactService->executeWithSubscriber($this->subscriber);
169
    }
170
}
171