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 ( fb8f78...f9a184 )
by Andreas
03:45
created

SyncContactConsumerTest::testConsume()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 31
Code Lines 23

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 23
nc 1
nop 0
dl 0
loc 31
rs 9.552
c 1
b 0
f 1
1
<?php
2
declare(strict_types=1);
3
/**
4
 */
5
6
namespace CommerceLeague\ActiveCampaign\Test\Unit\MessageQueue;
7
8
use CommerceLeague\ActiveCampaign\Api\ContactRepositoryInterface;
9
use CommerceLeague\ActiveCampaign\Api\Data\ContactInterface;
10
use CommerceLeague\ActiveCampaign\Logger\Logger;
11
use CommerceLeague\ActiveCampaign\MessageQueue\SyncContactConsumer;
12
use CommerceLeague\ActiveCampaignApi\Api\ContactApiResourceInterface;
13
use CommerceLeague\ActiveCampaignApi\Exception\HttpException;
14
use PHPUnit\Framework\MockObject\MockObject;
15
use PHPUnit\Framework\TestCase;
16
use CommerceLeague\ActiveCampaign\Helper\Client as ClientHelper;
17
18
class SyncContactConsumerTest extends TestCase
19
{
20
    /**
21
     * @var MockObject|ContactRepositoryInterface
22
     */
23
    protected $contactRepository;
24
25
    /**
26
     * @var MockObject|Logger
27
     */
28
    protected $logger;
29
30
    /**
31
     * @var MockObject|ClientHelper
32
     */
33
    protected $clientHelper;
34
35
    /**
36
     * @var MockObject|ContactInterface
37
     */
38
    protected $contact;
39
40
    /**
41
     * @var MockObject|ContactApiResourceInterface
42
     */
43
    protected $contactApi;
44
45
    /**
46
     * @var SyncContactConsumer
47
     */
48
    protected $syncContactConsumer;
49
50
    protected function setUp()
51
    {
52
        $this->contactRepository = $this->createMock(ContactRepositoryInterface::class);
53
        $this->logger = $this->createMock(Logger::class);
54
        $this->clientHelper = $this->createMock(ClientHelper::class);
55
        $this->contact = $this->createMock(ContactInterface::class);
56
        $this->contactApi = $this->createMock(ContactApiResourceInterface::class);
57
58
        $this->syncContactConsumer = new SyncContactConsumer(
59
            $this->contactRepository,
60
            $this->logger,
61
            $this->clientHelper
62
        );
63
    }
64
65
    public function testConsumeApiResponseException()
66
    {
67
        $email = '[email protected]';
68
        $request = ['email' => $email];
69
70
        $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

70
        $this->contactRepository->/** @scrutinizer ignore-call */ 
71
                                  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...
71
            ->method('getOrCreateByEmail')
72
            ->with($email)
73
            ->willReturn($this->contact);
74
75
        $this->clientHelper->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not exist on CommerceLeague\ActiveCampaign\Helper\Client. ( Ignorable by Annotation )

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

75
        $this->clientHelper->/** @scrutinizer ignore-call */ 
76
                             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...
76
            ->method('getContactApi')
77
            ->willReturn($this->contactApi);
78
79
        /** @var MockObject|HttpException $httpException */
80
        $httpException = $this->createMock(HttpException::class);
81
82
        $this->contactApi->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not exist on CommerceLeague\ActiveCam...actApiResourceInterface. ( 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->contactApi->/** @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('upsert')
84
            ->with(['contact' => $request])
85
            ->willThrowException($httpException);
86
87
        $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

87
        $this->logger->/** @scrutinizer ignore-call */ 
88
                       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...
88
            ->method('error');
89
90
        $this->contact->expects($this->never())
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

90
        $this->contact->/** @scrutinizer ignore-call */ 
91
                        expects($this->never())
Loading history...
91
            ->method('setActiveCampaignId');
92
93
        $this->syncContactConsumer->consume(json_encode(['email' => $email, 'request' => $request]));
94
    }
95
96
    public function testConsume()
97
    {
98
        $email = '[email protected]';
99
        $request = ['email' => $email];
100
        $activeCampaignId = 123;
101
        $response = ['contact' => ['id' => $activeCampaignId]];
102
103
        $this->contactRepository->expects($this->once())
104
            ->method('getOrCreateByEmail')
105
            ->with($email)
106
            ->willReturn($this->contact);
107
108
        $this->clientHelper->expects($this->once())
109
            ->method('getContactApi')
110
            ->willReturn($this->contactApi);
111
112
        $this->contactApi->expects($this->once())
113
            ->method('upsert')
114
            ->with(['contact' => $request])
115
            ->willReturn($response);
116
117
        $this->contact->expects($this->once())
118
            ->method('setActiveCampaignId')
119
            ->with($activeCampaignId)
120
            ->willReturnSelf();
121
122
        $this->contactRepository->expects($this->once())
123
            ->method('save')
124
            ->with($this->contact);
125
126
        $this->syncContactConsumer->consume(json_encode(['email' => $email, 'request' => $request]));
127
    }
128
}
129