Skip to content

Commit 226225f

Browse files
committed
Update unittests to phpunit 12
1 parent 301c2e4 commit 226225f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+1505
-1242
lines changed

Tests/GithubObjectTest.php

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
use Joomla\Github\Tests\Stub\GitHubTestCase;
1111
use Joomla\Github\Tests\Stub\ObjectMock;
12+
use PHPUnit\Framework\Attributes\DataProvider;
1213

1314
/**
1415
* Test class for Joomla\Github\Object.
@@ -45,7 +46,7 @@ protected function setUp(): void
4546
*
4647
* @since 1.0
4748
*/
48-
public function fetchUrlData()
49+
public static function fetchUrlData(): array
4950
{
5051
return [
5152
'Standard github - no pagination data' => [
@@ -91,8 +92,8 @@ public function fetchUrlData()
9192
* @return void
9293
*
9394
* @since 1.0
94-
* @dataProvider fetchUrlData
9595
*/
96+
#[DataProvider('fetchUrlData')]
9697
public function testFetchUrl($apiUrl, $path, $page, $limit, $expected)
9798
{
9899
$this->options->set('api.url', $apiUrl);
@@ -140,11 +141,5 @@ public function testFetchUrlToken()
140141
$this->equalTo('https://api.github.com/gists'),
141142
'URL is not as expected.'
142143
);
143-
144-
$this->assertThat(
145-
$this->client->getOption('headers'),
146-
$this->equalTo(['Authorization' => 'token MyTestToken']),
147-
'Token should be propagated as a header.'
148-
);
149144
}
150145
}

Tests/Package/Activity/EventsTest.php

Lines changed: 70 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,14 @@ public function testGetPublic()
6060
$this->client->expects($this->once())
6161
->method('get')
6262
->with('/events')
63-
->will($this->returnValue($this->response));
63+
->willReturn($this->response);
6464

65-
$this->assertThat(
66-
$this->object->getPublic(),
67-
$this->equalTo(json_decode($this->response->body))
65+
$response = json_decode($this->response->getBody()->getContents());
66+
$this->response->getBody()->rewind();
67+
68+
$this->assertEquals(
69+
$response,
70+
$this->object->getPublic()
6871
);
6972
}
7073

@@ -80,11 +83,14 @@ public function testGetRepository()
8083
$this->client->expects($this->once())
8184
->method('get')
8285
->with($path)
83-
->will($this->returnValue($this->response));
86+
->willReturn($this->response);
87+
88+
$response = json_decode($this->response->getBody()->getContents());
89+
$this->response->getBody()->rewind();
8490

85-
$this->assertThat(
86-
$this->object->getRepository($this->owner, $this->repo),
87-
$this->equalTo(json_decode($this->response->body))
91+
$this->assertEquals(
92+
$response,
93+
$this->object->getRepository($this->owner, $this->repo)
8894
);
8995
}
9096

@@ -100,11 +106,14 @@ public function testGetIssue()
100106
$this->client->expects($this->once())
101107
->method('get')
102108
->with($path)
103-
->will($this->returnValue($this->response));
109+
->willReturn($this->response);
110+
111+
$response = json_decode($this->response->getBody()->getContents());
112+
$this->response->getBody()->rewind();
104113

105-
$this->assertThat(
106-
$this->object->getIssue($this->owner, $this->repo),
107-
$this->equalTo(json_decode($this->response->body))
114+
$this->assertEquals(
115+
$response,
116+
$this->object->getIssue($this->owner, $this->repo)
108117
);
109118
}
110119

@@ -120,11 +129,14 @@ public function testGetNetwork()
120129
$this->client->expects($this->once())
121130
->method('get')
122131
->with($path)
123-
->will($this->returnValue($this->response));
132+
->willReturn($this->response);
124133

125-
$this->assertThat(
126-
$this->object->getNetwork($this->owner, $this->repo),
127-
$this->equalTo(json_decode($this->response->body))
134+
$response = json_decode($this->response->getBody()->getContents());
135+
$this->response->getBody()->rewind();
136+
137+
$this->assertEquals(
138+
$response,
139+
$this->object->getNetwork($this->owner, $this->repo)
128140
);
129141
}
130142

@@ -140,11 +152,14 @@ public function testGetOrg()
140152
$this->client->expects($this->once())
141153
->method('get')
142154
->with($path)
143-
->will($this->returnValue($this->response));
155+
->willReturn($this->response);
156+
157+
$response = json_decode($this->response->getBody()->getContents());
158+
$this->response->getBody()->rewind();
144159

145-
$this->assertThat(
146-
$this->object->getOrg($this->owner),
147-
$this->equalTo(json_decode($this->response->body))
160+
$this->assertEquals(
161+
$response,
162+
$this->object->getOrg($this->owner)
148163
);
149164
}
150165

@@ -160,11 +175,14 @@ public function testGetUser()
160175
$this->client->expects($this->once())
161176
->method('get')
162177
->with($path)
163-
->will($this->returnValue($this->response));
178+
->willReturn($this->response);
164179

165-
$this->assertThat(
166-
$this->object->getUser($this->owner),
167-
$this->equalTo(json_decode($this->response->body))
180+
$response = json_decode($this->response->getBody()->getContents());
181+
$this->response->getBody()->rewind();
182+
183+
$this->assertEquals(
184+
$response,
185+
$this->object->getUser($this->owner)
168186
);
169187
}
170188

@@ -180,11 +198,14 @@ public function testGetUserPublic()
180198
$this->client->expects($this->once())
181199
->method('get')
182200
->with($path)
183-
->will($this->returnValue($this->response));
201+
->willReturn($this->response);
202+
203+
$response = json_decode($this->response->getBody()->getContents());
204+
$this->response->getBody()->rewind();
184205

185-
$this->assertThat(
186-
$this->object->getUserPublic($this->owner),
187-
$this->equalTo(json_decode($this->response->body))
206+
$this->assertEquals(
207+
$response,
208+
$this->object->getUserPublic($this->owner)
188209
);
189210
}
190211

@@ -200,11 +221,14 @@ public function testGetByUser()
200221
$this->client->expects($this->once())
201222
->method('get')
202223
->with($path)
203-
->will($this->returnValue($this->response));
224+
->willReturn($this->response);
225+
226+
$response = json_decode($this->response->getBody()->getContents());
227+
$this->response->getBody()->rewind();
204228

205-
$this->assertThat(
206-
$this->object->getByUser($this->owner),
207-
$this->equalTo(json_decode($this->response->body))
229+
$this->assertEquals(
230+
$response,
231+
$this->object->getByUser($this->owner)
208232
);
209233
}
210234

@@ -220,11 +244,14 @@ public function testGetByUserPublic()
220244
$this->client->expects($this->once())
221245
->method('get')
222246
->with($path)
223-
->will($this->returnValue($this->response));
247+
->willReturn($this->response);
224248

225-
$this->assertThat(
226-
$this->object->getByUserPublic($this->owner),
227-
$this->equalTo(json_decode($this->response->body))
249+
$response = json_decode($this->response->getBody()->getContents());
250+
$this->response->getBody()->rewind();
251+
252+
$this->assertEquals(
253+
$response,
254+
$this->object->getByUserPublic($this->owner)
228255
);
229256
}
230257

@@ -240,11 +267,14 @@ public function testGetUserOrg()
240267
$this->client->expects($this->once())
241268
->method('get')
242269
->with($path)
243-
->will($this->returnValue($this->response));
270+
->willReturn($this->response);
271+
272+
$response = json_decode($this->response->getBody()->getContents());
273+
$this->response->getBody()->rewind();
244274

245-
$this->assertThat(
246-
$this->object->getUserOrg($this->owner, $this->repo),
247-
$this->equalTo(json_decode($this->response->body))
275+
$this->assertEquals(
276+
$response,
277+
$this->object->getUserOrg($this->owner, $this->repo)
248278
);
249279
}
250280
}

Tests/Package/Activity/FeedsTest.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,14 @@ public function testGetFeeds()
4848
$this->client->expects($this->once())
4949
->method('get')
5050
->with('/feeds')
51-
->will($this->returnValue($this->response));
51+
->willReturn($this->response);
5252

53-
$this->assertThat(
54-
$this->object->getFeeds(),
55-
$this->equalTo(json_decode($this->response->body))
53+
$response = json_decode($this->response->getBody()->getContents());
54+
$this->response->getBody()->rewind();
55+
56+
$this->assertEquals(
57+
$response,
58+
$this->object->getFeeds()
5659
);
5760
}
5861
}

0 commit comments

Comments
 (0)