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 ( 5543fb...d29718 )
by Andreas
03:19
created

CreateUpdateContactServiceTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 97
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 46
c 1
b 0
f 0
dl 0
loc 97
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A testExecuteContactCouldNotSave() 0 19 1
A testExecute() 0 22 1
A setUp() 0 14 1
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 PHPUnit\Framework\MockObject\MockObject;
18
use PHPUnit\Framework\TestCase;
19
20
class CreateUpdateContactServiceTest extends TestCase
21
{
22
    /**
23
     * @var MockObject|ContactRepositoryInterface
24
     */
25
    protected $contactRepository;
26
27
    /**
28
     * @var MockObject|Logger
29
     */
30
    protected $logger;
31
32
    /**
33
     * @var MockObject|ContactRequestBuilder
34
     */
35
    protected $contactRequestBuilder;
36
37
    /**
38
     * @var MockObject|CreateUpdatePublisher
39
     */
40
    protected $createUpdatePublisher;
41
42
    /**
43
     * @var MockObject|Customer
44
     */
45
    protected $customer;
46
47
    /**
48
     * @var MockObject|ContactInterface
49
     */
50
    protected $contact;
51
52
    /**
53
     * @var CreateUpdateContactService
54
     */
55
    protected $createUpdateContactService;
56
57
    protected function setUp()
58
    {
59
        $this->contactRepository = $this->createMock(ContactRepositoryInterface::class);
60
        $this->logger = $this->createMock(Logger::class);
61
        $this->contactRequestBuilder = $this->createMock(ContactRequestBuilder::class);
62
        $this->createUpdatePublisher = $this->createMock(CreateUpdatePublisher::class);
63
        $this->customer = $this->createMock(Customer::class);
64
        $this->contact = $this->createMock(ContactInterface::class);
65
66
        $this->createUpdateContactService = new CreateUpdateContactService(
67
            $this->contactRepository,
68
            $this->logger,
69
            $this->contactRequestBuilder,
70
            $this->createUpdatePublisher
71
        );
72
    }
73
74
    public function testExecuteContactCouldNotSave()
75
    {
76
        $exception = new CouldNotSaveException(new Phrase('an exception'));
77
78
        $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

78
        $this->contactRepository->/** @scrutinizer ignore-call */ 
79
                                  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...
79
            ->method('getOrCreateByCustomer')
80
            ->willThrowException($exception);
81
82
        $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

82
        $this->logger->/** @scrutinizer ignore-call */ 
83
                       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...
83
            ->method('critical')
84
            ->with($exception);
85
86
        $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

86
        $this->contactRequestBuilder->/** @scrutinizer ignore-call */ 
87
                                      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...
87
            ->method('build');
88
89
        $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

89
        $this->createUpdatePublisher->/** @scrutinizer ignore-call */ 
90
                                      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...
90
            ->method('publish');
91
92
        $this->createUpdateContactService->execute($this->customer);
93
    }
94
95
    public function testExecute()
96
    {
97
        $contactId = 123;
98
99
        $this->contactRepository->expects($this->once())
100
            ->method('getOrCreateByCustomer')
101
            ->willReturn($this->contact);
102
103
        $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

103
        $this->contact->/** @scrutinizer ignore-call */ 
104
                        expects($this->once())
Loading history...
104
            ->method('getId')
105
            ->willReturn($contactId);
106
107
        $this->contactRequestBuilder->expects($this->once())
108
            ->method('build')
109
            ->with($this->customer)
110
            ->willReturn(['request']);
111
112
        $this->createUpdatePublisher->expects($this->once())
113
            ->method('publish')
114
            ->with($this->isInstanceOf(CreateUpdateMessage::class));
115
116
        $this->createUpdateContactService->execute($this->customer);
117
    }
118
}
119