66use PHPUnit \Framework \Attributes \DataProviderExternal ;
77use PHPUnit \Framework \TestCase ;
88use Redmine \Api \Membership ;
9- use Redmine \Client \Client ;
109use Redmine \Exception \InvalidParameterException ;
1110use Redmine \Exception \UnexpectedResponseException ;
12- use Redmine \Tests \Fixtures \MockClient ;
11+ use Redmine \Http \HttpClient ;
12+ use Redmine \Tests \Fixtures \AssertingHttpClient ;
1313use Redmine \Tests \Fixtures \TestDataProvider ;
1414
1515#[CoversClass(Membership::class)]
@@ -21,21 +21,21 @@ public function testListByProjectWithoutParametersReturnsResponse(): void
2121 $ response = '["API Response"] ' ;
2222 $ expectedReturn = ['API Response ' ];
2323
24- // Create the used mock objects
25- $ client = $ this -> createMock (Client::class);
26- $ client -> expects ( $ this -> once ())
27- -> method ( ' requestGet ' )
28- -> with ( '/projects/5/memberships.json ' )
29- -> willReturn ( true );
30- $ client -> expects ( $ this -> exactly ( 1 ))
31- -> method ( ' getLastResponseBody ' )
32- -> willReturn ( $ response );
33- $ client -> expects ( $ this -> exactly ( 1 ))
34- -> method ( ' getLastResponseContentType ' )
35- -> willReturn ( ' application/json ' );
24+ $ client = AssertingHttpClient:: create (
25+ $ this ,
26+ [
27+ ' GET ' ,
28+ '/projects/5/memberships.json ' ,
29+ ' application/json ' ,
30+ '' ,
31+ 200 ,
32+ ' application/json ' ,
33+ $ response ,
34+ ],
35+ );
3636
3737 // Create the object under test
38- $ api = new Membership ($ client );
38+ $ api = Membership:: fromHttpClient ($ client );
3939
4040 // Perform the tests
4141 $ this ->assertSame ($ expectedReturn , $ api ->listByProject (5 ));
@@ -48,21 +48,21 @@ public function testListByProjectWithParametersReturnsResponse(): void
4848 $ response = '["API Response"] ' ;
4949 $ expectedReturn = ['API Response ' ];
5050
51- // Create the used mock objects
52- $ client = $ this -> createMock (Client::class);
53- $ client -> expects ( $ this -> once ())
54- -> method ( ' requestGet ' )
55- -> with ( '/projects/project-slug/memberships.json?limit=25&offset=0&0=not-used ' )
56- -> willReturn ( true );
57- $ client -> expects ( $ this -> exactly ( 1 ))
58- -> method ( ' getLastResponseBody ' )
59- -> willReturn ( $ response );
60- $ client -> expects ( $ this -> exactly ( 1 ))
61- -> method ( ' getLastResponseContentType ' )
62- -> willReturn ( ' application/json ' );
51+ $ client = AssertingHttpClient:: create (
52+ $ this ,
53+ [
54+ ' GET ' ,
55+ '/projects/project-slug/memberships.json?limit=25&offset=0&0=not-used ' ,
56+ ' application/json ' ,
57+ '' ,
58+ 200 ,
59+ ' application/json ' ,
60+ $ response ,
61+ ],
62+ );
6363
6464 // Create the object under test
65- $ api = new Membership ($ client );
65+ $ api = Membership:: fromHttpClient ($ client );
6666
6767 // Perform the tests
6868 $ this ->assertSame ($ expectedReturn , $ api ->listByProject ('project-slug ' , $ parameters ));
@@ -74,7 +74,7 @@ public function testListByProjectWithParametersReturnsResponse(): void
7474 #[DataProviderExternal(TestDataProvider::class, 'getInvalidProjectIdentifiers ' )]
7575 public function testListByProjectWithWrongProjectIdentifierThrowsException ($ projectIdentifier ): void
7676 {
77- $ api = new Membership (MockClient:: create ( ));
77+ $ api = Membership:: fromHttpClient ( $ this -> createStub (HttpClient::class ));
7878
7979 $ this ->expectException (InvalidParameterException::class);
8080 $ this ->expectExceptionMessage ('Redmine\Api\Membership::listByProject(): Argument #1 ($projectIdentifier) must be of type int or string ' );
@@ -84,21 +84,23 @@ public function testListByProjectWithWrongProjectIdentifierThrowsException($proj
8484
8585 public function testListByProjectThrowsException (): void
8686 {
87- // Create the used mock objects
88- $ client = $ this ->createMock (Client::class);
89- $ client ->expects ($ this ->exactly (1 ))
90- ->method ('requestGet ' )
91- ->with ('/projects/5/memberships.json ' )
92- ->willReturn (true );
93- $ client ->expects ($ this ->exactly (1 ))
94- ->method ('getLastResponseBody ' )
95- ->willReturn ('' );
96- $ client ->expects ($ this ->exactly (1 ))
97- ->method ('getLastResponseContentType ' )
98- ->willReturn ('application/json ' );
87+ $ response = '' ;
88+
89+ $ client = AssertingHttpClient::create (
90+ $ this ,
91+ [
92+ 'GET ' ,
93+ '/projects/5/memberships.json ' ,
94+ 'application/json ' ,
95+ '' ,
96+ 200 ,
97+ 'application/json ' ,
98+ $ response ,
99+ ],
100+ );
99101
100102 // Create the object under test
101- $ api = new Membership ($ client );
103+ $ api = Membership:: fromHttpClient ($ client );
102104
103105 $ this ->expectException (UnexpectedResponseException::class);
104106 $ this ->expectExceptionMessage ('The Redmine server replied with an unexpected response. ' );
0 commit comments