22
33namespace Mailjet \LaravelMailjet \Tests \Services ;
44
5- use Mockery \Container ;
5+ use Mailjet \Client ;
6+ use Mailjet \LaravelMailjet \Services \MailjetService ;
7+ use Mailjet \Resources ;
8+ use Mailjet \Response ;
9+ use Mockery ;
610use Orchestra \Testbench \TestCase ;
711
812class MailjetServiceTest extends TestCase
913{
14+ /**
15+ * @var Client|Mockery\LegacyMockInterface|Mockery\MockInterface
16+ */
17+ private $ mailjetClientMock ;
18+
19+ /**
20+ * @var MailjetService
21+ */
22+ private $ mailjetService ;
23+
1024 public function setUp ()
1125 {
1226 parent ::setUp ();
27+
28+ $ responseMock = $ this ->createMock (Response::class);
29+ $ responseMock ->method ('success ' )->willReturn (true );
30+
31+ $ this ->mailjetClientMock = Mockery::mock ('overload: ' . Client::class);
32+
33+ $ this ->mailjetClientMock
34+ ->shouldReceive ('put ' )
35+ ->andReturnUsing (function ($ resourceArg , $ params ) use ($ responseMock ) {
36+ $ data = [];
37+
38+ switch ($ resourceArg ) {
39+ case 'resource-test-put ' :
40+ $ data = array_merge ($ params , [
41+ 'status ' => '0003 ' ,
42+ ]);
43+ break ;
44+
45+ case Resources::$ Listrecipient :
46+ $ data = array_merge ($ params , [
47+ 'status ' => '0011 ' ,
48+ ]);
49+ break ;
50+ }
51+
52+ $ responseMock ->method ('getData ' )->willReturn ($ data );
53+
54+ return $ responseMock ;
55+ });
56+
57+ $ this ->mailjetClientMock
58+ ->shouldReceive ('post ' )
59+ ->andReturnUsing (function ($ resourceArg , $ params ) use ($ responseMock ) {
60+ $ data = [];
61+
62+ switch ($ resourceArg ) {
63+ case 'resource-test-post ' :
64+ $ data = array_merge ($ params , [
65+ 'status ' => '0001 ' ,
66+ ]);
67+ break ;
68+
69+ case Resources::$ Contactslist :
70+ $ data = array_merge ($ params , [
71+ 'status ' => '0006 ' ,
72+ ]);
73+ break ;
74+
75+ case Resources::$ Contact :
76+ $ data = array_merge ($ params , [
77+ 'status ' => '0009 ' ,
78+ ]);
79+ break ;
80+
81+ case Resources::$ Listrecipient :
82+ $ data = array_merge ($ params , [
83+ 'status ' => '0010 ' ,
84+ ]);
85+ break ;
86+
87+ }
88+
89+ $ responseMock ->method ('getData ' )->willReturn ($ data );
90+
91+ return $ responseMock ;
92+ });
93+
94+ $ this ->mailjetClientMock
95+ ->shouldReceive ('delete ' )
96+ ->andReturnUsing (function ($ resourceArg , $ params ) use ($ responseMock ) {
97+ $ data = [];
98+
99+ switch ($ resourceArg ) {
100+ case 'resource-test-delete ' :
101+ $ data = array_merge ($ params , [
102+ 'status ' => '0004 ' ,
103+ ]);
104+ break ;
105+ }
106+
107+ $ responseMock ->method ('getData ' )->willReturn ($ data );
108+
109+ return $ responseMock ;
110+ });
111+
112+ $ this ->mailjetClientMock
113+ ->shouldReceive ('get ' )
114+ ->andReturnUsing (function ($ resourceArg , $ params ) use ($ responseMock ) {
115+ $ data = [];
116+
117+ switch ($ resourceArg ) {
118+ case 'resource-test-get ' :
119+ $ data = array_merge ($ params , [
120+ 'status ' => '0002 ' ,
121+ ]);
122+ break ;
123+
124+ case Resources::$ Contactslist :
125+ $ data = array_merge ($ params , [
126+ 'status ' => '0005 ' ,
127+ ]);
128+ break ;
129+
130+ case Resources::$ Listrecipient :
131+ $ data = array_merge ($ params , [
132+ 'status ' => '0007 ' ,
133+ ]);
134+ break ;
135+
136+ case Resources::$ Contact :
137+ $ data = array_merge ($ params , [
138+ 'status ' => '0008 ' ,
139+ ]);
140+ break ;
141+ }
142+
143+ $ responseMock ->method ('getData ' )->willReturn ($ data );
144+
145+ return $ responseMock ;
146+ });
147+
148+ $ this ->mailjetService = $ this ->app ['Mailjet ' ];
13149 }
14150
15151 public function testFacade ()
16152 {
17- $ this ->assertTrue (method_exists ($ this ->app [ ' Mailjet ' ] , 'get ' ));
18- $ this ->assertTrue (method_exists ($ this ->app [ ' Mailjet ' ] , 'post ' ));
19- $ this ->assertTrue (method_exists ($ this ->app [ ' Mailjet ' ] , 'put ' ));
20- $ this ->assertTrue (method_exists ($ this ->app [ ' Mailjet ' ] , 'delete ' ));
21- $ this ->assertTrue (method_exists ($ this ->app [ ' Mailjet ' ] , 'getAllLists ' ));
22- $ this ->assertTrue (method_exists ($ this ->app [ ' Mailjet ' ] , 'createList ' ));
23- $ this ->assertTrue (method_exists ($ this ->app [ ' Mailjet ' ] , 'getListRecipients ' ));
24- $ this ->assertTrue (method_exists ($ this ->app [ ' Mailjet ' ] , 'getSingleContact ' ));
25- $ this ->assertTrue (method_exists ($ this ->app [ ' Mailjet ' ] , 'createContact ' ));
26- $ this ->assertTrue (method_exists ($ this ->app [ ' Mailjet ' ] , 'createListRecipient ' ));
27- $ this ->assertTrue (method_exists ($ this ->app [ ' Mailjet ' ] , 'editListrecipient ' ));
28- $ this ->assertTrue (method_exists ($ this ->app [ ' Mailjet ' ] , 'getClient ' ));
153+ $ this ->assertTrue (method_exists ($ this ->mailjetService , 'get ' ));
154+ $ this ->assertTrue (method_exists ($ this ->mailjetService , 'post ' ));
155+ $ this ->assertTrue (method_exists ($ this ->mailjetService , 'put ' ));
156+ $ this ->assertTrue (method_exists ($ this ->mailjetService , 'delete ' ));
157+ $ this ->assertTrue (method_exists ($ this ->mailjetService , 'getAllLists ' ));
158+ $ this ->assertTrue (method_exists ($ this ->mailjetService , 'createList ' ));
159+ $ this ->assertTrue (method_exists ($ this ->mailjetService , 'getListRecipients ' ));
160+ $ this ->assertTrue (method_exists ($ this ->mailjetService , 'getSingleContact ' ));
161+ $ this ->assertTrue (method_exists ($ this ->mailjetService , 'createContact ' ));
162+ $ this ->assertTrue (method_exists ($ this ->mailjetService , 'createListRecipient ' ));
163+ $ this ->assertTrue (method_exists ($ this ->mailjetService , 'editListrecipient ' ));
164+ $ this ->assertTrue (method_exists ($ this ->mailjetService , 'getClient ' ));
29165 }
30166
31167 public function testCanUseClient ()
@@ -34,7 +170,148 @@ public function testCanUseClient()
34170 $ this ->assertEquals ("Mailjet\Client " , get_class ($ client ));
35171 }
36172
173+ public function testPost ()
174+ {
175+ $ response = $ this ->mailjetService ->post ('resource-test-post ' , [
176+ 'data ' => 'test0001 ' ,
177+ ]);
178+
179+ $ this ->assertSame ([
180+ 'data ' => 'test0001 ' ,
181+ 'status ' => '0001 ' ,
182+ ], $ response ->getData ());
183+ }
184+
185+ public function testGet ()
186+ {
187+ $ response = $ this ->mailjetService ->get ('resource-test-get ' , [
188+ 'data ' => 'test0002 ' ,
189+ ], []);
37190
191+ $ this ->assertSame ([
192+ 'data ' => 'test0002 ' ,
193+ 'status ' => '0002 ' ,
194+ ], $ response ->getData ());
195+ }
196+
197+ public function testPut ()
198+ {
199+ $ response = $ this ->mailjetService ->put ('resource-test-put ' , [
200+ 'data ' => 'test0003 ' ,
201+ ], []);
202+
203+ $ this ->assertSame ([
204+ 'data ' => 'test0003 ' ,
205+ 'status ' => '0003 ' ,
206+ ], $ response ->getData ());
207+ }
208+
209+ public function testDelete ()
210+ {
211+ $ response = $ this ->mailjetService ->delete ('resource-test-delete ' , [
212+ 'data ' => 'test0004 ' ,
213+ ], []);
214+
215+ $ this ->assertSame ([
216+ 'data ' => 'test0004 ' ,
217+ 'status ' => '0004 ' ,
218+ ], $ response ->getData ());
219+ }
220+
221+ public function testGetAllLists ()
222+ {
223+ $ response = $ this ->mailjetService ->getAllLists ([
224+ 'data ' => 'test0005 ' ,
225+ ]);
226+
227+ $ this ->assertSame ([
228+ 'filters ' => [
229+ 'data ' => 'test0005 ' ,
230+ ],
231+ 'status ' => '0005 ' ,
232+ ], $ response ->getData ());
233+ }
234+
235+ public function testCreateList ()
236+ {
237+ $ response = $ this ->mailjetService ->createList ([
238+ 'data ' => 'test0006 '
239+ ]);
240+
241+ $ this ->assertSame ([
242+ 'body ' => [
243+ 'data ' => 'test0006 ' ,
244+ ],
245+ 'status ' => '0006 ' ,
246+ ], $ response ->getData ());
247+ }
248+
249+ public function testGetListRecipients ()
250+ {
251+ $ response = $ this ->mailjetService ->getListRecipients ([
252+ 'data ' => 'test0007 '
253+ ]);
254+
255+ $ this ->assertSame ([
256+ 'filters ' => [
257+ 'data ' => 'test0007 ' ,
258+ ],
259+ 'status ' => '0007 ' ,
260+ ], $ response ->getData ());
261+ }
262+
263+ public function testGetSingleContact ()
264+ {
265+ $ response = $ this ->mailjetService ->getSingleContact (123 );
266+
267+ $ this ->assertSame ([
268+ 'id ' => 123 ,
269+ 'status ' => '0008 ' ,
270+ ], $ response ->getData ());
271+ }
272+
273+ public function testCreateContact ()
274+ {
275+ $ response = $ this ->mailjetService ->createContact ([
276+ 'data ' => 'test0009 '
277+ ]);
278+
279+ $ this ->assertSame ([
280+ 'body ' => [
281+ 'data ' => 'test0009 ' ,
282+ ],
283+ 'status ' => '0009 ' ,
284+ ], $ response ->getData ());
285+ }
286+
287+ public function testCreateListRecipient ()
288+ {
289+ $ response = $ this ->mailjetService ->createListRecipient ([
290+ 'data ' => 'test0010 '
291+ ]);
292+
293+ $ this ->assertSame ([
294+ 'body ' => [
295+ 'data ' => 'test0010 ' ,
296+ ],
297+ 'status ' => '0010 ' ,
298+ ], $ response ->getData ());
299+ }
300+
301+ public function testEditListrecipient ()
302+ {
303+ $ response = $ this ->mailjetService ->editListrecipient (123 , [
304+ 'data ' => 'test0011 '
305+ ]);
306+
307+ $ this ->assertSame ([
308+ 'id ' => 123 ,
309+ 'body ' => [
310+ 'data ' => 'test0011 ' ,
311+ ],
312+ 'status ' => '0011 ' ,
313+ ], $ response ->getData ());
314+ }
38315
39316 protected function getPackageAliases ($ app )
40317 {
0 commit comments