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 ( f845d1...f19061 )
by Andreas
04:47
created

testBuildWithSubscriberNotSubscribed()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 20
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 13
c 1
b 0
f 1
nc 1
nop 0
dl 0
loc 20
rs 9.8333
1
<?php
2
declare(strict_types=1);
3
/**
4
 */
5
6
namespace CommerceLeague\ActiveCampaign\Test\Unit\Gateway\Request;
7
8
use CommerceLeague\ActiveCampaign\Gateway\Request\ContactBuilder;
9
use CommerceLeague\ActiveCampaign\Helper\Contants;
10
use Magento\Framework\Api\ExtensionAttributesInterface;
11
use Magento\Newsletter\Model\Subscriber;
12
use PHPUnit\Framework\MockObject\MockObject;
13
use PHPUnit\Framework\TestCase;
14
use Magento\Customer\Api\Data\CustomerInterface as MagentoCustomerInterface;
15
16
class ContactBuilderTest extends TestCase
17
{
18
    /**
19
     * @var MockObject|MagentoCustomerInterface
20
     */
21
    protected $magentoCustomer;
22
23
    /**
24
     * @var MockObject|Subscriber
25
     */
26
    protected $subscriber;
27
28
    /**
29
     * @var MockObject|ExtensionAttributesInterface
30
     */
31
    protected $extensionAttributes;
32
33
    /**
34
     * @var ContactBuilder
35
     */
36
    protected $contactBuilder;
37
38
    protected function setUp()
39
    {
40
        $this->magentoCustomer = $this->createMock(MagentoCustomerInterface::class);
41
        $this->subscriber = $this->createMock(Subscriber::class);
42
        $this->extensionAttributes = $this->getMockBuilder(ExtensionAttributesInterface::class)
43
            ->setMethods(['getIsSubscribed'])
44
            ->getMockForAbstractClass();
45
46
        $this->contactBuilder = new ContactBuilder();
47
    }
48
49
    public function testBuildWithMagentoCustomerNotSubscribed()
50
    {
51
        $email = '[email protected]';
52
        $firstName = 'firstName';
53
        $lastName = 'lastName';
54
55
        $this->magentoCustomer->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not exist on Magento\Customer\Api\Data\CustomerInterface. ( Ignorable by Annotation )

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

55
        $this->magentoCustomer->/** @scrutinizer ignore-call */ 
56
                                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...
56
            ->method('getExtensionAttributes')
57
            ->willReturn($this->extensionAttributes);
58
59
        $this->extensionAttributes->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not exist on Magento\Framework\Api\ExtensionAttributesInterface. It seems like you code against a sub-type of Magento\Framework\Api\ExtensionAttributesInterface such as Magento\Ui\Model\Bookmark. ( Ignorable by Annotation )

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

59
        $this->extensionAttributes->/** @scrutinizer ignore-call */ 
60
                                    expects($this->once())
Loading history...
60
            ->method('getIsSubscribed')
61
            ->willReturn(false);
62
63
        $this->magentoCustomer->expects($this->once())
64
            ->method('getEmail')
65
            ->willReturn($email);
66
67
        $this->magentoCustomer->expects($this->once())
68
            ->method('getFirstname')
69
            ->willReturn($firstName);
70
71
        $this->magentoCustomer->expects($this->once())
72
            ->method('getLastname')
73
            ->willReturn($lastName);
74
75
        $expected = [
76
            'status' => Contants::CONTACT_STATUS_UNSUBSCRIBED,
77
            'email' => $email,
78
            'firstName' => $firstName,
79
            'lastName' => $lastName
80
        ];
81
82
        $this->assertEquals(
83
            $expected,
84
            $this->contactBuilder->buildWithMagentoCustomer($this->magentoCustomer)
85
        );
86
    }
87
88
89
    public function testBuildWithMagentoCustomerSubscribed()
90
    {
91
        $email = '[email protected]';
92
        $firstName = 'firstName';
93
        $lastName = 'lastName';
94
95
        $this->magentoCustomer->expects($this->once())
96
            ->method('getExtensionAttributes')
97
            ->willReturn($this->extensionAttributes);
98
99
        $this->extensionAttributes->expects($this->once())
100
            ->method('getIsSubscribed')
101
            ->willReturn(true);
102
103
        $this->magentoCustomer->expects($this->once())
104
            ->method('getEmail')
105
            ->willReturn($email);
106
107
        $this->magentoCustomer->expects($this->once())
108
            ->method('getFirstname')
109
            ->willReturn($firstName);
110
111
        $this->magentoCustomer->expects($this->once())
112
            ->method('getLastname')
113
            ->willReturn($lastName);
114
115
        $expected = [
116
            'status' => Contants::CONTACT_STATUS_ACTIVE,
117
            'email' => $email,
118
            'firstName' => $firstName,
119
            'lastName' => $lastName
120
        ];
121
122
        $this->assertEquals(
123
            $expected,
124
            $this->contactBuilder->buildWithMagentoCustomer($this->magentoCustomer)
125
        );
126
    }
127
128
    public function testBuildWithSubscriberNotSubscribed()
129
    {
130
        $email = '[email protected]';
131
132
        $this->subscriber->expects($this->once())
133
            ->method('isSubscribed')
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

133
            ->/** @scrutinizer ignore-call */ method('isSubscribed')

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...
134
            ->willReturn(false);
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

134
            ->/** @scrutinizer ignore-call */ willReturn(false);

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...
135
136
        $this->subscriber->expects($this->once())
137
            ->method('getEmail')
138
            ->willReturn($email);
139
140
        $expected = [
141
            'status' => Contants::CONTACT_STATUS_UNSUBSCRIBED,
142
            'email' => $email
143
        ];
144
145
        $this->assertEquals(
146
            $expected,
147
            $this->contactBuilder->buildWithSubscriber($this->subscriber)
148
        );
149
    }
150
151
    public function testBuildWithSubscriberSubscribed()
152
    {
153
        $email = '[email protected]';
154
155
        $this->subscriber->expects($this->once())
156
            ->method('isSubscribed')
157
            ->willReturn(true);
158
159
        $this->subscriber->expects($this->once())
160
            ->method('getEmail')
161
            ->willReturn($email);
162
163
        $expected = [
164
            'status' => Contants::CONTACT_STATUS_ACTIVE,
165
            'email' => $email
166
        ];
167
168
        $this->assertEquals(
169
            $expected,
170
            $this->contactBuilder->buildWithSubscriber($this->subscriber)
171
        );
172
    }
173
174
}
175