@@ -55,7 +55,7 @@ public function testGetCurrentUserReturnsClientGetResponse()
5555 public function testGetIdByUsernameMakesGetRequest ()
5656 {
5757 // Test values
58- $ response = '{"users":[{"id":5,"login":"User 5 "}]} ' ;
58+ $ response = '{"users":[{"id":5,"login":"user_5 "}]} ' ;
5959
6060 // Create the used mock objects
6161 $ client = $ this ->createMock (Client::class);
@@ -79,8 +79,37 @@ public function testGetIdByUsernameMakesGetRequest()
7979 $ api = new User ($ client );
8080
8181 // Perform the tests
82- $ this ->assertFalse ($ api ->getIdByUsername ('User 1 ' ));
83- $ this ->assertSame (5 , $ api ->getIdByUsername ('User 5 ' ));
82+ $ this ->assertFalse ($ api ->getIdByUsername ('user_1 ' ));
83+ $ this ->assertSame (5 , $ api ->getIdByUsername ('user_5 ' ));
84+ }
85+
86+ public function testGetIdByUsernameTriggersDeprecationWarning ()
87+ {
88+ $ client = $ this ->createMock (Client::class);
89+ $ client ->method ('requestGet ' )
90+ ->willReturn (true );
91+ $ client ->method ('getLastResponseBody ' )
92+ ->willReturn ('{"users":[{"id":1,"login":"user_1"},{"id":5,"login":"user_5"}]} ' );
93+ $ client ->method ('getLastResponseContentType ' )
94+ ->willReturn ('application/json ' );
95+
96+ $ api = new User ($ client );
97+
98+ // PHPUnit 10 compatible way to test trigger_error().
99+ set_error_handler (
100+ function ($ errno , $ errstr ): bool {
101+ $ this ->assertSame (
102+ '`Redmine\Api\User::getIdByUsername()` is deprecated since v2.7.0, use `Redmine\Api\User::listLogins()` instead. ' ,
103+ $ errstr ,
104+ );
105+
106+ restore_error_handler ();
107+ return true ;
108+ },
109+ E_USER_DEPRECATED ,
110+ );
111+
112+ $ api ->getIdByUsername ('user_5 ' );
84113 }
85114
86115 /**
@@ -189,10 +218,10 @@ public function testAllReturnsClientGetResponseWithParameters()
189218 public function testListingReturnsNameIdArray ()
190219 {
191220 // Test values
192- $ response = '{"users":[{"id":1,"login":"User 1 "},{"id":5,"login":"User 5 "}]} ' ;
221+ $ response = '{"users":[{"id":1,"login":"user_1 "},{"id":5,"login":"user_5 "}]} ' ;
193222 $ expectedReturn = [
194- 'User 1 ' => 1 ,
195- 'User 5 ' => 5 ,
223+ 'user_1 ' => 1 ,
224+ 'user_5 ' => 5 ,
196225 ];
197226
198227 // Create the used mock objects
@@ -223,10 +252,10 @@ public function testListingReturnsNameIdArray()
223252 public function testListingCallsGetOnlyTheFirstTime ()
224253 {
225254 // Test values
226- $ response = '{"users":[{"id":1,"login":"User 1 "},{"id":5,"login":"User 5 "}]} ' ;
255+ $ response = '{"users":[{"id":1,"login":"user_1 "},{"id":5,"login":"user_5 "}]} ' ;
227256 $ expectedReturn = [
228- 'User 1 ' => 1 ,
229- 'User 5 ' => 5 ,
257+ 'user_1 ' => 1 ,
258+ 'user_5 ' => 5 ,
230259 ];
231260
232261 // Create the used mock objects
@@ -258,10 +287,10 @@ public function testListingCallsGetOnlyTheFirstTime()
258287 public function testListingCallsGetEveryTimeWithForceUpdate ()
259288 {
260289 // Test values
261- $ response = '{"users":[{"id":1,"login":"User 1 "},{"id":5,"login":"User 5 "}]} ' ;
290+ $ response = '{"users":[{"id":1,"login":"user_1 "},{"id":5,"login":"user_5 "}]} ' ;
262291 $ expectedReturn = [
263- 'User 1 ' => 1 ,
264- 'User 5 ' => 5 ,
292+ 'user_1 ' => 1 ,
293+ 'user_5 ' => 5 ,
265294 ];
266295
267296 // Create the used mock objects
0 commit comments