55use PHPUnit \Framework \Attributes \CoversClass ;
66use PHPUnit \Framework \TestCase ;
77use Redmine \Api \Issue ;
8- use Redmine \Client \Client ;
98use Redmine \Exception \UnexpectedResponseException ;
9+ use Redmine \Tests \Fixtures \AssertingHttpClient ;
1010
1111#[CoversClass(Issue::class)]
1212class ListTest extends TestCase
@@ -17,21 +17,21 @@ public function testListWithoutParametersReturnsResponse(): void
1717 $ response = '["API Response"] ' ;
1818 $ expectedReturn = ['API Response ' ];
1919
20- // Create the used mock objects
21- $ client = $ this -> createMock (Client::class);
22- $ client -> expects ( $ this -> once ())
23- -> method ( ' requestGet ' )
24- -> with ( '/issues.json ' )
25- -> willReturn ( true );
26- $ client -> expects ( $ this -> exactly ( 1 ))
27- -> method ( ' getLastResponseBody ' )
28- -> willReturn ( $ response );
29- $ client -> expects ( $ this -> exactly ( 1 ))
30- -> method ( ' getLastResponseContentType ' )
31- -> willReturn ( ' application/json ' );
20+ $ client = AssertingHttpClient:: create (
21+ $ this ,
22+ [
23+ ' GET ' ,
24+ '/issues.json ' ,
25+ ' application/json ' ,
26+ '' ,
27+ 200 ,
28+ ' application/json ' ,
29+ $ response ,
30+ ],
31+ );
3232
3333 // Create the object under test
34- $ api = new Issue ($ client );
34+ $ api = Issue:: fromHttpClient ($ client );
3535
3636 // Perform the tests
3737 $ this ->assertSame ($ expectedReturn , $ api ->list ());
@@ -44,43 +44,43 @@ public function testListWithParametersReturnsResponse(): void
4444 $ response = '["API Response"] ' ;
4545 $ expectedReturn = ['API Response ' ];
4646
47- // Create the used mock objects
48- $ client = $ this -> createMock (Client::class);
49- $ client -> expects ( $ this -> once ())
50- -> method ( ' requestGet ' )
51- -> with ( '/issues.json?limit=25&offset=0&0=not-used ' )
52- -> willReturn ( true );
53- $ client -> expects ( $ this -> exactly ( 1 ))
54- -> method ( ' getLastResponseBody ' )
55- -> willReturn ( $ response );
56- $ client -> expects ( $ this -> exactly ( 1 ))
57- -> method ( ' getLastResponseContentType ' )
58- -> willReturn ( ' application/json ' );
47+ $ client = AssertingHttpClient:: create (
48+ $ this ,
49+ [
50+ ' GET ' ,
51+ '/issues.json?limit=25&offset=0&0=not-used ' ,
52+ ' application/json ' ,
53+ '' ,
54+ 200 ,
55+ ' application/json ' ,
56+ $ response ,
57+ ],
58+ );
5959
6060 // Create the object under test
61- $ api = new Issue ($ client );
61+ $ api = Issue:: fromHttpClient ($ client );
6262
6363 // Perform the tests
6464 $ this ->assertSame ($ expectedReturn , $ api ->list ($ parameters ));
6565 }
6666
6767 public function testListThrowsException (): void
6868 {
69- // Create the used mock objects
70- $ client = $ this -> createMock (Client::class);
71- $ client -> expects ( $ this -> exactly ( 1 ))
72- -> method ( ' requestGet ' )
73- -> with ( '/issues.json ' )
74- -> willReturn ( true );
75- $ client -> expects ( $ this -> exactly ( 1 ))
76- -> method ( ' getLastResponseBody ' )
77- -> willReturn ( '' );
78- $ client -> expects ( $ this -> exactly ( 1 ))
79- -> method ( ' getLastResponseContentType ' )
80- -> willReturn ( ' application/json ' );
69+ $ client = AssertingHttpClient:: create (
70+ $ this ,
71+ [
72+ ' GET ' ,
73+ '/issues.json ' ,
74+ ' application/json ' ,
75+ '' ,
76+ 200 ,
77+ ' application/json ' ,
78+ '' ,
79+ ],
80+ );
8181
8282 // Create the object under test
83- $ api = new Issue ($ client );
83+ $ api = Issue:: fromHttpClient ($ client );
8484
8585 $ this ->expectException (UnexpectedResponseException::class);
8686 $ this ->expectExceptionMessage ('The Redmine server replied with an unexpected response. ' );
0 commit comments