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 ( c92bdf...416677 )
by Andreas
04:49
created

ExportContactObserverTest   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 142
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 77
dl 0
loc 142
rs 10
c 0
b 0
f 0
wmc 5

5 Methods

Rating   Name   Duplication   Size   Complexity  
A testExecuteApiDisabled() 0 10 1
A setUp() 0 11 1
A testExecuteExportContactDisabled() 0 14 1
A testExecute() 0 38 1
A testExecuteWithSubscriberAsCustomer() 0 28 1
1
<?php
2
declare(strict_types=1);
3
/**
4
 */
5
6
namespace CommerceLeague\ActiveCampaign\Test\Observer\Newsletter;
7
8
use CommerceLeague\ActiveCampaign\Helper\Config as ConfigHelper;
9
use CommerceLeague\ActiveCampaign\MessageQueue\Topics;
10
use CommerceLeague\ActiveCampaign\Observer\Newsletter\ExportContactObserver;
11
use Magento\Framework\Event;
12
use Magento\Framework\Event\Observer;
13
use Magento\Framework\MessageQueue\PublisherInterface;
14
use Magento\Newsletter\Model\Subscriber;
15
use PHPUnit\Framework\MockObject\MockObject;
16
use PHPUnit\Framework\TestCase;
17
18
class ExportContactObserverTest extends TestCase
19
{
20
    /**
21
     * @var MockObject|ConfigHelper
22
     */
23
    protected $configHelper;
24
25
    /**
26
     * @var MockObject|PublisherInterface
27
     */
28
    protected $publisher;
29
30
    /**
31
     * @var MockObject|Observer
32
     */
33
    protected $observer;
34
35
    /**
36
     * @var MockObject|Event
37
     */
38
    protected $event;
39
40
    /**
41
     * @var MockObject|Subscriber
42
     */
43
    protected $subscriber;
44
45
    /**
46
     * @var ExportContactObserver
47
     */
48
    protected $exportContactObserver;
49
50
    protected function setUp()
51
    {
52
        $this->configHelper = $this->createMock(ConfigHelper::class);
53
        $this->publisher = $this->createMock(PublisherInterface::class);
54
        $this->observer = $this->createMock(Observer::class);
55
        $this->event = $this->createMock(Event::class);
56
        $this->subscriber = $this->createMock(Subscriber::class);
57
58
        $this->exportContactObserver = new ExportContactObserver(
59
            $this->configHelper,
60
            $this->publisher
61
        );
62
    }
63
64
    public function testExecuteApiDisabled()
65
    {
66
        $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

66
        $this->configHelper->/** @scrutinizer ignore-call */ 
67
                             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...
67
            ->method('isEnabled')
68
            ->willReturn(false);
69
70
        $this->observer->expects($this->never())
71
            ->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

71
            ->/** @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...
72
73
        $this->exportContactObserver->execute($this->observer);
74
    }
75
76
    public function testExecuteExportContactDisabled()
77
    {
78
        $this->configHelper->expects($this->once())
79
            ->method('isEnabled')
80
            ->willReturn(true);
81
82
        $this->configHelper->expects($this->once())
83
            ->method('isContactExportEnabled')
84
            ->willReturn(false);
85
86
        $this->observer->expects($this->never())
87
            ->method('getEvent');
88
89
        $this->exportContactObserver->execute($this->observer);
90
    }
91
92
    public function testExecuteWithSubscriberAsCustomer()
93
    {
94
        $this->configHelper->expects($this->once())
95
            ->method('isEnabled')
96
            ->willReturn(true);
97
98
        $this->configHelper->expects($this->once())
99
            ->method('isContactExportEnabled')
100
            ->willReturn(true);
101
102
        $this->observer->expects($this->once())
103
            ->method('getEvent')
104
            ->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

104
            ->/** @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...
105
106
        $this->event->expects($this->once())
107
            ->method('getData')
108
            ->with('subscriber')
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

108
            ->/** @scrutinizer ignore-call */ with('subscriber')

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...
109
            ->willReturn($this->subscriber);
110
111
        $this->subscriber->expects($this->once())
112
            ->method('getData')
113
            ->with('customer_id')
114
            ->willReturn(123);
115
116
        $this->publisher->expects($this->never())
0 ignored issues
show
Bug introduced by
The method expects() does not exist on Magento\Framework\MessageQueue\PublisherInterface. ( Ignorable by Annotation )

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

116
        $this->publisher->/** @scrutinizer ignore-call */ 
117
                          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...
117
            ->method('publish');
118
119
        $this->exportContactObserver->execute($this->observer);
120
    }
121
122
    public function testExecute()
123
    {
124
        $email = '[email protected]';
125
126
        $this->configHelper->expects($this->once())
127
            ->method('isEnabled')
128
            ->willReturn(true);
129
130
        $this->configHelper->expects($this->once())
131
            ->method('isContactExportEnabled')
132
            ->willReturn(true);
133
134
        $this->observer->expects($this->once())
135
            ->method('getEvent')
136
            ->willReturn($this->event);
137
138
        $this->event->expects($this->once())
139
            ->method('getData')
140
            ->with('subscriber')
141
            ->willReturn($this->subscriber);
142
143
        $this->subscriber->expects($this->once())
144
            ->method('getData')
145
            ->with('customer_id')
146
            ->willReturn(null);
147
148
        $this->subscriber->expects($this->once())
149
            ->method('getEmail')
150
            ->willReturn($email);
151
152
        $this->publisher->expects($this->once())
153
            ->method('publish')
154
            ->with(
155
                Topics::NEWSLETTER_CONTACT_EXPORT,
156
                json_encode(['email' => $email])
157
            );
158
159
        $this->exportContactObserver->execute($this->observer);
160
    }
161
}
162