55use PHPUnit \Framework \Attributes \CoversClass ;
66use PHPUnit \Framework \TestCase ;
77use Redmine \Api \Role ;
8- use Redmine \Client \Client ;
98use Redmine \Exception \UnexpectedResponseException ;
9+ use Redmine \Tests \Fixtures \AssertingHttpClient ;
1010
1111#[CoversClass(Role::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 ( '/roles.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+ '/roles.json ' ,
25+ ' application/json ' ,
26+ '' ,
27+ 200 ,
28+ ' application/json ' ,
29+ $ response ,
30+ ],
31+ );
3232
3333 // Create the object under test
34- $ api = new Role ($ client );
34+ $ api = Role:: fromHttpClient ($ client );
3535
3636 // Perform the tests
3737 $ this ->assertSame ($ expectedReturn , $ api ->list ());
@@ -44,43 +44,45 @@ 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 ( '/roles.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+ '/roles.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 Role ($ client );
61+ $ api = Role:: 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 ('/roles.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+ $ response = '' ;
70+
71+ $ client = AssertingHttpClient::create (
72+ $ this ,
73+ [
74+ 'GET ' ,
75+ '/roles.json ' ,
76+ 'application/json ' ,
77+ '' ,
78+ 200 ,
79+ 'application/json ' ,
80+ $ response ,
81+ ],
82+ );
8183
8284 // Create the object under test
83- $ api = new Role ($ client );
85+ $ api = Role:: fromHttpClient ($ client );
8486
8587 $ this ->expectException (UnexpectedResponseException::class);
8688 $ this ->expectExceptionMessage ('The Redmine server replied with an unexpected response. ' );
0 commit comments