@@ -128,4 +128,88 @@ public function testTitleIsSetCorrectly()
128128 $ this ->assertEquals ('setting title! ' , $ issue ->toArray ()['title ' ]);
129129 }
130130
131+ public function typeOfRequestProvider ()
132+ {
133+ return [
134+ ['availableReassignees ' , 'get ' ],
135+ ['availableStatuses ' , 'get ' ],
136+ ];
137+ }
138+
139+ /**
140+ * @dataProvider typeOfRequestProvider
141+ */
142+ public function testMethodsMakeCorrectTypeOfRequest ($ function , $ requestType )
143+ {
144+ $ responseMock = $ this ->getMockBuilder ('\GuzzleHttp\Message\Response ' )
145+ ->disableOriginalConstructor ()->getMock ();
146+ $ responseMock ->expects ($ this ->once ())->method ('json ' )
147+ ->willReturn ($ this ->returnValue (true ));
148+
149+ $ guzzleClientMock = $ this ->getMockBuilder ('\GuzzleHttp\Client ' )
150+ ->disableOriginalConstructor ()->getMock ();
151+ $ guzzleClientMock ->expects ($ this ->once ())->method ($ requestType )
152+ ->willReturn ($ responseMock );
153+
154+ $ client = new Client ('team ' , 'username ' , 'password ' );
155+ $ client ->setClient ($ guzzleClientMock );
156+
157+ $ client ->project (123 )->issue (111 )->$ function ();
158+ }
159+
160+ public function typeOfRequestWithArgumentProvider ()
161+ {
162+ return [
163+ ['addComment ' , 'post ' , new Comment ()],
164+ ['updateStatus ' , 'put ' , 1 ],
165+ ['updatePriorityLevel ' , 'put ' , 1 ],
166+ ['updateTester ' , 'put ' , 1 ],
167+ ['updateFixer ' , 'put ' , 1 ],
168+ ];
169+ }
170+
171+ /**
172+ * @dataProvider typeOfRequestWithArgumentProvider
173+ */
174+ public function testMethodsWithArgumentMakeCorrectTypeOfRequest (
175+ $ function ,
176+ $ requestType ,
177+ $ argument
178+ ) {
179+ $ responseMock = $ this ->getMockBuilder ('\GuzzleHttp\Message\Response ' )
180+ ->disableOriginalConstructor ()->getMock ();
181+ $ responseMock ->expects ($ this ->once ())->method ('json ' )
182+ ->willReturn ($ this ->returnValue (true ));
183+
184+ $ guzzleClientMock = $ this ->getMockBuilder ('\GuzzleHttp\Client ' )
185+ ->disableOriginalConstructor ()->getMock ();
186+ $ guzzleClientMock ->expects ($ this ->once ())->method ($ requestType )
187+ ->willReturn ($ responseMock );
188+
189+ $ client = new Client ('team ' , 'username ' , 'password ' );
190+ $ client ->setClient ($ guzzleClientMock );
191+
192+ $ client ->project (123 )->issue (182 )->$ function ($ argument );
193+ }
194+
195+ public function testUpdateMethodSendsCommentIfSet ()
196+ {
197+ $ responseMock = $ this ->getMockBuilder ('\GuzzleHttp\Message\Response ' )
198+ ->disableOriginalConstructor ()->getMock ();
199+ $ responseMock ->expects ($ this ->once ())->method ('json ' )
200+ ->willReturn ($ this ->returnValue (true ));
201+
202+ $ guzzleClientMock = $ this ->getMockBuilder ('\GuzzleHttp\Client ' )
203+ ->disableOriginalConstructor ()->getMock ();
204+ $ guzzleClientMock ->expects ($ this ->once ())->method ('put ' )
205+ ->with ($ this ->equalTo ('https://team.mydonedone.com/issuetracker/api/v2/projects/111/issues/321/fixer.json ' ), $ this ->equalTo (['body ' => ['new_fixer_id ' => 1 , 'comment ' => 'Comment! ' ]]))->willReturn ($ responseMock );
206+
207+ $ client = new Client ('team ' , 'username ' , 'password ' );
208+ $ client ->setClient ($ guzzleClientMock );
209+
210+ $ client ->project (111 )->issue (321 )->updateFixer (
211+ 1 , 'Comment! '
212+ );
213+ }
214+
131215}
0 commit comments