Skip to content

Commit a764598

Browse files
committed
refactor: use Issue::fromHttpClient() in tests
1 parent 53ac09d commit a764598

File tree

11 files changed

+63
-63
lines changed

11 files changed

+63
-63
lines changed

tests/Unit/Api/Issue/AddNoteToIssueTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public function testAddNoteToIssueReturnsCorrectResponse(int $id, string $note,
3333
);
3434

3535
// Create the object under test
36-
$api = new Issue($client);
36+
$api = Issue::fromHttpClient($client);
3737

3838
// Perform the tests
3939
$this->assertSame('', $api->addNoteToIssue($id, $note, $isPrivate));

tests/Unit/Api/Issue/AddWatcherTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public function testAddWatcherReturnsCorrectResponse(int $issueId, int $watcherU
3232
);
3333

3434
// Create the object under test
35-
$api = new Issue($client);
35+
$api = Issue::fromHttpClient($client);
3636

3737
// Perform the tests
3838
$return = $api->addWatcher($issueId, $watcherUserId);
@@ -74,7 +74,7 @@ public function testAddWatcherReturnsEmptyString(): void
7474
);
7575

7676
// Create the object under test
77-
$api = new Issue($client);
77+
$api = Issue::fromHttpClient($client);
7878

7979
// Perform the tests
8080
$return = $api->addWatcher(1, 2);

tests/Unit/Api/Issue/AttachManyTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public function testAttachManyReturnsCorrectResponse(int $issueId, array $parame
3131
);
3232

3333
// AttachMany the object under test
34-
$api = new Issue($client);
34+
$api = Issue::fromHttpClient($client);
3535

3636
// Perform the tests
3737
$this->assertSame('', $api->attachMany($issueId, $parameters));

tests/Unit/Api/Issue/CreateTest.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public function testCreateReturnsCorrectResponse(array $parameters, string $expe
3232
);
3333

3434
// Create the object under test
35-
$api = new Issue($client);
35+
$api = Issue::fromHttpClient($client);
3636

3737
// Perform the tests
3838
$return = $api->create($parameters);
@@ -248,7 +248,7 @@ public function testCreateReturnsEmptyString(): void
248248
);
249249

250250
// Create the object under test
251-
$api = new Issue($client);
251+
$api = Issue::fromHttpClient($client);
252252

253253
// Perform the tests
254254
$return = $api->create([]);
@@ -281,7 +281,7 @@ public function testCreateWithHttpClientRetrievesIssueStatusId(): void
281281
);
282282

283283
// Create the object under test
284-
$api = new Issue($client);
284+
$api = Issue::fromHttpClient($client);
285285

286286
// Perform the tests
287287
$xmlElement = $api->create(['status' => 'Status Name']);
@@ -318,7 +318,7 @@ public function testCreateWithHttpClientRetrievesProjectId(): void
318318
);
319319

320320
// Create the object under test
321-
$api = new Issue($client);
321+
$api = Issue::fromHttpClient($client);
322322

323323
// Perform the tests
324324
$xmlElement = $api->create(['project' => 'Project Name']);
@@ -355,7 +355,7 @@ public function testCreateWithHttpClientRetrievesIssueCategoryId(): void
355355
);
356356

357357
// Create the object under test
358-
$api = new Issue($client);
358+
$api = Issue::fromHttpClient($client);
359359

360360
// Perform the tests
361361
$xmlElement = $api->create(['project_id' => 3, 'category' => 'Category Name']);
@@ -392,7 +392,7 @@ public function testCreateWithHttpClientRetrievesTrackerId(): void
392392
);
393393

394394
// Create the object under test
395-
$api = new Issue($client);
395+
$api = Issue::fromHttpClient($client);
396396

397397
// Perform the tests
398398
$xmlElement = $api->create(['tracker' => 'Tracker Name']);
@@ -429,7 +429,7 @@ public function testCreateWithHttpClientRetrievesUserId(): void
429429
);
430430

431431
// Create the object under test
432-
$api = new Issue($client);
432+
$api = Issue::fromHttpClient($client);
433433

434434
// Perform the tests
435435
$xmlElement = $api->create(['assigned_to' => 'user_6', 'author' => 'user_5']);
@@ -524,7 +524,7 @@ public function testCreateWithClientCleansParameters(): void
524524
];
525525

526526
// Create the object under test
527-
$api = new Issue($client);
527+
$api = Issue::fromHttpClient($client);
528528

529529
// Perform the tests
530530
$xmlElement = $api->create($parameters);

tests/Unit/Api/Issue/ListTest.php

Lines changed: 40 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
use PHPUnit\Framework\Attributes\CoversClass;
66
use PHPUnit\Framework\TestCase;
77
use Redmine\Api\Issue;
8-
use Redmine\Client\Client;
98
use Redmine\Exception\UnexpectedResponseException;
9+
use Redmine\Tests\Fixtures\AssertingHttpClient;
1010

1111
#[CoversClass(Issue::class)]
1212
class 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.');

tests/Unit/Api/Issue/RemoveTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public function testRemoveReturnsCorrectResponse(int $issueId, string $expectedP
3131
);
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($response, $api->remove($issueId));

tests/Unit/Api/Issue/RemoveWatcherTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public function testRemoveWatcherReturnsCorrectResponse(int $issueId, int $watch
3131
);
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($response, $api->removeWatcher($issueId, $watcherUserId));

tests/Unit/Api/Issue/SetIssueStatusTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public function testSetIssueStatusReturnsCorrectResponse(): void
3535
);
3636

3737
// Create the object under test
38-
$api = new Issue($client);
38+
$api = Issue::fromHttpClient($client);
3939

4040
// Perform the tests
4141
$this->assertSame('', $api->setIssueStatus(5, 'Status Name'));

tests/Unit/Api/Issue/ShowTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public function testShowReturnsCorrectResponse($issueId, array $params, string $
3131
);
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->show($issueId, $params));

tests/Unit/Api/Issue/UpdateTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public function testUpdateReturnsCorrectResponse(int $id, array $parameters, str
3333
);
3434

3535
// Create the object under test
36-
$api = new Issue($client);
36+
$api = Issue::fromHttpClient($client);
3737

3838
// Perform the tests
3939
$this->assertSame('', $api->update($id, $parameters));
@@ -194,7 +194,7 @@ public function testUpdateCleansParameters(): void
194194
];
195195

196196
// Create the object under test
197-
$api = new Issue($client);
197+
$api = Issue::fromHttpClient($client);
198198

199199
// Perform the tests
200200
$this->assertSame('', $api->update(70, $parameters));

0 commit comments

Comments
 (0)