1 | <?php |
||||||
2 | /** |
||||||
3 | */ |
||||||
4 | |||||||
5 | namespace CommerceLeague\ActiveCampaign\Test\Unit\Model\ActiveCampaign; |
||||||
6 | |||||||
7 | use CommerceLeague\ActiveCampaign\Api\Data\ContactInterface; |
||||||
8 | use CommerceLeague\ActiveCampaign\Model\ActiveCampaign\Contact; |
||||||
9 | use CommerceLeague\ActiveCampaign\Model\ActiveCampaign\ContactRepository; |
||||||
10 | use Magento\Framework\Exception\CouldNotDeleteException; |
||||||
11 | use Magento\Framework\Exception\CouldNotSaveException; |
||||||
12 | use Magento\Framework\Exception\NoSuchEntityException; |
||||||
13 | use PHPUnit\Framework\MockObject\MockObject; |
||||||
14 | use PHPUnit\Framework\TestCase; |
||||||
15 | use CommerceLeague\ActiveCampaign\Model\ResourceModel\ActiveCampaign\Contact as ContactResource; |
||||||
16 | use CommerceLeague\ActiveCampaign\Model\ActiveCampaign\ContactFactory; |
||||||
0 ignored issues
–
show
|
|||||||
17 | |||||||
18 | class ContactRepositoryTest extends TestCase |
||||||
19 | { |
||||||
20 | /** |
||||||
21 | * @var MockObject|ContactResource |
||||||
22 | */ |
||||||
23 | protected $contactResource; |
||||||
24 | |||||||
25 | /** |
||||||
26 | * @var MockObject|Contact |
||||||
27 | */ |
||||||
28 | protected $contact; |
||||||
29 | |||||||
30 | /** |
||||||
31 | * @var MockObject|ContactFactory |
||||||
32 | */ |
||||||
33 | protected $contactFactory; |
||||||
34 | |||||||
35 | /** |
||||||
36 | * @var ContactRepository |
||||||
37 | */ |
||||||
38 | protected $contactRepository; |
||||||
39 | |||||||
40 | protected function setUp() |
||||||
41 | { |
||||||
42 | $this->contactResource = $this->getMockBuilder(ContactResource::class) |
||||||
43 | ->disableOriginalConstructor() |
||||||
44 | ->getMock(); |
||||||
45 | |||||||
46 | $this->contactFactory = $this->getMockBuilder(ContactFactory::class) |
||||||
47 | ->disableOriginalConstructor() |
||||||
48 | ->setMethods(['create']) |
||||||
49 | ->getMock(); |
||||||
50 | |||||||
51 | $this->contact = $this->getMockBuilder(Contact::class) |
||||||
52 | ->disableOriginalConstructor() |
||||||
53 | ->getMock(); |
||||||
54 | |||||||
55 | $this->contactFactory->expects($this->any()) |
||||||
56 | ->method('create') |
||||||
57 | ->willReturn($this->contact); |
||||||
58 | |||||||
59 | $this->contactRepository = new ContactRepository( |
||||||
60 | $this->contactResource, |
||||||
61 | $this->contactFactory |
||||||
62 | ); |
||||||
63 | } |
||||||
64 | |||||||
65 | public function testSaveThrowsException() |
||||||
66 | { |
||||||
67 | $this->contactResource->expects($this->once()) |
||||||
0 ignored issues
–
show
The method
expects() does not exist on CommerceLeague\ActiveCam...\ActiveCampaign\Contact .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
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...
|
|||||||
68 | ->method('save') |
||||||
69 | ->with($this->contact) |
||||||
70 | ->willThrowException(new \Exception('an exception message')); |
||||||
71 | |||||||
72 | $this->expectException(CouldNotSaveException::class); |
||||||
73 | $this->expectExceptionMessage('an exception message'); |
||||||
74 | |||||||
75 | $this->contactRepository->save($this->contact); |
||||||
76 | } |
||||||
77 | |||||||
78 | public function testSave() |
||||||
79 | { |
||||||
80 | $this->contactResource->expects($this->once()) |
||||||
81 | ->method('save') |
||||||
82 | ->with($this->contact) |
||||||
83 | ->willReturnSelf(); |
||||||
84 | |||||||
85 | $this->assertSame($this->contact, $this->contactRepository->save($this->contact)); |
||||||
86 | } |
||||||
87 | |||||||
88 | public function testGetById() |
||||||
89 | { |
||||||
90 | $entityId = 123; |
||||||
91 | |||||||
92 | $this->contactResource->expects($this->once()) |
||||||
93 | ->method('load') |
||||||
94 | ->with($this->contact, $entityId) |
||||||
95 | ->willReturn($this->contact); |
||||||
96 | |||||||
97 | $this->assertSame($this->contact, $this->contactRepository->getById($entityId)); |
||||||
98 | } |
||||||
99 | |||||||
100 | public function testGetByEmail() |
||||||
101 | { |
||||||
102 | $email = '[email protected]'; |
||||||
103 | |||||||
104 | $this->contactResource->expects($this->once()) |
||||||
105 | ->method('load') |
||||||
106 | ->with($this->contact, $email, ContactInterface::EMAIL) |
||||||
107 | ->willReturn($this->contact); |
||||||
108 | |||||||
109 | $this->assertSame($this->contact, $this->contactRepository->getByEmail($email)); |
||||||
110 | } |
||||||
111 | |||||||
112 | public function testGetOrCreateByEmailWithKnownContact() |
||||||
113 | { |
||||||
114 | $email = '[email protected]'; |
||||||
115 | |||||||
116 | $this->contactResource->expects($this->once()) |
||||||
117 | ->method('load') |
||||||
118 | ->with($this->contact, $email, ContactInterface::EMAIL) |
||||||
119 | ->willReturn($this->contact); |
||||||
120 | |||||||
121 | $this->contact->expects($this->once()) |
||||||
0 ignored issues
–
show
The method
expects() does not exist on CommerceLeague\ActiveCam...\ActiveCampaign\Contact . Since you implemented __call , consider adding a @method annotation.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||||
122 | ->method('getId') |
||||||
0 ignored issues
–
show
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
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...
The method
method() does not exist on CommerceLeague\ActiveCam...\ActiveCampaign\Contact . Since you implemented __call , consider adding a @method annotation.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||||
123 | ->willReturn(123); |
||||||
0 ignored issues
–
show
The method
willReturn() does not exist on CommerceLeague\ActiveCam...\ActiveCampaign\Contact . Since you implemented __call , consider adding a @method annotation.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
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
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...
|
|||||||
124 | |||||||
125 | $this->contact->expects($this->never()) |
||||||
126 | ->method('setEmail'); |
||||||
127 | |||||||
128 | $this->assertSame($this->contact, $this->contactRepository->getOrCreateByEmail($email)); |
||||||
129 | } |
||||||
130 | |||||||
131 | public function testGetOrCreateByEmail() |
||||||
132 | { |
||||||
133 | $email = '[email protected]'; |
||||||
134 | |||||||
135 | $this->contactResource->expects($this->once()) |
||||||
136 | ->method('load') |
||||||
137 | ->with($this->contact, $email, ContactInterface::EMAIL) |
||||||
138 | ->willReturn($this->contact); |
||||||
139 | |||||||
140 | $this->contact->expects($this->once()) |
||||||
141 | ->method('getId') |
||||||
142 | ->willReturn(null); |
||||||
143 | |||||||
144 | $this->contact->expects($this->once()) |
||||||
145 | ->method('setEmail') |
||||||
146 | ->with($email) |
||||||
0 ignored issues
–
show
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
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...
The method
with() does not exist on CommerceLeague\ActiveCam...\ActiveCampaign\Contact . Since you implemented __call , consider adding a @method annotation.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||||
147 | ->willReturnSelf(); |
||||||
0 ignored issues
–
show
The method
willReturnSelf() 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
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...
The method
willReturnSelf() does not exist on CommerceLeague\ActiveCam...\ActiveCampaign\Contact . Since you implemented __call , consider adding a @method annotation.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||||
148 | |||||||
149 | $this->contactResource->expects($this->once()) |
||||||
150 | ->method('save') |
||||||
151 | ->with($this->contact) |
||||||
152 | ->willReturn($this->contact); |
||||||
153 | |||||||
154 | $this->assertSame($this->contact, $this->contactRepository->getOrCreateByEmail($email)); |
||||||
155 | } |
||||||
156 | |||||||
157 | public function testDeleteThrowsException() |
||||||
158 | { |
||||||
159 | $this->contactResource->expects($this->once()) |
||||||
160 | ->method('delete') |
||||||
161 | ->with($this->contact) |
||||||
162 | ->willThrowException(new \Exception('an exception message')); |
||||||
163 | |||||||
164 | $this->expectException(CouldNotDeleteException::class); |
||||||
165 | $this->expectExceptionMessage('an exception message'); |
||||||
166 | |||||||
167 | $this->contactRepository->delete($this->contact); |
||||||
168 | } |
||||||
169 | |||||||
170 | public function testDelete() |
||||||
171 | { |
||||||
172 | $this->contactResource->expects($this->once()) |
||||||
173 | ->method('delete') |
||||||
174 | ->with($this->contact) |
||||||
175 | ->willReturnSelf(); |
||||||
176 | |||||||
177 | $this->assertTrue($this->contactRepository->delete($this->contact)); |
||||||
178 | } |
||||||
179 | |||||||
180 | public function testDeleteByIdThrowsException() |
||||||
181 | { |
||||||
182 | $entityId = 123; |
||||||
183 | |||||||
184 | $this->contact->expects($this->once()) |
||||||
185 | ->method('getId') |
||||||
186 | ->willReturn(null); |
||||||
187 | |||||||
188 | $this->contactResource->expects($this->once()) |
||||||
189 | ->method('load') |
||||||
190 | ->with($this->contact, $entityId) |
||||||
191 | ->willReturn($this->contact); |
||||||
192 | |||||||
193 | $this->contactResource->expects($this->never()) |
||||||
194 | ->method('delete'); |
||||||
195 | |||||||
196 | $this->expectException(NoSuchEntityException::class); |
||||||
197 | $this->expectExceptionMessage('The Contact with the "123" ID doesn\'t exist'); |
||||||
198 | |||||||
199 | $this->contactRepository->deleteById($entityId); |
||||||
200 | } |
||||||
201 | |||||||
202 | public function testDeleteById() |
||||||
203 | { |
||||||
204 | $entityId = 123; |
||||||
205 | |||||||
206 | $this->contact->expects($this->once()) |
||||||
207 | ->method('getId') |
||||||
208 | ->willReturn($entityId); |
||||||
209 | |||||||
210 | $this->contactResource->expects($this->once()) |
||||||
211 | ->method('load') |
||||||
212 | ->with($this->contact, $entityId) |
||||||
213 | ->willReturn($this->contact); |
||||||
214 | |||||||
215 | $this->contactResource->expects($this->once()) |
||||||
216 | ->method('delete') |
||||||
217 | ->with($this->contact) |
||||||
218 | ->willReturnSelf(); |
||||||
219 | |||||||
220 | $this->assertTrue($this->contactRepository->deleteById($entityId)); |
||||||
221 | } |
||||||
222 | } |
||||||
223 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths