diff --git a/.gitattributes b/.gitattributes index 839fec09..0f255e23 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,6 +1,7 @@ .github/ export-ignore -build/ export-ignore +docs/ export-ignore Tests/ export-ignore +.editorconfig export-ignore .gitattributes export-ignore .gitignore export-ignore phpstan.neon export-ignore diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 09649838..5e0e34ee 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -12,4 +12,4 @@ concurrency: jobs: framework-ci: - uses: joomla-framework/.github/.github/workflows/workflow-v3.yml@main + uses: joomla-framework/.github/.github/workflows/workflow-v4.yml@main diff --git a/README.md b/README.md index 5952754a..465c9b88 100644 --- a/README.md +++ b/README.md @@ -753,12 +753,12 @@ The following resources contain more information: [Joomla! API Reference](http: ## Installation via Composer -Add `"joomla/github": "~2.0"` to the require block in your composer.json and then run `composer install`. +Add `"joomla/github": "~4.0"` to the require block in your composer.json and then run `composer install`. ```json { "require": { - "joomla/github": "~2.0" + "joomla/github": "~4.0" } } ``` @@ -766,11 +766,11 @@ Add `"joomla/github": "~2.0"` to the require block in your composer.json and the Alternatively, you can simply run the following from the command line: ```sh -composer require joomla/github "~2.0" +composer require joomla/github "~4.0" ``` If you want to include the test sources, use ```sh -composer require --prefer-source joomla/github "~2.0" +composer require --prefer-source joomla/github "~4.0" ``` diff --git a/SECURITY.md b/SECURITY.md index 4574d2ad..c7725547 100644 --- a/SECURITY.md +++ b/SECURITY.md @@ -5,7 +5,9 @@ These versions are currently being supported with security updates: | Version | Supported | -| ------- | ------------------ | +|---------| ------------------ | +| 4.x.x | :white_check_mark: | +| 3.x.x | :white_check_mark: | | 2.0.x | :white_check_mark: | | 1.7.x | :white_check_mark: | | < 1.7 | :x: | diff --git a/Tests/GithubObjectTest.php b/Tests/GithubObjectTest.php index 43bf0795..de9d5129 100755 --- a/Tests/GithubObjectTest.php +++ b/Tests/GithubObjectTest.php @@ -9,6 +9,7 @@ use Joomla\Github\Tests\Stub\GitHubTestCase; use Joomla\Github\Tests\Stub\ObjectMock; +use PHPUnit\Framework\Attributes\DataProvider; /** * Test class for Joomla\Github\Object. @@ -45,7 +46,7 @@ protected function setUp(): void * * @since 1.0 */ - public function fetchUrlData() + public static function fetchUrlData(): array { return [ 'Standard github - no pagination data' => [ @@ -91,8 +92,8 @@ public function fetchUrlData() * @return void * * @since 1.0 - * @dataProvider fetchUrlData */ + #[DataProvider('fetchUrlData')] public function testFetchUrl($apiUrl, $path, $page, $limit, $expected) { $this->options->set('api.url', $apiUrl); @@ -140,11 +141,5 @@ public function testFetchUrlToken() $this->equalTo('https://api.github.com/gists'), 'URL is not as expected.' ); - - $this->assertThat( - $this->client->getOption('headers'), - $this->equalTo(['Authorization' => 'token MyTestToken']), - 'Token should be propagated as a header.' - ); } } diff --git a/Tests/Package/Activity/EventsTest.php b/Tests/Package/Activity/EventsTest.php index 1e39801c..f71207bd 100644 --- a/Tests/Package/Activity/EventsTest.php +++ b/Tests/Package/Activity/EventsTest.php @@ -5,7 +5,7 @@ * @license GNU General Public License version 2 or later; see LICENSE */ -namespace Joomla\Github\Tests; +namespace Joomla\Github\Tests\Package\Activity; use Joomla\Github\Package\Activity\Events; use Joomla\Github\Tests\Stub\GitHubTestCase; @@ -60,11 +60,13 @@ public function testGetPublic() $this->client->expects($this->once()) ->method('get') ->with('/events') - ->will($this->returnValue($this->response)); + ->willReturn($this->response); - $this->assertThat( - $this->object->getPublic(), - $this->equalTo(json_decode($this->response->body)) + $response = json_decode((string) $this->response->getBody()); + + $this->assertEquals( + $response, + $this->object->getPublic() ); } @@ -80,11 +82,13 @@ public function testGetRepository() $this->client->expects($this->once()) ->method('get') ->with($path) - ->will($this->returnValue($this->response)); + ->willReturn($this->response); + + $response = json_decode((string) $this->response->getBody()); - $this->assertThat( - $this->object->getRepository($this->owner, $this->repo), - $this->equalTo(json_decode($this->response->body)) + $this->assertEquals( + $response, + $this->object->getRepository($this->owner, $this->repo) ); } @@ -100,11 +104,13 @@ public function testGetIssue() $this->client->expects($this->once()) ->method('get') ->with($path) - ->will($this->returnValue($this->response)); + ->willReturn($this->response); + + $response = json_decode((string) $this->response->getBody()); - $this->assertThat( - $this->object->getIssue($this->owner, $this->repo), - $this->equalTo(json_decode($this->response->body)) + $this->assertEquals( + $response, + $this->object->getIssue($this->owner, $this->repo) ); } @@ -120,11 +126,13 @@ public function testGetNetwork() $this->client->expects($this->once()) ->method('get') ->with($path) - ->will($this->returnValue($this->response)); + ->willReturn($this->response); - $this->assertThat( - $this->object->getNetwork($this->owner, $this->repo), - $this->equalTo(json_decode($this->response->body)) + $response = json_decode((string) $this->response->getBody()); + + $this->assertEquals( + $response, + $this->object->getNetwork($this->owner, $this->repo) ); } @@ -140,11 +148,13 @@ public function testGetOrg() $this->client->expects($this->once()) ->method('get') ->with($path) - ->will($this->returnValue($this->response)); + ->willReturn($this->response); + + $response = json_decode((string) $this->response->getBody()); - $this->assertThat( - $this->object->getOrg($this->owner), - $this->equalTo(json_decode($this->response->body)) + $this->assertEquals( + $response, + $this->object->getOrg($this->owner) ); } @@ -160,11 +170,13 @@ public function testGetUser() $this->client->expects($this->once()) ->method('get') ->with($path) - ->will($this->returnValue($this->response)); + ->willReturn($this->response); - $this->assertThat( - $this->object->getUser($this->owner), - $this->equalTo(json_decode($this->response->body)) + $response = json_decode((string) $this->response->getBody()); + + $this->assertEquals( + $response, + $this->object->getUser($this->owner) ); } @@ -180,11 +192,13 @@ public function testGetUserPublic() $this->client->expects($this->once()) ->method('get') ->with($path) - ->will($this->returnValue($this->response)); + ->willReturn($this->response); + + $response = json_decode((string) $this->response->getBody()); - $this->assertThat( - $this->object->getUserPublic($this->owner), - $this->equalTo(json_decode($this->response->body)) + $this->assertEquals( + $response, + $this->object->getUserPublic($this->owner) ); } @@ -200,11 +214,13 @@ public function testGetByUser() $this->client->expects($this->once()) ->method('get') ->with($path) - ->will($this->returnValue($this->response)); + ->willReturn($this->response); + + $response = json_decode((string) $this->response->getBody()); - $this->assertThat( - $this->object->getByUser($this->owner), - $this->equalTo(json_decode($this->response->body)) + $this->assertEquals( + $response, + $this->object->getByUser($this->owner) ); } @@ -220,11 +236,13 @@ public function testGetByUserPublic() $this->client->expects($this->once()) ->method('get') ->with($path) - ->will($this->returnValue($this->response)); + ->willReturn($this->response); - $this->assertThat( - $this->object->getByUserPublic($this->owner), - $this->equalTo(json_decode($this->response->body)) + $response = json_decode((string) $this->response->getBody()); + + $this->assertEquals( + $response, + $this->object->getByUserPublic($this->owner) ); } @@ -240,11 +258,13 @@ public function testGetUserOrg() $this->client->expects($this->once()) ->method('get') ->with($path) - ->will($this->returnValue($this->response)); + ->willReturn($this->response); + + $response = json_decode((string) $this->response->getBody()); - $this->assertThat( - $this->object->getUserOrg($this->owner, $this->repo), - $this->equalTo(json_decode($this->response->body)) + $this->assertEquals( + $response, + $this->object->getUserOrg($this->owner, $this->repo) ); } } diff --git a/Tests/Package/Activity/FeedsTest.php b/Tests/Package/Activity/FeedsTest.php index 173c7010..10c071eb 100644 --- a/Tests/Package/Activity/FeedsTest.php +++ b/Tests/Package/Activity/FeedsTest.php @@ -48,11 +48,13 @@ public function testGetFeeds() $this->client->expects($this->once()) ->method('get') ->with('/feeds') - ->will($this->returnValue($this->response)); + ->willReturn($this->response); - $this->assertThat( - $this->object->getFeeds(), - $this->equalTo(json_decode($this->response->body)) + $response = json_decode((string) $this->response->getBody()); + + $this->assertEquals( + $response, + $this->object->getFeeds() ); } } diff --git a/Tests/Package/Activity/NotificationsTest.php b/Tests/Package/Activity/NotificationsTest.php index 66d06e7b..14a03e8c 100644 --- a/Tests/Package/Activity/NotificationsTest.php +++ b/Tests/Package/Activity/NotificationsTest.php @@ -5,7 +5,7 @@ * @license GNU General Public License version 2 or later; see LICENSE */ -namespace Joomla\Github\Tests; +namespace Joomla\Github\Tests\Package\Activity; use Joomla\Github\Package\Activity\Notifications; use Joomla\Github\Tests\Stub\GitHubTestCase; @@ -52,11 +52,13 @@ public function testGetList() $this->client->expects($this->once()) ->method('get') ->with('/notifications?all=1&participating=1&since=2005-08-17T00:00:00+00:00&before=2005-08-17T00:00:00+00:00', [], 0) - ->will($this->returnValue($this->response)); + ->willReturn($this->response); - $this->assertThat( - $this->object->getList(true, true, new \DateTime('2005-8-17', new \DateTimeZone('UTC')), new \DateTime('2005-8-17', new \DateTimeZone('UTC'))), - $this->equalTo(json_decode($this->response->body)) + $response = json_decode((string) $this->response->getBody()); + + $this->assertEquals( + $response, + $this->object->getList(true, true, new \DateTime('2005-8-17', new \DateTimeZone('UTC')), new \DateTime('2005-8-17', new \DateTimeZone('UTC'))) ); } @@ -74,9 +76,12 @@ public function testGetListRepository() $this->client->expects($this->once()) ->method('get') ->with('/repos/{owner}/{repo}/notifications?' . $args, [], 0) - ->will($this->returnValue($this->response)); + ->willReturn($this->response); + + $response = json_decode((string) $this->response->getBody()); - $this->assertThat( + $this->assertEquals( + $response, $this->object->getListRepository( '{owner}', '{repo}', @@ -84,8 +89,7 @@ public function testGetListRepository() true, new \DateTime('2005-8-17', new \DateTimeZone('UTC')), new \DateTime('2005-8-17', new \DateTimeZone('UTC')) - ), - $this->equalTo(json_decode($this->response->body)) + ) ); } @@ -98,17 +102,18 @@ public function testGetListRepository() */ public function testMarkRead() { - $this->response->code = 205; - $this->response->body = ''; + $this->response = $this->getResponseObject('', 205); $this->client->expects($this->once()) ->method('put') ->with('/notifications', '{"unread":true,"read":true}', [], 0) - ->will($this->returnValue($this->response)); + ->willReturn($this->response); + + $response = (string) $this->response->getBody(); - $this->assertThat( - $this->object->markRead(), - $this->equalTo($this->response->body) + $this->assertEquals( + $response, + $this->object->markRead() ); } @@ -121,8 +126,7 @@ public function testMarkRead() */ public function testMarkReadLastRead() { - $this->response->code = 205; - $this->response->body = ''; + $this->response = $this->getResponseObject('', 205); $date = new \DateTime('1966-09-14', new \DateTimeZone('UTC')); $data = '{"unread":true,"read":true,"last_read_at":"1966-09-14T00:00:00+00:00"}'; @@ -130,11 +134,13 @@ public function testMarkReadLastRead() $this->client->expects($this->once()) ->method('put') ->with('/notifications', $data, [], 0) - ->will($this->returnValue($this->response)); + ->willReturn($this->response); - $this->assertThat( - $this->object->markRead(true, true, $date), - $this->equalTo($this->response->body) + $response = (string) $this->response->getBody(); + + $this->assertEquals( + $response, + $this->object->markRead(true, true, $date) ); } @@ -147,19 +153,20 @@ public function testMarkReadLastRead() */ public function testMarkReadRepository() { - $this->response->code = 205; - $this->response->body = ''; + $this->response = $this->getResponseObject('', 205); $data = '{"unread":true,"read":true}'; $this->client->expects($this->once()) ->method('put') ->with('/repos/joomla/joomla-platform/notifications', $data, [], 0) - ->will($this->returnValue($this->response)); + ->willReturn($this->response); + + $response = (string) $this->response->getBody(); - $this->assertThat( - $this->object->markReadRepository('joomla', 'joomla-platform', true, true), - $this->equalTo($this->response->body) + $this->assertEquals( + $response, + $this->object->markReadRepository('joomla', 'joomla-platform', true, true) ); } @@ -172,8 +179,7 @@ public function testMarkReadRepository() */ public function testMarkReadRepositoryLastRead() { - $this->response->code = 205; - $this->response->body = ''; + $this->response = $this->getResponseObject('', 205); $date = new \DateTime('1966-09-14', new \DateTimeZone('UTC')); $data = '{"unread":true,"read":true,"last_read_at":"1966-09-14T00:00:00+00:00"}'; @@ -181,11 +187,13 @@ public function testMarkReadRepositoryLastRead() $this->client->expects($this->once()) ->method('put') ->with('/repos/joomla/joomla-platform/notifications', $data, [], 0) - ->will($this->returnValue($this->response)); + ->willReturn($this->response); + + $response = (string) $this->response->getBody(); - $this->assertThat( - $this->object->markReadRepository('joomla', 'joomla-platform', true, true, $date), - $this->equalTo($this->response->body) + $this->assertEquals( + $response, + $this->object->markReadRepository('joomla', 'joomla-platform', true, true, $date) ); } @@ -201,11 +209,13 @@ public function testViewThread() $this->client->expects($this->once()) ->method('get') ->with('/notifications/threads/1', [], 0) - ->will($this->returnValue($this->response)); + ->willReturn($this->response); - $this->assertThat( - $this->object->viewThread(1), - $this->equalTo(json_decode($this->response->body)) + $response = json_decode((string) $this->response->getBody()); + + $this->assertEquals( + $response, + $this->object->viewThread(1) ); } @@ -218,16 +228,18 @@ public function testViewThread() */ public function testMarkReadThread() { - $this->response->code = 205; + $this->response = $this->getResponseObject($this->sampleString, 205); $this->client->expects($this->once()) ->method('patch') ->with('/notifications/threads/1', '{"unread":true,"read":true}', [], 0) - ->will($this->returnValue($this->response)); + ->willReturn($this->response); + + $response = json_decode((string) $this->response->getBody()); - $this->assertThat( - $this->object->markReadThread(1), - $this->equalTo(json_decode($this->response->body)) + $this->assertEquals( + $response, + $this->object->markReadThread(1) ); } @@ -243,11 +255,13 @@ public function testGetThreadSubscription() $this->client->expects($this->once()) ->method('get') ->with('/notifications/threads/1/subscription', [], 0) - ->will($this->returnValue($this->response)); + ->willReturn($this->response); + + $response = json_decode((string) $this->response->getBody()); - $this->assertThat( - $this->object->getThreadSubscription(1), - $this->equalTo(json_decode($this->response->body)) + $this->assertEquals( + $response, + $this->object->getThreadSubscription(1) ); } @@ -263,11 +277,13 @@ public function testSetThreadSubscription() $this->client->expects($this->once()) ->method('put') ->with('/notifications/threads/1/subscription', '{"subscribed":true,"ignored":false}', [], 0) - ->will($this->returnValue($this->response)); + ->willReturn($this->response); - $this->assertThat( - $this->object->setThreadSubscription(1, true, false), - $this->equalTo(json_decode($this->response->body)) + $response = json_decode((string) $this->response->getBody()); + + $this->assertEquals( + $response, + $this->object->setThreadSubscription(1, true, false) ); } @@ -280,17 +296,18 @@ public function testSetThreadSubscription() */ public function testDeleteThreadSubscription() { - $this->response->code = 204; - $this->response->body = ''; + $this->response = $this->getResponseObject('', 204); $this->client->expects($this->once()) ->method('delete') ->with('/notifications/threads/1/subscription', [], 0) - ->will($this->returnValue($this->response)); + ->willReturn($this->response); + + $response = json_decode((string) $this->response->getBody()); - $this->assertThat( - $this->object->deleteThreadSubscription(1), - $this->equalTo(json_decode($this->response->body)) + $this->assertEquals( + $response, + $this->object->deleteThreadSubscription(1) ); } } diff --git a/Tests/Package/Activity/StarringTest.php b/Tests/Package/Activity/StarringTest.php index c1c4cf8f..6f70766c 100644 --- a/Tests/Package/Activity/StarringTest.php +++ b/Tests/Package/Activity/StarringTest.php @@ -5,7 +5,7 @@ * @license GNU General Public License version 2 or later; see LICENSE */ -namespace Joomla\Github\Tests; +namespace Joomla\Github\Tests\Package\Activity; use Joomla\Github\Package\Activity\Starring; use Joomla\Github\Tests\Stub\GitHubTestCase; @@ -52,11 +52,13 @@ public function testGetList() $this->client->expects($this->once()) ->method('get') ->with('/repos/joomla/joomla-platform/stargazers', [], 0) - ->will($this->returnValue($this->response)); + ->willReturn($this->response); - $this->assertThat( - $this->object->getList('joomla', 'joomla-platform'), - $this->equalTo(json_decode($this->response->body)) + $response = json_decode((string) $this->response->getBody()); + + $this->assertEquals( + $response, + $this->object->getList('joomla', 'joomla-platform') ); } @@ -72,11 +74,13 @@ public function testGetRepositories() $this->client->expects($this->once()) ->method('get') ->with('/user/starred?sort=created&direction=desc', [], 0) - ->will($this->returnValue($this->response)); + ->willReturn($this->response); + + $response = json_decode((string) $this->response->getBody()); - $this->assertThat( - $this->object->getRepositories(), - $this->equalTo(json_decode($this->response->body)) + $this->assertEquals( + $response, + $this->object->getRepositories() ); } @@ -92,11 +96,13 @@ public function testGetRepositoriesWithName() $this->client->expects($this->once()) ->method('get') ->with('/users/{user}/starred?sort=created&direction=desc', [], 0) - ->will($this->returnValue($this->response)); + ->willReturn($this->response); - $this->assertThat( - $this->object->getRepositories('{user}'), - $this->equalTo(json_decode($this->response->body)) + $response = json_decode((string) $this->response->getBody()); + + $this->assertEquals( + $response, + $this->object->getRepositories('{user}') ); } @@ -141,17 +147,18 @@ public function testGetRepositoriesInvalidDirection() */ public function testCheck() { - $this->response->code = 204; - $this->response->body = true; + $this->response = $this->getResponseObject(true, 204); $this->client->expects($this->once()) ->method('get') ->with('/user/starred/joomla/joomla-platform', [], 0) - ->will($this->returnValue($this->response)); + ->willReturn($this->response); + + $response = json_decode((string) $this->response->getBody()); - $this->assertThat( - $this->object->check('joomla', 'joomla-platform'), - $this->equalTo(json_decode($this->response->body)) + $this->assertEquals( + $response, + $this->object->check('joomla', 'joomla-platform') ); } @@ -164,17 +171,18 @@ public function testCheck() */ public function testCheckFalse() { - $this->response->code = 404; - $this->response->body = false; + $this->response = $this->getResponseObject(false, 404); $this->client->expects($this->once()) ->method('get') ->with('/user/starred/joomla/joomla-platform', [], 0) - ->will($this->returnValue($this->response)); + ->willReturn($this->response); - $this->assertThat( - $this->object->check('joomla', 'joomla-platform'), - $this->equalTo(json_decode($this->response->body)) + $response = json_decode((string) $this->response->getBody()); + + $this->assertEquals( + $response, + $this->object->check('joomla', 'joomla-platform') ); } @@ -187,19 +195,20 @@ public function testCheckFalse() */ public function testCheckUnexpected() { - $this->expectException(\UnexpectedValueException::class); + $this->expectException(\Laminas\Diactoros\Exception\InvalidArgumentException::class); - $this->response->code = 666; - $this->response->body = false; + $this->response = $this->getResponseObject(false, 666); $this->client->expects($this->once()) ->method('get') ->with('/user/starred/joomla/joomla-platform', [], 0) - ->will($this->returnValue($this->response)); + ->willReturn($this->response); + + $response = json_decode((string) $this->response->getBody()); - $this->assertThat( - $this->object->check('joomla', 'joomla-platform'), - $this->equalTo(json_decode($this->response->body)) + $this->assertEquals( + $response, + $this->object->check('joomla', 'joomla-platform') ); } @@ -212,16 +221,18 @@ public function testCheckUnexpected() */ public function testStar() { - $this->response->code = 204; + $this->response = $this->getResponseObject($this->sampleString, 204); $this->client->expects($this->once()) ->method('put') ->with('/user/starred/joomla/joomla-platform', '', [], 0) - ->will($this->returnValue($this->response)); + ->willReturn($this->response); - $this->assertThat( - $this->object->star('joomla', 'joomla-platform'), - $this->equalTo(json_decode($this->response->body)) + $response = json_decode((string) $this->response->getBody()); + + $this->assertEquals( + $response, + $this->object->star('joomla', 'joomla-platform') ); } @@ -234,17 +245,18 @@ public function testStar() */ public function testUnstar() { - $this->response->code = 204; - $this->response->body = ''; + $this->response = $this->getResponseObject('', 204); $this->client->expects($this->once()) ->method('delete') ->with('/user/starred/joomla/joomla-platform', [], 0) - ->will($this->returnValue($this->response)); + ->willReturn($this->response); + + $response = json_decode((string) $this->response->getBody()); - $this->assertThat( - $this->object->unstar('joomla', 'joomla-platform'), - $this->equalTo(json_decode($this->response->body)) + $this->assertEquals( + $response, + $this->object->unstar('joomla', 'joomla-platform') ); } } diff --git a/Tests/Package/Activity/WatchingTest.php b/Tests/Package/Activity/WatchingTest.php index 5bc9b1e5..d7ce4b73 100644 --- a/Tests/Package/Activity/WatchingTest.php +++ b/Tests/Package/Activity/WatchingTest.php @@ -48,11 +48,13 @@ public function testGetList() $this->client->expects($this->once()) ->method('get') ->with('/repos/joomla/joomla-platform/subscribers', [], 0) - ->will($this->returnValue($this->response)); + ->willReturn($this->response); - $this->assertThat( - $this->object->getList('joomla', 'joomla-platform'), - $this->equalTo(json_decode($this->response->body)) + $response = json_decode((string) $this->response->getBody()); + + $this->assertEquals( + $response, + $this->object->getList('joomla', 'joomla-platform') ); } @@ -66,11 +68,13 @@ public function testGetRepositories() $this->client->expects($this->once()) ->method('get') ->with('/user/subscriptions', [], 0) - ->will($this->returnValue($this->response)); + ->willReturn($this->response); - $this->assertThat( - $this->object->getRepositories(), - $this->equalTo(json_decode($this->response->body)) + $response = json_decode((string) $this->response->getBody()); + + $this->assertEquals( + $response, + $this->object->getRepositories() ); } @@ -84,11 +88,13 @@ public function testGetRepositoriesUser() $this->client->expects($this->once()) ->method('get') ->with('/users/joomla/subscriptions', [], 0) - ->will($this->returnValue($this->response)); + ->willReturn($this->response); - $this->assertThat( - $this->object->getRepositories('joomla'), - $this->equalTo(json_decode($this->response->body)) + $response = json_decode((string) $this->response->getBody()); + + $this->assertEquals( + $response, + $this->object->getRepositories('joomla') ); } @@ -102,11 +108,13 @@ public function testGetSubscription() $this->client->expects($this->once()) ->method('get') ->with('/repos/joomla/joomla-platform/subscription', [], 0) - ->will($this->returnValue($this->response)); + ->willReturn($this->response); - $this->assertThat( - $this->object->getSubscription('joomla', 'joomla-platform'), - $this->equalTo(json_decode($this->response->body)) + $response = json_decode((string) $this->response->getBody()); + + $this->assertEquals( + $response, + $this->object->getSubscription('joomla', 'joomla-platform') ); } @@ -120,11 +128,13 @@ public function testSetSubscription() $this->client->expects($this->once()) ->method('put') ->with('/repos/joomla/joomla-platform/subscription', '{"subscribed":true,"ignored":false}', [], 0) - ->will($this->returnValue($this->response)); + ->willReturn($this->response); - $this->assertThat( - $this->object->setSubscription('joomla', 'joomla-platform', true, false), - $this->equalTo(json_decode($this->response->body)) + $response = json_decode((string) $this->response->getBody()); + + $this->assertEquals( + $response, + $this->object->setSubscription('joomla', 'joomla-platform', true, false) ); } @@ -135,17 +145,18 @@ public function testSetSubscription() */ public function testDeleteSubscription() { - $this->response->code = 204; - $this->response->body = ''; + $this->response = $this->getResponseObject('', 204); $this->client->expects($this->once()) ->method('delete') ->with('/repos/joomla/joomla-platform/subscription', [], 0) - ->will($this->returnValue($this->response)); + ->willReturn($this->response); - $this->assertThat( - $this->object->deleteSubscription('joomla', 'joomla-platform'), - $this->equalTo($this->response->body) + $response = (string) $this->response->getBody(); + + $this->assertEquals( + $response, + $this->object->deleteSubscription('joomla', 'joomla-platform') ); } @@ -156,13 +167,12 @@ public function testDeleteSubscription() */ public function testCheck() { - $this->response->code = 204; - $this->response->body = ''; + $this->response = $this->getResponseObject('', 204); $this->client->expects($this->once()) ->method('get') ->with('/user/subscriptions/joomla/joomla-platform', [], 0) - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->assertThat( $this->object->check('joomla', 'joomla-platform'), @@ -177,13 +187,12 @@ public function testCheck() */ public function testCheckFalse() { - $this->response->code = 404; - $this->response->body = ''; + $this->response = $this->getResponseObject('', 404); $this->client->expects($this->once()) ->method('get') ->with('/user/subscriptions/joomla/joomla-platform', [], 0) - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->assertThat( $this->object->check('joomla', 'joomla-platform'), @@ -198,15 +207,14 @@ public function testCheckFalse() */ public function testCheckUnexpected() { - $this->expectException(\UnexpectedValueException::class); + $this->expectException(\Laminas\Diactoros\Exception\InvalidArgumentException::class); - $this->response->code = 666; - $this->response->body = ''; + $this->response = $this->getResponseObject(false, 666); $this->client->expects($this->once()) ->method('get') ->with('/user/subscriptions/joomla/joomla-platform', [], 0) - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->object->check('joomla', 'joomla-platform'); } @@ -218,17 +226,18 @@ public function testCheckUnexpected() */ public function testWatch() { - $this->response->code = 204; - $this->response->body = ''; + $this->response = $this->getResponseObject('', 204); $this->client->expects($this->once()) ->method('put') ->with('/user/subscriptions/joomla/joomla-platform', '', [], 0) - ->will($this->returnValue($this->response)); + ->willReturn($this->response); - $this->assertThat( - $this->object->watch('joomla', 'joomla-platform'), - $this->equalTo($this->response->body) + $response = (string) $this->response->getBody(); + + $this->assertEquals( + $response, + $this->object->watch('joomla', 'joomla-platform') ); } @@ -239,17 +248,18 @@ public function testWatch() */ public function testUnwatch() { - $this->response->code = 204; - $this->response->body = ''; + $this->response = $this->getResponseObject('', 204); $this->client->expects($this->once()) ->method('delete') ->with('/user/subscriptions/joomla/joomla-platform', [], 0) - ->will($this->returnValue($this->response)); + ->willReturn($this->response); - $this->assertThat( - $this->object->unwatch('joomla', 'joomla-platform'), - $this->equalTo($this->response->body) + $response = (string) $this->response->getBody(); + + $this->assertEquals( + $response, + $this->object->unwatch('joomla', 'joomla-platform') ); } } diff --git a/Tests/Package/AuthorizationsTest.php b/Tests/Package/AuthorizationsTest.php index 0a303f9a..f5746fc5 100644 --- a/Tests/Package/AuthorizationsTest.php +++ b/Tests/Package/AuthorizationsTest.php @@ -46,7 +46,7 @@ protected function setUp(): void */ public function testCreate() { - $this->response->code = 201; + $this->response = $this->getResponseObject($this->sampleString, 201); $authorisation = '{' . '"scopes":["public_repo"],' @@ -57,7 +57,7 @@ public function testCreate() $this->client->expects($this->once()) ->method('post') ->with('/authorizations', $authorisation) - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->assertThat( $this->object->create(['public_repo'], 'My test app', 'http://www.joomla.org'), @@ -76,8 +76,7 @@ public function testCreateFailure() { $exception = false; - $this->response->code = 500; - $this->response->body = $this->errorString; + $this->response = $this->getResponseObject($this->errorString, 500); $authorisation = '{' . '"scopes":["public_repo"],' @@ -88,7 +87,7 @@ public function testCreateFailure() $this->client->expects($this->once()) ->method('post') ->with('/authorizations', $authorisation) - ->will($this->returnValue($this->response)); + ->willReturn($this->response); try { $this->object->create(['public_repo'], 'My test app', 'http://www.joomla.org'); @@ -113,12 +112,12 @@ public function testCreateFailure() */ public function testDelete() { - $this->response->code = 204; + $this->response = $this->getResponseObject($this->sampleString, 204); $this->client->expects($this->once()) ->method('delete') ->with('/authorizations/42') - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->assertThat( $this->object->delete(42), @@ -137,13 +136,12 @@ public function testDeleteFailure() { $exception = false; - $this->response->code = 500; - $this->response->body = $this->errorString; + $this->response = $this->getResponseObject($this->errorString, 500); $this->client->expects($this->once()) ->method('delete') ->with('/authorizations/42') - ->will($this->returnValue($this->response)); + ->willReturn($this->response); try { $this->object->delete(42); @@ -168,12 +166,12 @@ public function testDeleteFailure() */ public function testDeleteGrant() { - $this->response->code = 204; + $this->response = $this->getResponseObject($this->sampleString, 204); $this->client->expects($this->once()) ->method('delete') ->with('/authorizations/grants/42') - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->assertThat( $this->object->deleteGrant(42), @@ -192,13 +190,12 @@ public function testDeleteGrantFailure() { $exception = false; - $this->response->code = 500; - $this->response->body = $this->errorString; + $this->response = $this->getResponseObject($this->errorString, 500); $this->client->expects($this->once()) ->method('delete') ->with('/authorizations/grants/42') - ->will($this->returnValue($this->response)); + ->willReturn($this->response); try { $this->object->deleteGrant(42); @@ -232,7 +229,7 @@ public function testEditAddScopes() $this->client->expects($this->once()) ->method('patch') ->with('/authorizations/42', $authorisation) - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->assertThat( $this->object->edit(42, [], ['public_repo', 'gist'], [], 'My test app', 'http://www.joomla.org'), @@ -258,7 +255,7 @@ public function testEditRemoveScopes() $this->client->expects($this->once()) ->method('patch') ->with('/authorizations/42', $authorisation) - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->assertThat( $this->object->edit(42, [], [], ['public_repo', 'gist'], 'My test app', 'http://www.joomla.org'), @@ -284,7 +281,7 @@ public function testEditScopes() $this->client->expects($this->once()) ->method('patch') ->with('/authorizations/42', $authorisation) - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->assertThat( $this->object->edit(42, ['public_repo', 'gist'], [], [], 'My test app', 'http://www.joomla.org'), @@ -303,8 +300,7 @@ public function testEditFailure() { $exception = false; - $this->response->code = 500; - $this->response->body = $this->errorString; + $this->response = $this->getResponseObject($this->errorString, 500); $authorisation = '{' . '"add_scopes":["public_repo","gist"],' @@ -315,7 +311,7 @@ public function testEditFailure() $this->client->expects($this->once()) ->method('patch') ->with('/authorizations/42', $authorisation) - ->will($this->returnValue($this->response)); + ->willReturn($this->response); try { $this->object->edit(42, [], ['public_repo', 'gist'], [], 'My test app', 'http://www.joomla.org'); @@ -357,7 +353,7 @@ public function testGet() $this->client->expects($this->once()) ->method('get') ->with('/authorizations/42') - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->assertThat( $this->object->get(42), @@ -376,13 +372,12 @@ public function testGetFailure() { $this->expectException(\DomainException::class); - $this->response->code = 500; - $this->response->body = $this->errorString; + $this->response = $this->getResponseObject($this->errorString, 500); $this->client->expects($this->once()) ->method('get') ->with('/authorizations/42') - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->object->get(42); } @@ -399,7 +394,7 @@ public function testGetGrant() $this->client->expects($this->once()) ->method('get') ->with('/authorizations/grants/42') - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->assertThat( $this->object->getGrant(42), @@ -418,13 +413,12 @@ public function testGetGrantFailure() { $this->expectException(\DomainException::class); - $this->response->code = 500; - $this->response->body = $this->errorString; + $this->response = $this->getResponseObject($this->errorString, 500); $this->client->expects($this->once()) ->method('get') ->with('/authorizations/grants/42') - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->object->getGrant(42); } @@ -441,7 +435,7 @@ public function testGetList() $this->client->expects($this->once()) ->method('get') ->with('/authorizations') - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->assertThat( $this->object->getList(), @@ -460,13 +454,12 @@ public function testGetListFailure() { $this->expectException(\DomainException::class); - $this->response->code = 500; - $this->response->body = $this->errorString; + $this->response = $this->getResponseObject($this->errorString, 500); $this->client->expects($this->once()) ->method('get') ->with('/authorizations') - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->object->getList(); } @@ -483,7 +476,7 @@ public function testGetListGrants() $this->client->expects($this->once()) ->method('get') ->with('/authorizations/grants') - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->assertThat( $this->object->getListGrants(), @@ -502,13 +495,12 @@ public function testGetListGrantsFailure() { $this->expectException(\DomainException::class); - $this->response->code = 500; - $this->response->body = $this->errorString; + $this->response = $this->getResponseObject($this->errorString, 500); $this->client->expects($this->once()) ->method('get') ->with('/authorizations/grants') - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->object->getListGrants(); } @@ -525,7 +517,7 @@ public function testGetRateLimit() $this->client->expects($this->once()) ->method('get') ->with('/rate_limit') - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->assertThat( $this->object->getRateLimit(), @@ -542,13 +534,12 @@ public function testGetRateLimit() */ public function testGetRateLimitUnlimited() { - $this->response->code = 404; - $this->response->body = ''; + $this->response = $this->getResponseObject('', 404); $this->client->expects($this->once()) ->method('get') ->with('/rate_limit') - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->assertFalse($this->object->getRateLimit()->limit, 'The limit should be false for unlimited'); } @@ -564,13 +555,12 @@ public function testGetRateLimitFailure() { $this->expectException(\DomainException::class); - $this->response->code = 500; - $this->response->body = $this->errorString; + $this->response = $this->getResponseObject($this->errorString, 500); $this->client->expects($this->once()) ->method('get') ->with('/rate_limit') - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->object->getRateLimit(); } @@ -582,13 +572,14 @@ public function testGetRateLimitFailure() */ public function testGetAuthorizationLink() { - $this->response->code = 200; - $this->response->body = 'https://github.com/login/oauth/authorize?client_id=12345' - . '&redirect_uri=aaa&scope=bbb&state=ccc'; + $this->response = $this->getResponseObject('https://github.com/login/oauth/authorize?client_id=12345' + . '&redirect_uri=aaa&scope=bbb&state=ccc', 200); - $this->assertThat( - $this->object->getAuthorizationLink('12345', 'aaa', 'bbb', 'ccc'), - $this->equalTo($this->response->body) + $response = (string) $this->response->getBody(); + + $this->assertEquals( + $response, + $this->object->getAuthorizationLink('12345', 'aaa', 'bbb', 'ccc') ); } @@ -599,17 +590,18 @@ public function testGetAuthorizationLink() */ public function testRequestToken() { - $this->response->code = 200; - $this->response->body = ''; + $this->response = $this->getResponseObject(''); $this->client->expects($this->once()) ->method('post') ->with('https://github.com/login/oauth/access_token') - ->will($this->returnValue($this->response)); + ->willReturn($this->response); - $this->assertThat( - $this->object->requestToken('12345', 'aaa', 'bbb', 'ccc'), - $this->equalTo($this->response->body) + $response = (string) $this->response->getBody(); + + $this->assertEquals( + $response, + $this->object->requestToken('12345', 'aaa', 'bbb', 'ccc') ); } @@ -620,17 +612,18 @@ public function testRequestToken() */ public function testRequestTokenJson() { - $this->response->code = 200; - $this->response->body = ''; + $this->response = $this->getResponseObject(''); $this->client->expects($this->once()) ->method('post') ->with('https://github.com/login/oauth/access_token') - ->will($this->returnValue($this->response)); + ->willReturn($this->response); - $this->assertThat( - $this->object->requestToken('12345', 'aaa', 'bbb', 'ccc', 'json'), - $this->equalTo($this->response->body) + $response = (string) $this->response->getBody(); + + $this->assertEquals( + $response, + $this->object->requestToken('12345', 'aaa', 'bbb', 'ccc', 'json') ); } @@ -641,17 +634,18 @@ public function testRequestTokenJson() */ public function testRequestTokenXml() { - $this->response->code = 200; - $this->response->body = ''; + $this->response = $this->getResponseObject(''); $this->client->expects($this->once()) ->method('post') ->with('https://github.com/login/oauth/access_token') - ->will($this->returnValue($this->response)); + ->willReturn($this->response); - $this->assertThat( - $this->object->requestToken('12345', 'aaa', 'bbb', 'ccc', 'xml'), - $this->equalTo($this->response->body) + $response = (string) $this->response->getBody(); + + $this->assertEquals( + $response, + $this->object->requestToken('12345', 'aaa', 'bbb', 'ccc', 'xml') ); } @@ -664,8 +658,7 @@ public function testRequestTokenInvalidFormat() { $this->expectException(\UnexpectedValueException::class); - $this->response->code = 200; - $this->response->body = ''; + $this->response = $this->getResponseObject(''); $this->object->requestToken('12345', 'aaa', 'bbb', 'ccc', 'invalid'); } @@ -679,12 +672,12 @@ public function testRequestTokenInvalidFormat() */ public function testRevokeGrantForApplication() { - $this->response->code = 204; + $this->response = $this->getResponseObject($this->sampleString, 204); $this->client->expects($this->once()) ->method('delete') ->with('/applications/42/grants/1a2b3c') - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->assertThat( $this->object->revokeGrantForApplication(42, '1a2b3c'), @@ -703,13 +696,12 @@ public function testRevokeGrantForApplicationFailure() { $this->expectException(\DomainException::class); - $this->response->code = 500; - $this->response->body = $this->errorString; + $this->response = $this->getResponseObject($this->errorString, 500); $this->client->expects($this->once()) ->method('delete') ->with('/applications/42/grants/1a2b3c') - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->object->revokeGrantForApplication(42, '1a2b3c'); } diff --git a/Tests/Package/Data/BlobsTest.php b/Tests/Package/Data/BlobsTest.php index 856fabd5..cf528816 100644 --- a/Tests/Package/Data/BlobsTest.php +++ b/Tests/Package/Data/BlobsTest.php @@ -48,11 +48,13 @@ public function testGet() $this->client->expects($this->once()) ->method('get') ->with('/repos/joomla/joomla-platform/git/blobs/12345', [], 0) - ->will($this->returnValue($this->response)); + ->willReturn($this->response); - $this->assertThat( - $this->object->get('joomla', 'joomla-platform', '12345'), - $this->equalTo(json_decode($this->response->body)) + $response = json_decode((string) $this->response->getBody()); + + $this->assertEquals( + $response, + $this->object->get('joomla', 'joomla-platform', '12345') ); } @@ -63,16 +65,18 @@ public function testGet() */ public function testCreate() { - $this->response->code = 201; + $this->response = $this->getResponseObject($this->sampleString, 201); $this->client->expects($this->once()) ->method('post') ->with('/repos/joomla/joomla-platform/git/blobs', '{"content":"Hello w\u00f6rld","encoding":"utf-8"}', [], 0) - ->will($this->returnValue($this->response)); + ->willReturn($this->response); + + $response = json_decode((string) $this->response->getBody()); - $this->assertThat( - $this->object->create('joomla', 'joomla-platform', 'Hello wörld'), - $this->equalTo(json_decode($this->response->body)) + $this->assertEquals( + $response, + $this->object->create('joomla', 'joomla-platform', 'Hello wörld') ); } } diff --git a/Tests/Package/Data/CommitsTest.php b/Tests/Package/Data/CommitsTest.php index 21b8f959..401f8b25 100644 --- a/Tests/Package/Data/CommitsTest.php +++ b/Tests/Package/Data/CommitsTest.php @@ -48,11 +48,13 @@ public function testGet() $this->client->expects($this->once()) ->method('get') ->with('/repos/joomla/joomla-platform/git/commits/12345', [], 0) - ->will($this->returnValue($this->response)); + ->willReturn($this->response); - $this->assertThat( - $this->object->get('joomla', 'joomla-platform', '12345'), - $this->equalTo(json_decode($this->response->body)) + $response = json_decode((string) $this->response->getBody()); + + $this->assertEquals( + $response, + $this->object->get('joomla', 'joomla-platform', '12345') ); } @@ -63,16 +65,18 @@ public function testGet() */ public function testCreate() { - $this->response->code = 201; + $this->response = $this->getResponseObject($this->sampleString, 201); $this->client->expects($this->once()) ->method('post') ->with('/repos/joomla/joomla-platform/git/commits', '{"message":"My Message","tree":"12345","parents":[]}', [], 0) - ->will($this->returnValue($this->response)); + ->willReturn($this->response); + + $response = json_decode((string) $this->response->getBody()); - $this->assertThat( - $this->object->create('joomla', 'joomla-platform', 'My Message', '12345'), - $this->equalTo(json_decode($this->response->body)) + $this->assertEquals( + $response, + $this->object->create('joomla', 'joomla-platform', 'My Message', '12345') ); } } diff --git a/Tests/Package/Data/RefsTest.php b/Tests/Package/Data/RefsTest.php index 36af0dc5..bf298f92 100755 --- a/Tests/Package/Data/RefsTest.php +++ b/Tests/Package/Data/RefsTest.php @@ -48,7 +48,7 @@ public function testGet() $this->client->expects($this->once()) ->method('get') ->with('/repos/joomla/joomla-platform/git/refs/heads/master') - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->assertThat( $this->object->get('joomla', 'joomla-platform', 'heads/master'), @@ -65,13 +65,12 @@ public function testGetFailure() { $this->expectException(\DomainException::class); - $this->response->code = 500; - $this->response->body = $this->errorString; + $this->response = $this->getResponseObject($this->errorString, 500); $this->client->expects($this->once()) ->method('get') ->with('/repos/joomla/joomla-platform/git/refs/heads/master') - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->object->get('joomla', 'joomla-platform', 'heads/master'); } @@ -83,7 +82,7 @@ public function testGetFailure() */ public function testCreate() { - $this->response->code = 201; + $this->response = $this->getResponseObject($this->sampleString, 201); // Build the request data. $data = json_encode( @@ -96,7 +95,7 @@ public function testCreate() $this->client->expects($this->once()) ->method('post') ->with('/repos/joomla/joomla-platform/git/refs', $data) - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->assertThat( $this->object->create('joomla', 'joomla-platform', '/ref/heads/myhead', 'This is the sha'), @@ -113,8 +112,7 @@ public function testCreateFailure() { $this->expectException(\DomainException::class); - $this->response->code = 501; - $this->response->body = $this->errorString; + $this->response = $this->getResponseObject($this->errorString, 501); // Build the request data. $data = json_encode( @@ -127,7 +125,7 @@ public function testCreateFailure() $this->client->expects($this->once()) ->method('post') ->with('/repos/joomla/joomla-platform/git/refs', $data) - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->object->create('joomla', 'joomla-platform', '/ref/heads/myhead', 'This is the sha'); } @@ -150,7 +148,7 @@ public function testEdit() $this->client->expects($this->once()) ->method('patch') ->with('/repos/joomla/joomla-platform/git/refs/heads/master', $data) - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->assertThat( $this->object->edit('joomla', 'joomla-platform', 'heads/master', 'This is the sha', true), @@ -167,8 +165,7 @@ public function testEditFailure() { $this->expectException(\DomainException::class); - $this->response->code = 500; - $this->response->body = $this->errorString; + $this->response = $this->getResponseObject($this->errorString, 500); // Build the request data. $data = json_encode( @@ -180,7 +177,7 @@ public function testEditFailure() $this->client->expects($this->once()) ->method('patch') ->with('/repos/joomla/joomla-platform/git/refs/heads/master', $data) - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->object->edit('joomla', 'joomla-platform', 'heads/master', 'This is the sha'); } @@ -195,7 +192,7 @@ public function testGetList() $this->client->expects($this->once()) ->method('get') ->with('/repos/joomla/joomla-platform/git/refs') - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->assertThat( $this->object->getList('joomla', 'joomla-platform'), @@ -213,7 +210,7 @@ public function testGetListWithNamespace() $this->client->expects($this->once()) ->method('get') ->with('/repos/joomla/joomla-platform/git/refs/tags') - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->assertThat( $this->object->getList('joomla', 'joomla-platform', 'tags'), @@ -230,13 +227,12 @@ public function testGetListFailure() { $this->expectException(\DomainException::class); - $this->response->code = 500; - $this->response->body = $this->errorString; + $this->response = $this->getResponseObject($this->errorString, 500); $this->client->expects($this->once()) ->method('get') ->with('/repos/joomla/joomla-platform/git/refs') - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->object->getList('joomla', 'joomla-platform'); } @@ -248,15 +244,14 @@ public function testGetListFailure() */ public function testDelete() { - $this->response->code = 204; - $this->response->body = ''; + $this->response = $this->getResponseObject('', 204); $ref = 'refs/heads/sc/featureA'; $this->client->expects($this->once()) ->method('delete') ->with('/repos/joomla/joomla-platform/git/refs/' . $ref) - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->assertThat( $this->object->delete('joomla', 'joomla-platform', $ref), @@ -273,15 +268,14 @@ public function testDeleteFailure() { $this->expectException(\DomainException::class); - $this->response->code = 500; - $this->response->body = $this->errorString; + $this->response = $this->getResponseObject($this->errorString, 500); $ref = 'refs/heads/sc/featureA'; $this->client->expects($this->once()) ->method('delete') ->with('/repos/joomla/joomla-platform/git/refs/' . $ref) - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->object->delete('joomla', 'joomla-platform', $ref); } diff --git a/Tests/Package/Data/TagsTest.php b/Tests/Package/Data/TagsTest.php index f3861735..c6537bc1 100644 --- a/Tests/Package/Data/TagsTest.php +++ b/Tests/Package/Data/TagsTest.php @@ -48,11 +48,13 @@ public function testGet() $this->client->expects($this->once()) ->method('get') ->with('/repos/joomla/joomla-platform/git/tags/12345', [], 0) - ->will($this->returnValue($this->response)); + ->willReturn($this->response); - $this->assertThat( - $this->object->get('joomla', 'joomla-platform', '12345'), - $this->equalTo(json_decode($this->response->body)) + $response = json_decode((string) $this->response->getBody()); + + $this->assertEquals( + $response, + $this->object->get('joomla', 'joomla-platform', '12345') ); } @@ -63,18 +65,20 @@ public function testGet() */ public function testCreate() { - $this->response->code = 201; + $this->response = $this->getResponseObject($this->sampleString, 201); $data = '{"tag":"0.1","message":"Message","object":"12345","type":"commit","tagger":' . '{"name":"elkuku","email":"email@example.com","date":"123456789"}}'; $this->client->expects($this->once()) ->method('post') ->with('/repos/joomla/joomla-platform/git/tags', $data, [], 0) - ->will($this->returnValue($this->response)); + ->willReturn($this->response); + + $response = json_decode((string) $this->response->getBody()); - $this->assertThat( - $this->object->create('joomla', 'joomla-platform', '0.1', 'Message', '12345', 'commit', 'elkuku', 'email@example.com', '123456789'), - $this->equalTo(json_decode($this->response->body)) + $this->assertEquals( + $response, + $this->object->create('joomla', 'joomla-platform', '0.1', 'Message', '12345', 'commit', 'elkuku', 'email@example.com', '123456789') ); } } diff --git a/Tests/Package/Data/TreesTest.php b/Tests/Package/Data/TreesTest.php index f3459cfd..c038cb12 100644 --- a/Tests/Package/Data/TreesTest.php +++ b/Tests/Package/Data/TreesTest.php @@ -48,11 +48,13 @@ public function testGet() $this->client->expects($this->once()) ->method('get') ->with('/repos/joomla/joomla-platform/git/trees/12345', [], 0) - ->will($this->returnValue($this->response)); + ->willReturn($this->response); - $this->assertThat( - $this->object->get('joomla', 'joomla-platform', '12345'), - $this->equalTo(json_decode($this->response->body)) + $response = json_decode((string) $this->response->getBody()); + + $this->assertEquals( + $response, + $this->object->get('joomla', 'joomla-platform', '12345') ); } @@ -66,11 +68,13 @@ public function testGetRecursively() $this->client->expects($this->once()) ->method('get') ->with('/repos/joomla/joomla-platform/git/trees/12345?recursive=1', [], 0) - ->will($this->returnValue($this->response)); + ->willReturn($this->response); + + $response = json_decode((string) $this->response->getBody()); - $this->assertThat( - $this->object->getRecursively('joomla', 'joomla-platform', '12345'), - $this->equalTo(json_decode($this->response->body)) + $this->assertEquals( + $response, + $this->object->getRecursively('joomla', 'joomla-platform', '12345') ); } @@ -81,16 +85,18 @@ public function testGetRecursively() */ public function testCreate() { - $this->response->code = 201; + $this->response = $this->getResponseObject($this->sampleString, 201); $this->client->expects($this->once()) ->method('post') ->with('/repos/joomla/joomla-platform/git/trees', '{"tree":"12345","base_tree":"678"}', [], 0) - ->will($this->returnValue($this->response)); + ->willReturn($this->response); + + $response = json_decode((string) $this->response->getBody()); - $this->assertThat( - $this->object->create('joomla', 'joomla-platform', '12345', '678'), - $this->equalTo(json_decode($this->response->body)) + $this->assertEquals( + $response, + $this->object->create('joomla', 'joomla-platform', '12345', '678') ); } } diff --git a/Tests/Package/EmojisTest.php b/Tests/Package/EmojisTest.php index 0ad9dbd7..d8972561 100755 --- a/Tests/Package/EmojisTest.php +++ b/Tests/Package/EmojisTest.php @@ -47,7 +47,7 @@ public function testGetList() $this->client->expects($this->once()) ->method('get') ->with('/emojis') - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->assertThat( $this->object->getList(), @@ -64,13 +64,12 @@ public function testGetListFailure() { $exception = false; - $this->response->code = 500; - $this->response->body = $this->errorString; + $this->response = $this->getResponseObject($this->errorString, 500); $this->client->expects($this->once()) ->method('get') ->with('/emojis') - ->will($this->returnValue($this->response)); + ->willReturn($this->response); try { $this->object->getList(); diff --git a/Tests/Package/GistsTest.php b/Tests/Package/GistsTest.php index 26f5454d..5796c5c5 100755 --- a/Tests/Package/GistsTest.php +++ b/Tests/Package/GistsTest.php @@ -44,7 +44,7 @@ protected function setUp(): void */ public function testCreate() { - $this->response->code = 201; + $this->response = $this->getResponseObject($this->sampleString, 201); // Build the request data. $data = json_encode( @@ -60,7 +60,7 @@ public function testCreate() $this->client->expects($this->once()) ->method('post') ->with('/gists', $data) - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->assertThat( $this->object->create( @@ -81,7 +81,7 @@ public function testCreate() */ public function testCreateGistFromFile() { - $this->response->code = 201; + $this->response = $this->getResponseObject($this->sampleString, 201); // Build the request data. $data = json_encode( @@ -97,7 +97,7 @@ public function testCreateGistFromFile() $this->client->expects($this->once()) ->method('post') ->with('/gists', $data) - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->assertThat( $this->object->create( @@ -120,7 +120,7 @@ public function testCreateGistFromFileNotFound() { $this->expectException(\InvalidArgumentException::class); - $this->response->code = 501; + $this->response = $this->getResponseObject($this->sampleString, 501); $this->object->create( [ @@ -140,8 +140,7 @@ public function testCreateFailure() { $exception = false; - $this->response->code = 500; - $this->response->body = $this->errorString; + $this->response = $this->getResponseObject($this->errorString, 500); // Build the request data. $data = json_encode( @@ -151,7 +150,7 @@ public function testCreateFailure() $this->client->expects($this->once()) ->method('post') ->with('/gists', $data) - ->will($this->returnValue($this->response)); + ->willReturn($this->response); try { $this->object->create([], true, 'This is a gist'); @@ -174,7 +173,7 @@ public function testCreateFailure() */ public function testCreateComment() { - $this->response->code = 201; + $this->response = $this->getResponseObject($this->sampleString, 201); $gist = new \stdClass(); $gist->body = 'My Insightful Comment'; @@ -182,7 +181,7 @@ public function testCreateComment() $this->client->expects($this->once()) ->method('post') ->with('/gists/523/comments', json_encode($gist)) - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->assertThat( $this->object->comments->create(523, 'My Insightful Comment'), @@ -199,8 +198,7 @@ public function testCreateCommentFailure() { $exception = false; - $this->response->code = 500; - $this->response->body = $this->errorString; + $this->response = $this->getResponseObject($this->errorString, 500); $gist = new \stdClass(); $gist->body = 'My Insightful Comment'; @@ -208,7 +206,7 @@ public function testCreateCommentFailure() $this->client->expects($this->once()) ->method('post') ->with('/gists/523/comments', json_encode($gist)) - ->will($this->returnValue($this->response)); + ->willReturn($this->response); try { $this->object->comments->create(523, 'My Insightful Comment'); @@ -231,12 +229,12 @@ public function testCreateCommentFailure() */ public function testDelete() { - $this->response->code = 204; + $this->response = $this->getResponseObject($this->sampleString, 204); $this->client->expects($this->once()) ->method('delete') ->with('/gists/254') - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->object->delete(254); } @@ -250,13 +248,12 @@ public function testDeleteFailure() { $exception = false; - $this->response->code = 500; - $this->response->body = $this->errorString; + $this->response = $this->getResponseObject($this->errorString, 500); $this->client->expects($this->once()) ->method('delete') ->with('/gists/254') - ->will($this->returnValue($this->response)); + ->willReturn($this->response); try { $this->object->delete(254); @@ -279,12 +276,12 @@ public function testDeleteFailure() */ public function testDeleteComment() { - $this->response->code = 204; + $this->response = $this->getResponseObject($this->sampleString, 204); $this->client->expects($this->once()) ->method('delete') ->with('/gists/comments/254') - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->object->comments->delete(254); } @@ -298,13 +295,12 @@ public function testDeleteCommentFailure() { $exception = false; - $this->response->code = 500; - $this->response->body = $this->errorString; + $this->response = $this->getResponseObject($this->errorString, 500); $this->client->expects($this->once()) ->method('delete') ->with('/gists/comments/254') - ->will($this->returnValue($this->response)); + ->willReturn($this->response); try { $this->object->comments->delete(254); @@ -342,7 +338,7 @@ public function testEdit() $this->client->expects($this->once()) ->method('patch') ->with('/gists/512', $data) - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->assertThat( $this->object->edit( @@ -367,8 +363,7 @@ public function testEditFailure() { $exception = false; - $this->response->code = 500; - $this->response->body = $this->errorString; + $this->response = $this->getResponseObject($this->errorString, 500); // Build the request data. $data = json_encode( @@ -385,7 +380,7 @@ public function testEditFailure() $this->client->expects($this->once()) ->method('patch') ->with('/gists/512', $data) - ->will($this->returnValue($this->response)); + ->willReturn($this->response); try { $this->object->edit( @@ -422,7 +417,7 @@ public function testEditComment() $this->client->expects($this->once()) ->method('patch') ->with('/gists/comments/523', json_encode($gist)) - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->assertThat( $this->object->comments->edit(523, 'This comment is now even more insightful'), @@ -439,8 +434,7 @@ public function testEditCommentFailure() { $exception = false; - $this->response->code = 500; - $this->response->body = $this->errorString; + $this->response = $this->getResponseObject($this->errorString, 500); $gist = new \stdClass(); $gist->body = 'This comment is now even more insightful'; @@ -448,7 +442,7 @@ public function testEditCommentFailure() $this->client->expects($this->once()) ->method('patch') ->with('/gists/comments/523', json_encode($gist)) - ->will($this->returnValue($this->response)); + ->willReturn($this->response); try { $this->object->comments->edit(523, 'This comment is now even more insightful'); @@ -471,12 +465,12 @@ public function testEditCommentFailure() */ public function testFork() { - $this->response->code = 201; + $this->response = $this->getResponseObject($this->sampleString, 201); $this->client->expects($this->once()) ->method('post') ->with('/gists/523/forks') - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->assertThat( $this->object->fork(523), @@ -493,13 +487,12 @@ public function testForkFailure() { $exception = false; - $this->response->code = 501; - $this->response->body = $this->errorString; + $this->response = $this->getResponseObject($this->errorString, 501); $this->client->expects($this->once()) ->method('post') ->with('/gists/523/forks') - ->will($this->returnValue($this->response)); + ->willReturn($this->response); try { $this->object->fork(523); @@ -525,7 +518,7 @@ public function testGet() $this->client->expects($this->once()) ->method('get') ->with('/gists/523') - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->assertThat( $this->object->get(523), @@ -542,13 +535,12 @@ public function testGetFailure() { $exception = false; - $this->response->code = 500; - $this->response->body = $this->errorString; + $this->response = $this->getResponseObject($this->errorString, 500); $this->client->expects($this->once()) ->method('get') ->with('/gists/523') - ->will($this->returnValue($this->response)); + ->willReturn($this->response); try { $this->object->get(523); @@ -574,7 +566,7 @@ public function testGetComment() $this->client->expects($this->once()) ->method('get') ->with('/gists/comments/523') - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->assertThat( $this->object->comments->get(523), @@ -591,13 +583,12 @@ public function testGetCommentFailure() { $exception = false; - $this->response->code = 500; - $this->response->body = $this->errorString; + $this->response = $this->getResponseObject($this->errorString, 500); $this->client->expects($this->once()) ->method('get') ->with('/gists/comments/523') - ->will($this->returnValue($this->response)); + ->willReturn($this->response); try { $this->object->comments->get(523); @@ -623,7 +614,7 @@ public function testGetComments() $this->client->expects($this->once()) ->method('get') ->with('/gists/523/comments') - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->assertThat( $this->object->comments->getList(523), @@ -640,13 +631,12 @@ public function testGetCommentsFailure() { $exception = false; - $this->response->code = 500; - $this->response->body = $this->errorString; + $this->response = $this->getResponseObject($this->errorString, 500); $this->client->expects($this->once()) ->method('get') ->with('/gists/523/comments') - ->will($this->returnValue($this->response)); + ->willReturn($this->response); try { $this->object->comments->getList(523); @@ -672,7 +662,7 @@ public function testGetCommitList() $this->client->expects($this->once()) ->method('get') ->with('/gists/523/commits') - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->assertThat( $this->object->getCommitList(523), @@ -689,13 +679,12 @@ public function testGetCommitListFailure() { $exception = false; - $this->response->code = 500; - $this->response->body = $this->errorString; + $this->response = $this->getResponseObject($this->errorString, 500); $this->client->expects($this->once()) ->method('get') ->with('/gists/523/commits') - ->will($this->returnValue($this->response)); + ->willReturn($this->response); try { $this->object->getCommitList(523); @@ -721,7 +710,7 @@ public function testGetForkList() $this->client->expects($this->once()) ->method('get') ->with('/gists/523/forks') - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->assertThat( $this->object->getForkList(523), @@ -738,13 +727,12 @@ public function testGetForkListFailure() { $exception = false; - $this->response->code = 500; - $this->response->body = $this->errorString; + $this->response = $this->getResponseObject($this->errorString, 500); $this->client->expects($this->once()) ->method('get') ->with('/gists/523/forks') - ->will($this->returnValue($this->response)); + ->willReturn($this->response); try { $this->object->getForkList(523); @@ -770,7 +758,7 @@ public function testGetList() $this->client->expects($this->once()) ->method('get') ->with('/gists') - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->assertThat( $this->object->getList(), @@ -787,13 +775,12 @@ public function testGetListFailure() { $exception = false; - $this->response->code = 500; - $this->response->body = $this->errorString; + $this->response = $this->getResponseObject($this->errorString, 500); $this->client->expects($this->once()) ->method('get') ->with('/gists') - ->will($this->returnValue($this->response)); + ->willReturn($this->response); try { $this->object->getList(); @@ -819,7 +806,7 @@ public function testGetListByUser() $this->client->expects($this->once()) ->method('get') ->with('/users/joomla/gists') - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->assertThat( $this->object->getListByUser('joomla'), @@ -836,13 +823,12 @@ public function testGetListByUserFailure() { $exception = false; - $this->response->code = 500; - $this->response->body = $this->errorString; + $this->response = $this->getResponseObject($this->errorString, 500); $this->client->expects($this->once()) ->method('get') ->with('/users/joomla/gists') - ->will($this->returnValue($this->response)); + ->willReturn($this->response); try { $this->object->getListByUser('joomla'); @@ -868,7 +854,7 @@ public function testGetListPublic() $this->client->expects($this->once()) ->method('get') ->with('/gists/public') - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->assertThat( $this->object->getListPublic(), @@ -885,13 +871,12 @@ public function testGetListPublicFailure() { $exception = false; - $this->response->code = 500; - $this->response->body = $this->errorString; + $this->response = $this->getResponseObject($this->errorString, 500); $this->client->expects($this->once()) ->method('get') ->with('/gists/public') - ->will($this->returnValue($this->response)); + ->willReturn($this->response); try { $this->object->getListPublic(); @@ -917,7 +902,7 @@ public function testGetListStarred() $this->client->expects($this->once()) ->method('get') ->with('/gists/starred') - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->assertThat( $this->object->getListStarred(), @@ -934,13 +919,12 @@ public function testGetListStarredFailure() { $exception = false; - $this->response->code = 500; - $this->response->body = $this->errorString; + $this->response = $this->getResponseObject($this->errorString, 500); $this->client->expects($this->once()) ->method('get') ->with('/gists/starred') - ->will($this->returnValue($this->response)); + ->willReturn($this->response); try { $this->object->getListStarred(); @@ -966,7 +950,7 @@ public function testGetRevision() $this->client->expects($this->once()) ->method('get') ->with('/gists/523/a1b2c3') - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->assertThat( $this->object->getRevision(523, 'a1b2c3'), @@ -983,13 +967,12 @@ public function testGetRevisionFailure() { $exception = false; - $this->response->code = 500; - $this->response->body = $this->errorString; + $this->response = $this->getResponseObject($this->errorString, 500); $this->client->expects($this->once()) ->method('get') ->with('/gists/523/a1b2c3') - ->will($this->returnValue($this->response)); + ->willReturn($this->response); try { $this->object->getRevision(523, 'a1b2c3'); @@ -1012,12 +995,12 @@ public function testGetRevisionFailure() */ public function testIsStarredTrue() { - $this->response->code = 204; + $this->response = $this->getResponseObject($this->sampleString, 204); $this->client->expects($this->once()) ->method('get') ->with('/gists/523/star') - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->assertThat( $this->object->isStarred(523), @@ -1032,12 +1015,12 @@ public function testIsStarredTrue() */ public function testIsStarredFalse() { - $this->response->code = 404; + $this->response = $this->getResponseObject($this->sampleString, 404); $this->client->expects($this->once()) ->method('get') ->with('/gists/523/star') - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->assertThat( $this->object->isStarred(523), @@ -1054,13 +1037,12 @@ public function testIsStarredFailure() { $exception = false; - $this->response->code = 500; - $this->response->body = $this->errorString; + $this->response = $this->getResponseObject($this->errorString, 500); $this->client->expects($this->once()) ->method('get') ->with('/gists/523/star') - ->will($this->returnValue($this->response)); + ->willReturn($this->response); try { $this->object->isStarred(523); @@ -1083,12 +1065,12 @@ public function testIsStarredFailure() */ public function testStar() { - $this->response->code = 204; + $this->response = $this->getResponseObject($this->sampleString, 204); $this->client->expects($this->once()) ->method('put') ->with('/gists/523/star', '') - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->object->star(523); } @@ -1102,13 +1084,12 @@ public function testStarFailure() { $exception = false; - $this->response->code = 504; - $this->response->body = $this->errorString; + $this->response = $this->getResponseObject($this->errorString, 504); $this->client->expects($this->once()) ->method('put') ->with('/gists/523/star', '') - ->will($this->returnValue($this->response)); + ->willReturn($this->response); try { $this->object->star(523); @@ -1131,12 +1112,12 @@ public function testStarFailure() */ public function testUnstar() { - $this->response->code = 204; + $this->response = $this->getResponseObject($this->sampleString, 204); $this->client->expects($this->once()) ->method('delete') ->with('/gists/523/star') - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->object->unstar(523); } @@ -1150,13 +1131,12 @@ public function testUnstarFailure() { $exception = false; - $this->response->code = 504; - $this->response->body = $this->errorString; + $this->response = $this->getResponseObject($this->errorString, 504); $this->client->expects($this->once()) ->method('delete') ->with('/gists/523/star') - ->will($this->returnValue($this->response)); + ->willReturn($this->response); try { $this->object->unstar(523); diff --git a/Tests/Package/GitignoreTest.php b/Tests/Package/GitignoreTest.php index 8a9de29d..17fc9635 100644 --- a/Tests/Package/GitignoreTest.php +++ b/Tests/Package/GitignoreTest.php @@ -46,8 +46,7 @@ protected function setUp(): void */ public function testGetList() { - $this->response->code = 200; - $this->response->body = '[ + $body = '[ "Actionscript", "Android", "AppceleratorTitanium", @@ -56,15 +55,18 @@ public function testGetList() "C", "C++" ]'; + $this->response = $this->getResponseObject($body); $this->client->expects($this->once()) ->method('get') ->with('/gitignore/templates', [], 0) - ->will($this->returnValue($this->response)); + ->willReturn($this->response); - $this->assertThat( - $this->object->getList(), - $this->equalTo(json_decode($this->response->body)) + $response = json_decode((string) $this->response->getBody()); + + $this->assertEquals( + $response, + $this->object->getList() ); } @@ -77,21 +79,23 @@ public function testGetList() */ public function testGet() { - $this->response->code = 200; - $this->response->body = '{ + $body = '{ "name": "C", "source": "# Object files\n*.o\n\n# Libraries\n*.lib\n*.a\n\n# Shared objects (inc. Windows DLLs)\n' . '*.dll\n*.so\n*.so.*\n*.dylib\n\n# Executables\n*.exe\n*.out\n*.app\n" }'; + $this->response = $this->getResponseObject($body); $this->client->expects($this->once()) ->method('get') ->with('/gitignore/templates/C', [], 0) - ->will($this->returnValue($this->response)); + ->willReturn($this->response); + + $response = json_decode((string) $this->response->getBody()); - $this->assertThat( - $this->object->get('C'), - $this->equalTo(json_decode($this->response->body)) + $this->assertEquals( + $response, + $this->object->get('C') ); } @@ -104,8 +108,7 @@ public function testGet() */ public function testGetRaw() { - $this->response->code = 200; - $this->response->body = '# Object files + $body = '# Object files *.o # Libraries @@ -123,15 +126,18 @@ public function testGetRaw() *.out *.app '; + $this->response = $this->getResponseObject($body); $this->client->expects($this->once()) ->method('get') ->with('/gitignore/templates/C', ['Accept' => 'application/vnd.github.raw+json'], 0) - ->will($this->returnValue($this->response)); + ->willReturn($this->response); - $this->assertThat( - $this->object->get('C', true), - $this->equalTo($this->response->body) + $response = (string) $this->response->getBody(); + + $this->assertEquals( + $response, + $this->object->get('C', true) ); } @@ -145,17 +151,18 @@ public function testGetFailure() { $this->expectException(\DomainException::class); - $this->response->code = 404; - $this->response->body = '{"message":"Not found"}'; + $this->response = $this->getResponseObject('{"message":"Not found"}', 404); $this->client->expects($this->once()) ->method('get') ->with('/gitignore/templates/X', [], 0) - ->will($this->returnValue($this->response)); + ->willReturn($this->response); + + $response = json_decode((string) $this->response->getBody()); - $this->assertThat( - $this->object->get('X'), - $this->equalTo(json_decode($this->response->body)) + $this->assertEquals( + $response, + $this->object->get('X') ); } } diff --git a/Tests/Package/GraphqlTest.php b/Tests/Package/GraphqlTest.php index 6538debb..db214005 100644 --- a/Tests/Package/GraphqlTest.php +++ b/Tests/Package/GraphqlTest.php @@ -44,8 +44,7 @@ protected function setUp(): void */ public function testCreate() { - $this->response->code = 200; - $this->response->body = $this->sampleString; + $this->response = $this->getResponseObject($this->sampleString); // Build the query. $query = 'foo'; @@ -64,7 +63,7 @@ public function testCreate() $this->client->expects($this->once()) ->method('post') ->with('/graphql', json_encode($data), $headers) - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->assertThat( $this->object->execute($query), @@ -81,8 +80,7 @@ public function testCreateFailure() { $exception = false; - $this->response->code = 500; - $this->response->body = $this->errorString; + $this->response = $this->getResponseObject($this->errorString, 500); // Build the query. $query = 'foo'; @@ -101,7 +99,7 @@ public function testCreateFailure() $this->client->expects($this->once()) ->method('post') ->with('/graphql', json_encode($data), $headers) - ->will($this->returnValue($this->response)); + ->willReturn($this->response); try { $this->object->execute($query); diff --git a/Tests/Package/Issues/AssigneesTest.php b/Tests/Package/Issues/AssigneesTest.php index 6ce15ec9..1677276d 100644 --- a/Tests/Package/Issues/AssigneesTest.php +++ b/Tests/Package/Issues/AssigneesTest.php @@ -57,8 +57,7 @@ protected function setUp(): void */ public function testGetList() { - $this->response->code = 200; - $this->response->body = '[ + $body = '[ { "login": "octocat", "id": 1, @@ -67,15 +66,18 @@ public function testGetList() "url": "https://api.github.com/users/octocat" } ]'; + $this->response = $this->getResponseObject($body); $this->client->expects($this->once()) ->method('get') ->with('/repos/' . $this->owner . '/' . $this->repo . '/assignees', [], 0) - ->will($this->returnValue($this->response)); + ->willReturn($this->response); - $this->assertThat( - $this->object->getList($this->owner, $this->repo), - $this->equalTo(json_decode($this->response->body)) + $response = json_decode((string) $this->response->getBody()); + + $this->assertEquals( + $response, + $this->object->getList($this->owner, $this->repo) ); } @@ -90,15 +92,14 @@ public function testGetList() */ public function testCheck() { - $this->response->code = 204; - $this->response->body = ''; + $this->response = $this->getResponseObject('', 204); $assignee = 'elkuku'; $this->client->expects($this->once()) ->method('get') ->with('/repos/' . $this->owner . '/' . $this->repo . '/assignees/' . $assignee, [], 0) - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->assertThat( $this->object->check($this->owner, $this->repo, $assignee), @@ -117,15 +118,14 @@ public function testCheck() */ public function testCheckNo() { - $this->response->code = 404; - $this->response->body = ''; + $this->response = $this->getResponseObject('', 404); $assignee = 'elkuku'; $this->client->expects($this->once()) ->method('get') ->with('/repos/' . $this->owner . '/' . $this->repo . '/assignees/' . $assignee, [], 0) - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->assertThat( $this->object->check($this->owner, $this->repo, $assignee), @@ -144,17 +144,16 @@ public function testCheckNo() */ public function testCheckException() { - $this->expectException(\DomainException::class); + $this->expectException(\Laminas\Diactoros\Exception\InvalidArgumentException::class); - $this->response->code = 666; - $this->response->body = ''; + $this->response = $this->getResponseObject(false, 666); $assignee = 'elkuku'; $this->client->expects($this->once()) ->method('get') ->with('/repos/' . $this->owner . '/' . $this->repo . '/assignees/' . $assignee, [], 0) - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->assertThat( $this->object->check($this->owner, $this->repo, $assignee), @@ -169,8 +168,7 @@ public function testCheckException() */ public function testAdd() { - $this->response->code = 201; - $this->response->body = '[ + $body = '[ { "login": "octocat", "id": 1, @@ -179,15 +177,18 @@ public function testAdd() "url": "https://api.github.com/users/octocat" } ]'; + $this->response = $this->getResponseObject($body, 201); $this->client->expects($this->once()) ->method('post') ->with('/repos/' . $this->owner . '/' . $this->repo . '/issues/123/assignees', json_encode(['assignees' => ['joomla']])) - ->will($this->returnValue($this->response)); + ->willReturn($this->response); - $this->assertThat( - $this->object->add($this->owner, $this->repo, 123, ['joomla']), - $this->equalTo(json_decode($this->response->body)) + $response = json_decode((string) $this->response->getBody()); + + $this->assertEquals( + $response, + $this->object->add($this->owner, $this->repo, 123, ['joomla']) ); } @@ -198,8 +199,7 @@ public function testAdd() */ public function testRemove() { - $this->response->code = 200; - $this->response->body = '[ + $body = '[ { "login": "octocat", "id": 1, @@ -208,15 +208,18 @@ public function testRemove() "url": "https://api.github.com/users/octocat" } ]'; + $this->response = $this->getResponseObject($body); $this->client->expects($this->once()) ->method('delete') ->with('/repos/' . $this->owner . '/' . $this->repo . '/issues/123/assignees', [], null, json_encode(['assignees' => ['joomla']])) - ->will($this->returnValue($this->response)); + ->willReturn($this->response); - $this->assertThat( - $this->object->remove($this->owner, $this->repo, 123, ['joomla']), - $this->equalTo(json_decode($this->response->body)) + $response = json_decode((string) $this->response->getBody()); + + $this->assertEquals( + $response, + $this->object->remove($this->owner, $this->repo, 123, ['joomla']) ); } } diff --git a/Tests/Package/Issues/CommentsTest.php b/Tests/Package/Issues/CommentsTest.php index 86e13639..053f1cd8 100644 --- a/Tests/Package/Issues/CommentsTest.php +++ b/Tests/Package/Issues/CommentsTest.php @@ -48,11 +48,13 @@ public function testGetList() $this->client->expects($this->once()) ->method('get') ->with('/repos/joomla/joomla-platform/issues/1/comments', [], 0) - ->will($this->returnValue($this->response)); + ->willReturn($this->response); - $this->assertThat( - $this->object->getList('joomla', 'joomla-platform', '1'), - $this->equalTo(json_decode($this->response->body)) + $response = json_decode((string) $this->response->getBody()); + + $this->assertEquals( + $response, + $this->object->getList('joomla', 'joomla-platform', '1') ); } @@ -66,11 +68,13 @@ public function testGetRepositoryList() $this->client->expects($this->once()) ->method('get') ->with('/repos/joomla/joomla-platform/issues/comments?sort=created&direction=asc', [], 0) - ->will($this->returnValue($this->response)); + ->willReturn($this->response); - $this->assertThat( - $this->object->getRepositoryList('joomla', 'joomla-platform'), - $this->equalTo(json_decode($this->response->body)) + $response = json_decode((string) $this->response->getBody()); + + $this->assertEquals( + $response, + $this->object->getRepositoryList('joomla', 'joomla-platform') ); } @@ -110,11 +114,13 @@ public function testGetRepositoryListSince() $this->client->expects($this->once()) ->method('get') ->with('/repos/joomla/joomla-platform/issues/comments?sort=created&direction=asc&since=1966-09-15T12:34:56+00:00', [], 0) - ->will($this->returnValue($this->response)); + ->willReturn($this->response); - $this->assertThat( - $this->object->getRepositoryList('joomla', 'joomla-platform', 'created', 'asc', $date), - $this->equalTo(json_decode($this->response->body)) + $response = json_decode((string) $this->response->getBody()); + + $this->assertEquals( + $response, + $this->object->getRepositoryList('joomla', 'joomla-platform', 'created', 'asc', $date) ); } @@ -128,11 +134,13 @@ public function testGet() $this->client->expects($this->once()) ->method('get') ->with('/repos/joomla/joomla-platform/issues/comments/1', [], 0) - ->will($this->returnValue($this->response)); + ->willReturn($this->response); - $this->assertThat( - $this->object->get('joomla', 'joomla-platform', 1), - $this->equalTo(json_decode($this->response->body)) + $response = json_decode((string) $this->response->getBody()); + + $this->assertEquals( + $response, + $this->object->get('joomla', 'joomla-platform', 1) ); } @@ -146,11 +154,13 @@ public function testEdit() $this->client->expects($this->once()) ->method('patch') ->with('/repos/joomla/joomla-platform/issues/comments/1', '{"body":"Hello"}', [], 0) - ->will($this->returnValue($this->response)); + ->willReturn($this->response); - $this->assertThat( - $this->object->edit('joomla', 'joomla-platform', 1, 'Hello'), - $this->equalTo(json_decode($this->response->body)) + $response = json_decode((string) $this->response->getBody()); + + $this->assertEquals( + $response, + $this->object->edit('joomla', 'joomla-platform', 1, 'Hello') ); } @@ -161,16 +171,18 @@ public function testEdit() */ public function testCreate() { - $this->response->code = 201; + $this->response = $this->getResponseObject($this->sampleString, 201); $this->client->expects($this->once()) ->method('post') ->with('/repos/joomla/joomla-platform/issues/1/comments', '{"body":"Hello"}', [], 0) - ->will($this->returnValue($this->response)); + ->willReturn($this->response); - $this->assertThat( - $this->object->create('joomla', 'joomla-platform', 1, 'Hello'), - $this->equalTo(json_decode($this->response->body)) + $response = json_decode((string) $this->response->getBody()); + + $this->assertEquals( + $response, + $this->object->create('joomla', 'joomla-platform', 1, 'Hello') ); } @@ -181,13 +193,12 @@ public function testCreate() */ public function testDelete() { - $this->response->code = 204; - $this->response->body = ''; + $this->response = $this->getResponseObject('', 204); $this->client->expects($this->once()) ->method('delete') ->with('/repos/joomla/joomla-platform/issues/comments/1', [], 0) - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->assertThat( $this->object->delete('joomla', 'joomla-platform', 1), diff --git a/Tests/Package/Issues/EventsTest.php b/Tests/Package/Issues/EventsTest.php index b0a4189c..26b763da 100644 --- a/Tests/Package/Issues/EventsTest.php +++ b/Tests/Package/Issues/EventsTest.php @@ -48,11 +48,13 @@ public function testGetList() $this->client->expects($this->once()) ->method('get') ->with('/repos/joomla/joomla-platform/issues/1/events', [], 0) - ->will($this->returnValue($this->response)); + ->willReturn($this->response); - $this->assertThat( - $this->object->getList('joomla', 'joomla-platform', '1'), - $this->equalTo(json_decode($this->response->body)) + $response = json_decode((string) $this->response->getBody()); + + $this->assertEquals( + $response, + $this->object->getList('joomla', 'joomla-platform', '1') ); } @@ -66,11 +68,13 @@ public function testGetListRepository() $this->client->expects($this->once()) ->method('get') ->with('/repos/joomla/joomla-platform/issues/1/comments', [], 0) - ->will($this->returnValue($this->response)); + ->willReturn($this->response); + + $response = json_decode((string) $this->response->getBody()); - $this->assertThat( - $this->object->getListRepository('joomla', 'joomla-platform', '1'), - $this->equalTo(json_decode($this->response->body)) + $this->assertEquals( + $response, + $this->object->getListRepository('joomla', 'joomla-platform', '1') ); } @@ -84,11 +88,13 @@ public function testGet() $this->client->expects($this->once()) ->method('get') ->with('/repos/joomla/joomla-platform/issues/events/1', [], 0) - ->will($this->returnValue($this->response)); + ->willReturn($this->response); + + $response = json_decode((string) $this->response->getBody()); - $this->assertThat( - $this->object->get('joomla', 'joomla-platform', '1'), - $this->equalTo(json_decode($this->response->body)) + $this->assertEquals( + $response, + $this->object->get('joomla', 'joomla-platform', '1') ); } } diff --git a/Tests/Package/Issues/LabelsTest.php b/Tests/Package/Issues/LabelsTest.php index 400e62ea..b586d072 100644 --- a/Tests/Package/Issues/LabelsTest.php +++ b/Tests/Package/Issues/LabelsTest.php @@ -48,11 +48,13 @@ public function testGetList() $this->client->expects($this->once()) ->method('get') ->with('/repos/joomla/joomla-platform/labels', [], 0) - ->will($this->returnValue($this->response)); + ->willReturn($this->response); - $this->assertThat( - $this->object->getList('joomla', 'joomla-platform'), - $this->equalTo(json_decode($this->response->body)) + $response = json_decode((string) $this->response->getBody()); + + $this->assertEquals( + $response, + $this->object->getList('joomla', 'joomla-platform') ); } @@ -66,11 +68,13 @@ public function testGet() $this->client->expects($this->once()) ->method('get') ->with('/repos/joomla/joomla-platform/labels/1', [], 0) - ->will($this->returnValue($this->response)); + ->willReturn($this->response); + + $response = json_decode((string) $this->response->getBody()); - $this->assertThat( - $this->object->get('joomla', 'joomla-platform', '1'), - $this->equalTo(json_decode($this->response->body)) + $this->assertEquals( + $response, + $this->object->get('joomla', 'joomla-platform', '1') ); } @@ -81,16 +85,18 @@ public function testGet() */ public function testCreate() { - $this->response->code = 201; + $this->response = $this->getResponseObject($this->sampleString, 201); $this->client->expects($this->once()) ->method('post') ->with('/repos/joomla/joomla-platform/labels', '{"name":"foobar","color":"red"}', [], 0) - ->will($this->returnValue($this->response)); + ->willReturn($this->response); + + $response = json_decode((string) $this->response->getBody()); - $this->assertThat( - $this->object->create('joomla', 'joomla-platform', 'foobar', 'red'), - $this->equalTo(json_decode($this->response->body)) + $this->assertEquals( + $response, + $this->object->create('joomla', 'joomla-platform', 'foobar', 'red') ); } @@ -103,17 +109,18 @@ public function testCreateFailure() { $this->expectException(\DomainException::class); - $this->response->code = 404; - $this->response->body = $this->errorString; + $this->response = $this->getResponseObject($this->errorString, 404); $this->client->expects($this->once()) ->method('post') ->with('/repos/joomla/joomla-platform/labels', '{"name":"foobar","color":"red"}', [], 0) - ->will($this->returnValue($this->response)); + ->willReturn($this->response); - $this->assertThat( - $this->object->create('joomla', 'joomla-platform', 'foobar', 'red'), - $this->equalTo(json_decode($this->response->body)) + $response = json_decode((string) $this->response->getBody()); + + $this->assertEquals( + $response, + $this->object->create('joomla', 'joomla-platform', 'foobar', 'red') ); } @@ -127,11 +134,13 @@ public function testUpdate() $this->client->expects($this->once()) ->method('patch') ->with('/repos/joomla/joomla-platform/labels/foobar', '{"name":"boofaz","color":"red"}', [], 0) - ->will($this->returnValue($this->response)); + ->willReturn($this->response); + + $response = json_decode((string) $this->response->getBody()); - $this->assertThat( - $this->object->update('joomla', 'joomla-platform', 'foobar', 'boofaz', 'red'), - $this->equalTo(json_decode($this->response->body)) + $this->assertEquals( + $response, + $this->object->update('joomla', 'joomla-platform', 'foobar', 'boofaz', 'red') ); } @@ -142,16 +151,18 @@ public function testUpdate() */ public function testDelete() { - $this->response->code = 204; + $this->response = $this->getResponseObject($this->sampleString, 204); $this->client->expects($this->once()) ->method('delete') ->with('/repos/joomla/joomla-platform/labels/foobar', [], 0) - ->will($this->returnValue($this->response)); + ->willReturn($this->response); + + $response = json_decode((string) $this->response->getBody()); - $this->assertThat( - $this->object->delete('joomla', 'joomla-platform', 'foobar'), - $this->equalTo(json_decode($this->response->body)) + $this->assertEquals( + $response, + $this->object->delete('joomla', 'joomla-platform', 'foobar') ); } @@ -165,11 +176,13 @@ public function testGetListByIssue() $this->client->expects($this->once()) ->method('get') ->with('/repos/joomla/joomla-platform/issues/1/labels', [], 0) - ->will($this->returnValue($this->response)); + ->willReturn($this->response); - $this->assertThat( - $this->object->getListByIssue('joomla', 'joomla-platform', 1), - $this->equalTo(json_decode($this->response->body)) + $response = json_decode((string) $this->response->getBody()); + + $this->assertEquals( + $response, + $this->object->getListByIssue('joomla', 'joomla-platform', 1) ); } @@ -183,11 +196,13 @@ public function testAdd() $this->client->expects($this->once()) ->method('post') ->with('/repos/joomla/joomla-platform/issues/1/labels', '["A","B"]', [], 0) - ->will($this->returnValue($this->response)); + ->willReturn($this->response); + + $response = json_decode((string) $this->response->getBody()); - $this->assertThat( - $this->object->add('joomla', 'joomla-platform', 1, ['A', 'B']), - $this->equalTo(json_decode($this->response->body)) + $this->assertEquals( + $response, + $this->object->add('joomla', 'joomla-platform', 1, ['A', 'B']) ); } @@ -201,11 +216,13 @@ public function testRemoveFromIssue() $this->client->expects($this->once()) ->method('delete') ->with('/repos/joomla/joomla-platform/issues/1/labels/foobar', [], 0) - ->will($this->returnValue($this->response)); + ->willReturn($this->response); + + $response = json_decode((string) $this->response->getBody()); - $this->assertThat( - $this->object->removeFromIssue('joomla', 'joomla-platform', 1, 'foobar'), - $this->equalTo(json_decode($this->response->body)) + $this->assertEquals( + $response, + $this->object->removeFromIssue('joomla', 'joomla-platform', 1, 'foobar') ); } @@ -219,11 +236,13 @@ public function testReplace() $this->client->expects($this->once()) ->method('put') ->with('/repos/joomla/joomla-platform/issues/1/labels', '["A","B"]', [], 0) - ->will($this->returnValue($this->response)); + ->willReturn($this->response); - $this->assertThat( - $this->object->replace('joomla', 'joomla-platform', 1, ['A', 'B']), - $this->equalTo(json_decode($this->response->body)) + $response = json_decode((string) $this->response->getBody()); + + $this->assertEquals( + $response, + $this->object->replace('joomla', 'joomla-platform', 1, ['A', 'B']) ); } @@ -234,16 +253,18 @@ public function testReplace() */ public function testRemoveAllFromIssue() { - $this->response->code = 204; + $this->response = $this->getResponseObject($this->sampleString, 204); $this->client->expects($this->once()) ->method('delete') ->with('/repos/joomla/joomla-platform/issues/1/labels', [], 0) - ->will($this->returnValue($this->response)); + ->willReturn($this->response); + + $response = json_decode((string) $this->response->getBody()); - $this->assertThat( - $this->object->removeAllFromIssue('joomla', 'joomla-platform', 1), - $this->equalTo(json_decode($this->response->body)) + $this->assertEquals( + $response, + $this->object->removeAllFromIssue('joomla', 'joomla-platform', 1) ); } @@ -257,11 +278,13 @@ public function testGetListByMilestone() $this->client->expects($this->once()) ->method('get') ->with('/repos/joomla/joomla-platform/milestones/1/labels', [], 0) - ->will($this->returnValue($this->response)); + ->willReturn($this->response); + + $response = json_decode((string) $this->response->getBody()); - $this->assertThat( - $this->object->getListByMilestone('joomla', 'joomla-platform', 1), - $this->equalTo(json_decode($this->response->body)) + $this->assertEquals( + $response, + $this->object->getListByMilestone('joomla', 'joomla-platform', 1) ); } } diff --git a/Tests/Package/Issues/MilestonesTest.php b/Tests/Package/Issues/MilestonesTest.php index e1fbcee1..8a071e90 100644 --- a/Tests/Package/Issues/MilestonesTest.php +++ b/Tests/Package/Issues/MilestonesTest.php @@ -47,7 +47,7 @@ protected function setUp(): void */ public function testCreate() { - $this->response->code = 201; + $this->response = $this->getResponseObject($this->sampleString, 201); $milestone = '{' . '"title":"My Milestone","state":"open","description":"This milestone is impossible","due_on":"2012-12-25T20:09:31Z"' @@ -56,11 +56,13 @@ public function testCreate() $this->client->expects($this->once()) ->method('post') ->with('/repos/joomla/joomla-platform/milestones', $milestone) - ->will($this->returnValue($this->response)); + ->willReturn($this->response); - $this->assertThat( - $this->object->create('joomla', 'joomla-platform', 'My Milestone', 'open', 'This milestone is impossible', '2012-12-25T20:09:31Z'), - $this->equalTo(json_decode($this->response->body)) + $response = json_decode((string) $this->response->getBody()); + + $this->assertEquals( + $response, + $this->object->create('joomla', 'joomla-platform', 'My Milestone', 'open', 'This milestone is impossible', '2012-12-25T20:09:31Z') ); } @@ -75,8 +77,7 @@ public function testCreateFailure() { $this->expectException(\DomainException::class); - $this->response->code = 501; - $this->response->body = $this->errorString; + $this->response = $this->getResponseObject($this->errorString, 501); $milestone = '{' . '"title":"My Milestone","state":"open","description":"This milestone is impossible","due_on":"2012-12-25T20:09:31Z"' @@ -85,7 +86,7 @@ public function testCreateFailure() $this->client->expects($this->once()) ->method('post') ->with('/repos/joomla/joomla-platform/milestones', $milestone) - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->object->create('joomla', 'joomla-platform', 'My Milestone', 'open', 'This milestone is impossible', '2012-12-25T20:09:31Z'); } @@ -105,11 +106,13 @@ public function testEdit() $this->client->expects($this->once()) ->method('patch') ->with('/repos/joomla/joomla-platform/milestones/523', json_encode($milestone)) - ->will($this->returnValue($this->response)); + ->willReturn($this->response); - $this->assertThat( - $this->object->edit('joomla', 'joomla-platform', 523, null, 'closed'), - $this->equalTo(json_decode($this->response->body)) + $response = json_decode((string) $this->response->getBody()); + + $this->assertEquals( + $response, + $this->object->edit('joomla', 'joomla-platform', 523, null, 'closed') ); } @@ -129,7 +132,7 @@ public function testEditAllParameters() $this->client->expects($this->once()) ->method('patch') ->with('/repos/{user}/{repo}/milestones/523', $milestone) - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->assertThat( $this->object->edit( @@ -156,8 +159,7 @@ public function testEditFailure() { $this->expectException(\DomainException::class); - $this->response->code = 500; - $this->response->body = $this->errorString; + $this->response = $this->getResponseObject($this->errorString, 500); $milestone = new \stdClass(); $milestone->state = 'closed'; @@ -165,7 +167,7 @@ public function testEditFailure() $this->client->expects($this->once()) ->method('patch') ->with('/repos/joomla/joomla-platform/milestones/523', json_encode($milestone)) - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->object->edit('joomla', 'joomla-platform', 523, null, 'closed'); } @@ -182,7 +184,7 @@ public function testGet() $this->client->expects($this->once()) ->method('get') ->with('/repos/joomla/joomla-platform/milestones/523') - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->assertThat( $this->object->get('joomla', 'joomla-platform', 523), @@ -201,13 +203,12 @@ public function testGetFailure() { $this->expectException(\DomainException::class); - $this->response->code = 500; - $this->response->body = $this->errorString; + $this->response = $this->getResponseObject($this->errorString, 500); $this->client->expects($this->once()) ->method('get') ->with('/repos/joomla/joomla-platform/milestones/523') - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->object->get('joomla', 'joomla-platform', 523); } @@ -224,7 +225,7 @@ public function testGetList() $this->client->expects($this->once()) ->method('get') ->with('/repos/joomla/joomla-platform/milestones?state=open&sort=due_date&direction=desc') - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->assertThat( $this->object->getList('joomla', 'joomla-platform'), @@ -243,13 +244,12 @@ public function testGetListFailure() { $this->expectException(\DomainException::class); - $this->response->code = 500; - $this->response->body = $this->errorString; + $this->response = $this->getResponseObject($this->errorString, 500); $this->client->expects($this->once()) ->method('get') ->with('/repos/joomla/joomla-platform/milestones?state=open&sort=due_date&direction=desc') - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->object->getList('joomla', 'joomla-platform'); } @@ -263,12 +263,12 @@ public function testGetListFailure() */ public function testDelete() { - $this->response->code = 204; + $this->response = $this->getResponseObject($this->sampleString, 204); $this->client->expects($this->once()) ->method('delete') ->with('/repos/joomla/joomla-platform/milestones/254') - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->object->delete('joomla', 'joomla-platform', 254); } @@ -284,13 +284,12 @@ public function testDeleteFailure() { $this->expectException(\DomainException::class); - $this->response->code = 504; - $this->response->body = $this->errorString; + $this->response = $this->getResponseObject($this->errorString, 504); $this->client->expects($this->once()) ->method('delete') ->with('/repos/joomla/joomla-platform/milestones/254') - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->object->delete('joomla', 'joomla-platform', 254); } diff --git a/Tests/Package/IssuesTest.php b/Tests/Package/IssuesTest.php index 5272c0f3..e8f5c8bb 100755 --- a/Tests/Package/IssuesTest.php +++ b/Tests/Package/IssuesTest.php @@ -49,7 +49,7 @@ protected function setUp(): void */ public function testCreate() { - $this->response->code = 201; + $this->response = $this->getResponseObject($this->sampleString, 201); $issue = new \stdClass(); $issue->title = '{title}'; @@ -61,7 +61,7 @@ public function testCreate() $this->client->expects($this->once()) ->method('post') ->with('/repos/{user}/{repo}/issues', json_encode($issue)) - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->assertThat( $this->object->create('{user}', '{repo}', '{title}', '{body}', '{assignee}', '{milestone}', ['{label1}']), @@ -78,7 +78,7 @@ public function testCreate() */ public function testCreate2() { - $this->response->code = 201; + $this->response = $this->getResponseObject($this->sampleString, 201); $issue = new \stdClass(); $issue->title = '{title}'; @@ -90,7 +90,7 @@ public function testCreate2() $this->client->expects($this->once()) ->method('post') ->with('/repos/{user}/{repo}/issues', json_encode($issue)) - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->assertThat( $this->object->create('{user}', '{repo}', '{title}', '{body}', null, '{milestone}', ['{label1}'], ['{assignee1}']), @@ -111,8 +111,7 @@ public function testCreateFailure() { $this->expectException(\DomainException::class); - $this->response->code = 501; - $this->response->body = $this->errorString; + $this->response = $this->getResponseObject($this->errorString, 501); $issue = new \stdClass(); $issue->title = '{title}'; @@ -124,7 +123,7 @@ public function testCreateFailure() $this->client->expects($this->once()) ->method('post') ->with('/repos/{user}/{repo}/issues', json_encode($issue)) - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->object->create('{user}', '{repo}', '{title}', '{body}', '{assignee}', '{milestone}', ['{label1}']); } @@ -138,7 +137,7 @@ public function testCreateFailure() */ public function testCreateComment() { - $this->response->code = 201; + $this->response = $this->getResponseObject($this->sampleString, 201); $issue = new \stdClass(); $issue->body = 'My Insightful Comment'; @@ -146,7 +145,7 @@ public function testCreateComment() $this->client->expects($this->once()) ->method('post') ->with('/repos/joomla/joomla-platform/issues/523/comments', json_encode($issue)) - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->assertThat( $this->object->comments->create('joomla', 'joomla-platform', 523, 'My Insightful Comment'), @@ -167,8 +166,7 @@ public function testCreateCommentFailure() { $this->expectException(\DomainException::class); - $this->response->code = 501; - $this->response->body = $this->errorString; + $this->response = $this->getResponseObject($this->errorString, 501); $issue = new \stdClass(); $issue->body = 'My Insightful Comment'; @@ -176,7 +174,7 @@ public function testCreateCommentFailure() $this->client->expects($this->once()) ->method('post') ->with('/repos/joomla/joomla-platform/issues/523/comments', json_encode($issue)) - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->object->comments->create('joomla', 'joomla-platform', 523, 'My Insightful Comment'); } @@ -201,7 +199,7 @@ public function testEdit() $this->client->expects($this->once()) ->method('patch') ->with('/repos/joomla/joomla-platform/issues/523', json_encode($issue)) - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->assertThat( $this->object->edit( @@ -232,8 +230,7 @@ public function testEditFailure() { $this->expectException(\DomainException::class); - $this->response->code = 500; - $this->response->body = $this->errorString; + $this->response = $this->getResponseObject($this->errorString, 500); $issue = new \stdClass(); $issue->title = 'My issue'; @@ -243,7 +240,7 @@ public function testEditFailure() $this->client->expects($this->once()) ->method('patch') ->with('/repos/joomla/joomla-platform/issues/523', json_encode($issue)) - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->object->edit('joomla', 'joomla-platform', 523, 'Closed', 'My issue', 'These are my changes - please review them'); } @@ -260,7 +257,7 @@ public function testGet() $this->client->expects($this->once()) ->method('get') ->with('/repos/joomla/joomla-platform/issues/523') - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->assertThat( $this->object->get('joomla', 'joomla-platform', 523), @@ -281,13 +278,12 @@ public function testGetFailure() { $this->expectException(\DomainException::class); - $this->response->code = 500; - $this->response->body = $this->errorString; + $this->response = $this->getResponseObject($this->errorString, 500); $this->client->expects($this->once()) ->method('get') ->with('/repos/joomla/joomla-platform/issues/523') - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->object->get('joomla', 'joomla-platform', 523); } @@ -304,7 +300,7 @@ public function testGetList() $this->client->expects($this->once()) ->method('get') ->with('/issues') - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->assertThat( $this->object->getList(), @@ -326,7 +322,7 @@ public function testGetListAll() $this->client->expects($this->once()) ->method('get') ->with('/issues?filter={filter}&state={state}&labels={labels}&sort={sort}&direction={direction}&since=2012-01-01T12:12:12+0000') - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->assertThat( $this->object->getList('{filter}', '{state}', '{labels}', '{sort}', '{direction}', $since), @@ -347,13 +343,12 @@ public function testGetListFailure() { $this->expectException(\DomainException::class); - $this->response->code = 500; - $this->response->body = $this->errorString; + $this->response = $this->getResponseObject($this->errorString, 500); $this->client->expects($this->once()) ->method('get') ->with('/issues') - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->object->getList(); } @@ -370,7 +365,7 @@ public function testGetListByRepository() $this->client->expects($this->once()) ->method('get') ->with('/repos/joomla/joomla-platform/issues') - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->assertThat( $this->object->getListByRepository('joomla', 'joomla-platform'), @@ -397,7 +392,7 @@ public function testGetListByRepositoryAll() '/repos/joomla/joomla-platform/issues?milestone=25&state=closed&assignee=none&' . 'mentioned=joomla-jenkins&labels=bug&sort=created&direction=asc&since=2012-01-01T12:12:12+00:00' ) - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->assertThat( $this->object->getListByRepository( @@ -429,13 +424,12 @@ public function testGetListByRepositoryFailure() { $this->expectException(\DomainException::class); - $this->response->code = 500; - $this->response->body = $this->errorString; + $this->response = $this->getResponseObject($this->errorString, 500); $this->client->expects($this->once()) ->method('get') ->with('/repos/joomla/joomla-platform/issues') - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->object->getListByRepository('joomla', 'joomla-platform'); } @@ -449,12 +443,12 @@ public function testGetListByRepositoryFailure() */ public function testLock() { - $this->response->code = 204; + $this->response = $this->getResponseObject($this->sampleString, 204); $this->client->expects($this->once()) ->method('put') ->with('/repos/joomla/joomla-platform/issues/523/lock') - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->assertThat( $this->object->lock('joomla', 'joomla-platform', 523), @@ -475,13 +469,12 @@ public function testLockFailure() { $this->expectException(\DomainException::class); - $this->response->code = 500; - $this->response->body = $this->errorString; + $this->response = $this->getResponseObject($this->errorString, 500); $this->client->expects($this->once()) ->method('put') ->with('/repos/joomla/joomla-platform/issues/523/lock') - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->object->lock('joomla', 'joomla-platform', 523); } @@ -495,12 +488,12 @@ public function testLockFailure() */ public function testUnlock() { - $this->response->code = 204; + $this->response = $this->getResponseObject($this->sampleString, 204); $this->client->expects($this->once()) ->method('delete') ->with('/repos/joomla/joomla-platform/issues/523/lock') - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->assertThat( $this->object->unlock('joomla', 'joomla-platform', 523), @@ -521,13 +514,12 @@ public function testUnlockFailure() { $this->expectException(\DomainException::class); - $this->response->code = 500; - $this->response->body = $this->errorString; + $this->response = $this->getResponseObject($this->errorString, 500); $this->client->expects($this->once()) ->method('delete') ->with('/repos/joomla/joomla-platform/issues/523/lock') - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->object->unlock('joomla', 'joomla-platform', 523); } diff --git a/Tests/Package/MarkdownTest.php b/Tests/Package/MarkdownTest.php index 8f31d555..fd2418bb 100644 --- a/Tests/Package/MarkdownTest.php +++ b/Tests/Package/MarkdownTest.php @@ -44,11 +44,11 @@ protected function setUp(): void */ public function testRender() { - $this->response->code = 200; - $this->response->body = '
Hello world Hello world github/linguist#1 cool, ' . 'and #1!
'; + $this->response = $this->getResponseObject($body); $text = 'Hello world github/linguist#1 **cool**, and #1!'; $mode = 'gfm'; @@ -69,11 +69,13 @@ public function testRender() $this->client->expects($this->once()) ->method('post') ->with('/markdown', $data, [], 0) - ->will($this->returnValue($this->response)); + ->willReturn($this->response); - $this->assertThat( - $this->object->render($text, $mode, $context), - $this->equalTo($this->response->body) + $response = (string) $this->response->getBody(); + + $this->assertEquals( + $response, + $this->object->render($text, $mode, $context) ); } @@ -101,8 +103,7 @@ public function testRenderFailure() { $this->expectException(\DomainException::class); - $this->response->code = 404; - $this->response->body = ''; + $this->response = $this->getResponseObject('', 404); $text = 'Hello world github/linguist#1 **cool**, and #1!'; $mode = 'gfm'; @@ -123,7 +124,7 @@ public function testRenderFailure() $this->client->expects($this->once()) ->method('post') ->with('/markdown', $data, [], 0) - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->assertThat( $this->object->render($text, $mode, $context), diff --git a/Tests/Package/MetaTest.php b/Tests/Package/MetaTest.php index dd20ee95..fe724c9c 100644 --- a/Tests/Package/MetaTest.php +++ b/Tests/Package/MetaTest.php @@ -60,7 +60,7 @@ public function testGetMeta() $this->client->expects($this->once()) ->method('get') ->with('/meta') - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->assertThat( $this->object->getMeta(), @@ -79,13 +79,12 @@ public function testGetMetaFailure() { $this->expectException(\DomainException::class); - $this->response->code = 500; - $this->response->body = $this->errorString; + $this->response = $this->getResponseObject($this->errorString, 500); $this->client->expects($this->once()) ->method('get') ->with('/meta') - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->object->getMeta(); } diff --git a/Tests/Package/Orgs/HooksTest.php b/Tests/Package/Orgs/HooksTest.php index b99201f5..57a2b3a2 100644 --- a/Tests/Package/Orgs/HooksTest.php +++ b/Tests/Package/Orgs/HooksTest.php @@ -51,7 +51,7 @@ public function testGetList() $this->client->expects($this->once()) ->method('get') ->with('/orgs/joomla/hooks') - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->assertThat( $this->object->getList('joomla'), @@ -71,7 +71,7 @@ public function testGet() $this->client->expects($this->once()) ->method('get') ->with('/orgs/joomla/hooks/123') - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->assertThat( $this->object->get('joomla', 123), @@ -88,12 +88,12 @@ public function testGet() */ public function testCreate() { - $this->response->code = 201; + $this->response = $this->getResponseObject($this->sampleString, 201); $this->client->expects($this->once()) ->method('post') ->with('/orgs/joomla/hooks') - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->assertThat( $this->object->create('joomla', '{url}', 'json', '{secret}'), @@ -140,12 +140,12 @@ public function testCreateInvalidEvent() */ public function testEdit() { - $this->response->code = 201; + $this->response = $this->getResponseObject($this->sampleString, 201); $this->client->expects($this->once()) ->method('post') ->with('/orgs/{org}/hooks') - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->assertThat( $this->object->edit('{org}', '{url}', 'json', '{secret}', 1, ['create'], true), @@ -190,12 +190,12 @@ public function testEditFailure2() */ public function testPing() { - $this->response->code = 204; + $this->response = $this->getResponseObject($this->sampleString, 204); $this->client->expects($this->once()) ->method('post') ->with('/orgs/{org}/hooks/123/pings') - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->assertThat( $this->object->ping('{org}', 123), @@ -212,12 +212,12 @@ public function testPing() */ public function testDelete() { - $this->response->code = 204; + $this->response = $this->getResponseObject($this->sampleString, 204); $this->client->expects($this->once()) ->method('delete') ->with('/orgs/joomla/hooks/123') - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->assertThat( $this->object->delete('joomla', 123), diff --git a/Tests/Package/Orgs/MembersTest.php b/Tests/Package/Orgs/MembersTest.php index 604ed50a..a3eb6fe1 100644 --- a/Tests/Package/Orgs/MembersTest.php +++ b/Tests/Package/Orgs/MembersTest.php @@ -51,7 +51,7 @@ public function testGetList() $this->client->expects($this->once()) ->method('get') ->with('/orgs/joomla/members') - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->assertThat( $this->object->getList('joomla'), @@ -68,12 +68,12 @@ public function testGetList() */ public function testGetListNotAMember() { - $this->response->code = 302; + $this->response = $this->getResponseObject($this->sampleString, 302); $this->client->expects($this->once()) ->method('get') ->with('/orgs/joomla/members') - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->assertThat( $this->object->getList('joomla'), @@ -90,14 +90,14 @@ public function testGetListNotAMember() */ public function testGetListUnexpected() { - $this->expectException(\UnexpectedValueException::class); + $this->expectException(\Laminas\Diactoros\Exception\InvalidArgumentException::class); - $this->response->code = 666; + $this->response = $this->getResponseObject($this->sampleString, 666); $this->client->expects($this->once()) ->method('get') ->with('/orgs/joomla/members') - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->assertThat( $this->object->getList('joomla'), @@ -114,12 +114,12 @@ public function testGetListUnexpected() */ public function testCheck() { - $this->response->code = 204; + $this->response = $this->getResponseObject($this->sampleString, 204); $this->client->expects($this->once()) ->method('get') ->with('/orgs/joomla/members/elkuku') - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->assertThat( $this->object->check('joomla', 'elkuku'), @@ -136,12 +136,12 @@ public function testCheck() */ public function testCheckNoMember() { - $this->response->code = 404; + $this->response = $this->getResponseObject($this->sampleString, 404); $this->client->expects($this->once()) ->method('get') ->with('/orgs/joomla/members/elkuku') - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->assertThat( $this->object->check('joomla', 'elkuku'), @@ -158,12 +158,12 @@ public function testCheckNoMember() */ public function testCheckRequesterNoMember() { - $this->response->code = 302; + $this->response = $this->getResponseObject($this->sampleString, 302); $this->client->expects($this->once()) ->method('get') ->with('/orgs/joomla/members/elkuku') - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->assertThat( $this->object->check('joomla', 'elkuku'), @@ -180,14 +180,14 @@ public function testCheckRequesterNoMember() */ public function testCheckUnexpectedr() { - $this->expectException(\UnexpectedValueException::class); + $this->expectException(\Laminas\Diactoros\Exception\InvalidArgumentException::class); - $this->response->code = 666; + $this->response = $this->getResponseObject($this->sampleString, 666); $this->client->expects($this->once()) ->method('get') ->with('/orgs/joomla/members/elkuku') - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->assertThat( $this->object->check('joomla', 'elkuku'), @@ -204,12 +204,12 @@ public function testCheckUnexpectedr() */ public function testRemove() { - $this->response->code = 204; + $this->response = $this->getResponseObject($this->sampleString, 204); $this->client->expects($this->once()) ->method('delete') ->with('/orgs/joomla/members/elkuku') - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->assertThat( $this->object->remove('joomla', 'elkuku'), @@ -229,7 +229,7 @@ public function testGetListPublic() $this->client->expects($this->once()) ->method('get') ->with('/orgs/joomla/public_members') - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->assertThat( $this->object->getListPublic('joomla'), @@ -246,12 +246,12 @@ public function testGetListPublic() */ public function testCheckPublic() { - $this->response->code = 204; + $this->response = $this->getResponseObject($this->sampleString, 204); $this->client->expects($this->once()) ->method('get') ->with('/orgs/joomla/public_members/elkuku') - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->assertThat( $this->object->checkPublic('joomla', 'elkuku'), @@ -268,12 +268,12 @@ public function testCheckPublic() */ public function testCheckPublicNo() { - $this->response->code = 404; + $this->response = $this->getResponseObject($this->sampleString, 404); $this->client->expects($this->once()) ->method('get') ->with('/orgs/joomla/public_members/elkuku') - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->assertThat( $this->object->checkPublic('joomla', 'elkuku'), @@ -290,14 +290,14 @@ public function testCheckPublicNo() */ public function testCheckPublicUnexpected() { - $this->expectException(\UnexpectedValueException::class); + $this->expectException(\Laminas\Diactoros\Exception\InvalidArgumentException::class); - $this->response->code = 666; + $this->response = $this->getResponseObject($this->sampleString, 666); $this->client->expects($this->once()) ->method('get') ->with('/orgs/joomla/public_members/elkuku') - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->assertThat( $this->object->checkPublic('joomla', 'elkuku'), @@ -314,12 +314,12 @@ public function testCheckPublicUnexpected() */ public function testPublicize() { - $this->response->code = 204; + $this->response = $this->getResponseObject($this->sampleString, 204); $this->client->expects($this->once()) ->method('put') ->with('/orgs/joomla/public_members/elkuku') - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->assertThat( $this->object->publicize('joomla', 'elkuku'), @@ -336,12 +336,12 @@ public function testPublicize() */ public function testConceal() { - $this->response->code = 204; + $this->response = $this->getResponseObject($this->sampleString, 204); $this->client->expects($this->once()) ->method('delete') ->with('/orgs/joomla/public_members/elkuku') - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->assertThat( $this->object->conceal('joomla', 'elkuku'), @@ -361,7 +361,7 @@ public function testGetMembership() $this->client->expects($this->once()) ->method('get') ->with('/orgs/{org}/memberships/{user}') - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->assertThat( $this->object->getMembership('{org}', '{user}'), @@ -381,7 +381,7 @@ public function testUpdateMembership() $this->client->expects($this->once()) ->method('put') ->with('/orgs/{org}/memberships/{user}') - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->assertThat( $this->object->updateMembership('{org}', '{user}'), @@ -413,12 +413,12 @@ public function testUpdateMembershipInvalidRole() */ public function testRemoveMembership() { - $this->response->code = 204; + $this->response = $this->getResponseObject($this->sampleString, 204); $this->client->expects($this->once()) ->method('delete') ->with('/orgs/{org}/memberships/{user}') - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->assertThat( $this->object->removeMembership('{org}', '{user}'), @@ -438,7 +438,7 @@ public function testListMemberships() $this->client->expects($this->once()) ->method('get') ->with('/user/memberships/orgs') - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->assertThat( $this->object->listMemberships(), @@ -458,7 +458,7 @@ public function testListOrganizationMemberships() $this->client->expects($this->once()) ->method('get') ->with('/user/memberships/orgs/{org}') - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->assertThat( $this->object->listOrganizationMembership('{org}'), @@ -478,7 +478,7 @@ public function testEditOrganizationMemberships() $this->client->expects($this->once()) ->method('patch') ->with('/user/memberships/orgs/{org}') - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->assertThat( $this->object->editOrganizationMembership('{org}', 'active'), diff --git a/Tests/Package/Orgs/TeamsTest.php b/Tests/Package/Orgs/TeamsTest.php index 2e55c2dd..a95123e8 100644 --- a/Tests/Package/Orgs/TeamsTest.php +++ b/Tests/Package/Orgs/TeamsTest.php @@ -51,7 +51,7 @@ public function testGetList() $this->client->expects($this->once()) ->method('get') ->with('/orgs/joomla/teams') - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->assertThat( $this->object->getList('joomla'), @@ -71,7 +71,7 @@ public function testGet() $this->client->expects($this->once()) ->method('get') ->with('/teams/123') - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->assertThat( $this->object->get(123), @@ -88,12 +88,12 @@ public function testGet() */ public function testCreate() { - $this->response->code = 201; + $this->response = $this->getResponseObject($this->sampleString, 201); $this->client->expects($this->once()) ->method('post') ->with('/orgs/joomla/teams') - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->assertThat( $this->object->create('joomla', 'TheTeam', ['joomla-platform'], 'admin'), @@ -112,7 +112,7 @@ public function testCreateWrongPermission() { $this->expectException(\UnexpectedValueException::class); - $this->response->code = 201; + $this->response = $this->getResponseObject($this->sampleString, 201); $this->object->create('joomla', 'TheTeam', ['joomla-platform'], 'invalid'); } @@ -129,7 +129,7 @@ public function testEdit() $this->client->expects($this->once()) ->method('patch') ->with('/teams/123') - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->assertThat( $this->object->edit(123, 'TheTeam', 'admin'), @@ -160,12 +160,12 @@ public function testEditWrongPermission() */ public function testDelete() { - $this->response->code = 204; + $this->response = $this->getResponseObject($this->sampleString, 204); $this->client->expects($this->once()) ->method('delete') ->with('/teams/123') - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->assertThat( $this->object->delete(123), @@ -185,7 +185,7 @@ public function testGetListMembers() $this->client->expects($this->once()) ->method('get') ->with('/teams/123/members') - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->assertThat( $this->object->getListMembers(123), @@ -204,12 +204,12 @@ public function testGetListMembers() */ public function testIsMember() { - $this->response->code = 204; + $this->response = $this->getResponseObject($this->sampleString, 204); $this->client->expects($this->once()) ->method('get') ->with('/teams/123/members/elkuku') - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->assertThat( $this->object->isMember(123, 'elkuku'), @@ -228,12 +228,12 @@ public function testIsMember() */ public function testIsMemberNo() { - $this->response->code = 404; + $this->response = $this->getResponseObject($this->sampleString, 404); $this->client->expects($this->once()) ->method('get') ->with('/teams/123/members/elkuku') - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->assertThat( $this->object->isMember(123, 'elkuku'), @@ -252,14 +252,14 @@ public function testIsMemberNo() */ public function testIsMemberUnexpected() { - $this->expectException(\UnexpectedValueException::class); + $this->expectException(\Laminas\Diactoros\Exception\InvalidArgumentException::class); - $this->response->code = 666; + $this->response = $this->getResponseObject($this->sampleString, 666); $this->client->expects($this->once()) ->method('get') ->with('/teams/123/members/elkuku') - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->assertThat( $this->object->isMember(123, 'elkuku'), @@ -278,12 +278,12 @@ public function testIsMemberUnexpected() */ public function testAddMember() { - $this->response->code = 204; + $this->response = $this->getResponseObject($this->sampleString, 204); $this->client->expects($this->once()) ->method('put') ->with('/teams/123/members/elkuku') - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->assertThat( $this->object->addMember(123, 'elkuku'), @@ -302,12 +302,12 @@ public function testAddMember() */ public function testRemoveMember() { - $this->response->code = 204; + $this->response = $this->getResponseObject($this->sampleString, 204); $this->client->expects($this->once()) ->method('delete') ->with('/teams/123/members/elkuku') - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->assertThat( $this->object->removeMember(123, 'elkuku'), @@ -327,7 +327,7 @@ public function testGetListRepos() $this->client->expects($this->once()) ->method('get') ->with('/teams/123/repos') - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->assertThat( $this->object->getListRepos(123), @@ -344,12 +344,12 @@ public function testGetListRepos() */ public function testCheckRepo() { - $this->response->code = 204; + $this->response = $this->getResponseObject($this->sampleString, 204); $this->client->expects($this->once()) ->method('get') ->with('/teams/123/repos/joomla/cms') - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->assertThat( $this->object->checkRepo(123, 'joomla', 'cms'), @@ -366,12 +366,12 @@ public function testCheckRepo() */ public function testCheckRepoNo() { - $this->response->code = 404; + $this->response = $this->getResponseObject($this->sampleString, 404); $this->client->expects($this->once()) ->method('get') ->with('/teams/123/repos/joomla/cms') - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->assertThat( $this->object->checkRepo(123, 'joomla', 'cms'), @@ -388,14 +388,14 @@ public function testCheckRepoNo() */ public function testCheckRepoUnexpected() { - $this->expectException(\UnexpectedValueException::class); + $this->expectException(\Laminas\Diactoros\Exception\InvalidArgumentException::class); - $this->response->code = 666; + $this->response = $this->getResponseObject($this->sampleString, 666); $this->client->expects($this->once()) ->method('get') ->with('/teams/123/repos/joomla/cms') - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->assertThat( $this->object->checkRepo(123, 'joomla', 'cms'), @@ -412,12 +412,12 @@ public function testCheckRepoUnexpected() */ public function testAddRepo() { - $this->response->code = 204; + $this->response = $this->getResponseObject($this->sampleString, 204); $this->client->expects($this->once()) ->method('put') ->with('/teams/123/repos/joomla/joomla-platform') - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->assertThat( $this->object->addRepo(123, 'joomla', 'joomla-platform'), @@ -434,12 +434,12 @@ public function testAddRepo() */ public function testRemoveRepo() { - $this->response->code = 204; + $this->response = $this->getResponseObject($this->sampleString, 204); $this->client->expects($this->once()) ->method('delete') ->with('/teams/123/repos/joomla/joomla-platform') - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->assertThat( $this->object->removeRepo(123, 'joomla', 'joomla-platform'), @@ -456,13 +456,13 @@ public function testRemoveRepo() */ public function testGetTeamMemberships() { - $this->response->code = 200; - $this->response->body = '{"state":"TEST"}'; + $body = '{"state":"TEST"}'; + $this->response = $this->getResponseObject($body); $this->client->expects($this->once()) ->method('get') ->with('/teams/123/memberships/{user}') - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->assertThat( $this->object->getTeamMembership(123, '{user}'), @@ -481,13 +481,13 @@ public function testGetTeamMemberships() */ public function testGetTeamMembershipsFailure1() { - $this->response->code = 404; - $this->response->body = '{"state":"TEST"}'; + $body = '{"state":"TEST"}'; + $this->response = $this->getResponseObject($body, 404); $this->client->expects($this->once()) ->method('get') ->with('/teams/123/memberships/{user}') - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->assertThat( $this->object->getTeamMembership(123, '{user}'), @@ -506,16 +506,14 @@ public function testGetTeamMembershipsFailure1() */ public function testGetTeamMembershipsFailure2() { - $this->expectException(\UnexpectedValueException::class); - $this->expectExceptionMessage('Unexpected response code: 666'); + $this->expectException(\Laminas\Diactoros\Exception\InvalidArgumentException::class); - $this->response->code = 666; - $this->response->body = '{"state":"TEST"}'; + $this->response = $this->getResponseObject('{"state":"TEST"}', 666); $this->client->expects($this->once()) ->method('get') ->with('/teams/123/memberships/{user}') - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->assertThat( $this->object->getTeamMembership(123, '{user}'), @@ -535,7 +533,7 @@ public function testAddTeamMemberships() $this->client->expects($this->once()) ->method('put') ->with('/teams/123/memberships/{user}') - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->assertThat( $this->object->addTeamMembership(123, '{user}'), @@ -569,12 +567,12 @@ public function testAddTeamMembershipsFailure() */ public function testRemoveTeamMemberships() { - $this->response->code = 204; + $this->response = $this->getResponseObject($this->sampleString, 204); $this->client->expects($this->once()) ->method('delete') ->with('/teams/123/memberships/{user}') - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->assertThat( $this->object->removeTeamMembership(123, '{user}'), @@ -594,7 +592,7 @@ public function testGetUserTeams() $this->client->expects($this->once()) ->method('get') ->with('/user/teams') - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->assertThat( $this->object->getUserTeams(), diff --git a/Tests/Package/OrgsTest.php b/Tests/Package/OrgsTest.php index 28acae74..a35b23eb 100644 --- a/Tests/Package/OrgsTest.php +++ b/Tests/Package/OrgsTest.php @@ -47,7 +47,7 @@ public function testGetList() $this->client->expects($this->once()) ->method('get') ->with('/users/joomla/orgs') - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->assertThat( $this->object->getList('joomla'), @@ -65,7 +65,7 @@ public function testGet() $this->client->expects($this->once()) ->method('get') ->with('/orgs/joomla') - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->assertThat( $this->object->get('joomla'), @@ -83,7 +83,7 @@ public function testEdit() $this->client->expects($this->once()) ->method('patch') ->with('/orgs/joomla') - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->assertThat( $this->object->edit('joomla', 'email@example.com'), diff --git a/Tests/Package/Pulls/CommentsTest.php b/Tests/Package/Pulls/CommentsTest.php index faaea5a5..1c48d82c 100644 --- a/Tests/Package/Pulls/CommentsTest.php +++ b/Tests/Package/Pulls/CommentsTest.php @@ -48,17 +48,19 @@ protected function setUp(): void */ public function testCreate() { - $this->response->code = 201; + $this->response = $this->getResponseObject($this->sampleString, 201); $data = '{"body":"The Body","commit_id":"123abc","path":"a\/b\/c","position":456}'; $this->client->expects($this->once()) ->method('post') ->with('/repos/joomla/joomla-platform/pulls/1/comments', $data, [], 0) - ->will($this->returnValue($this->response)); + ->willReturn($this->response); - $this->assertThat( - $this->object->create('joomla', 'joomla-platform', 1, 'The Body', '123abc', 'a/b/c', 456), - $this->equalTo(json_decode($this->response->body)) + $response = json_decode((string) $this->response->getBody()); + + $this->assertEquals( + $response, + $this->object->create('joomla', 'joomla-platform', 1, 'The Body', '123abc', 'a/b/c', 456) ); } @@ -71,16 +73,18 @@ public function testCreate() */ public function testCreateReply() { - $this->response->code = 201; + $this->response = $this->getResponseObject($this->sampleString, 201); $this->client->expects($this->once()) ->method('post') ->with('/repos/joomla/joomla-platform/pulls/1/comments', '{"body":"The Body","in_reply_to":456}', [], 0) - ->will($this->returnValue($this->response)); + ->willReturn($this->response); + + $response = json_decode((string) $this->response->getBody()); - $this->assertThat( - $this->object->createReply('joomla', 'joomla-platform', 1, 'The Body', 456), - $this->equalTo(json_decode($this->response->body)) + $this->assertEquals( + $response, + $this->object->createReply('joomla', 'joomla-platform', 1, 'The Body', 456) ); } @@ -93,17 +97,18 @@ public function testCreateReply() */ public function testDelete() { - $this->response->code = 204; - $this->response->body = ''; + $this->response = $this->getResponseObject('', 204); $this->client->expects($this->once()) ->method('delete') ->with('/repos/joomla/joomla-platform/pulls/comments/456', [], 0) - ->will($this->returnValue($this->response)); + ->willReturn($this->response); - $this->assertThat( - $this->object->delete('joomla', 'joomla-platform', 456), - $this->equalTo(json_decode($this->response->body)) + $response = json_decode((string) $this->response->getBody()); + + $this->assertEquals( + $response, + $this->object->delete('joomla', 'joomla-platform', 456) ); } @@ -116,17 +121,18 @@ public function testDelete() */ public function testEdit() { - $this->response->code = 200; - $this->response->body = ''; + $this->response = $this->getResponseObject(''); $this->client->expects($this->once()) ->method('patch') ->with('/repos/joomla/joomla-platform/pulls/comments/456', '{"body":"Hello"}', [], 0) - ->will($this->returnValue($this->response)); + ->willReturn($this->response); + + $response = json_decode((string) $this->response->getBody()); - $this->assertThat( - $this->object->edit('joomla', 'joomla-platform', 456, 'Hello'), - $this->equalTo(json_decode($this->response->body)) + $this->assertEquals( + $response, + $this->object->edit('joomla', 'joomla-platform', 456, 'Hello') ); } @@ -142,11 +148,13 @@ public function testGet() $this->client->expects($this->once()) ->method('get') ->with('/repos/joomla/joomla-platform/pulls/comments/456', [], 0) - ->will($this->returnValue($this->response)); + ->willReturn($this->response); - $this->assertThat( - $this->object->get('joomla', 'joomla-platform', 456), - $this->equalTo(json_decode($this->response->body)) + $response = json_decode((string) $this->response->getBody()); + + $this->assertEquals( + $response, + $this->object->get('joomla', 'joomla-platform', 456) ); } @@ -162,11 +170,13 @@ public function testGetList() $this->client->expects($this->once()) ->method('get') ->with('/repos/joomla/joomla-platform/pulls/456/comments', [], 0) - ->will($this->returnValue($this->response)); + ->willReturn($this->response); + + $response = json_decode((string) $this->response->getBody()); - $this->assertThat( - $this->object->getList('joomla', 'joomla-platform', 456), - $this->equalTo(json_decode($this->response->body)) + $this->assertEquals( + $response, + $this->object->getList('joomla', 'joomla-platform', 456) ); } @@ -182,11 +192,13 @@ public function testGetListForRepo() $this->client->expects($this->once()) ->method('get') ->with('/repos/{user}/{repo}/pulls/comments', [], 0) - ->will($this->returnValue($this->response)); + ->willReturn($this->response); + + $response = json_decode((string) $this->response->getBody()); - $this->assertThat( - $this->object->getListForRepo('{user}', '{repo}'), - $this->equalTo(json_decode($this->response->body)) + $this->assertEquals( + $response, + $this->object->getListForRepo('{user}', '{repo}') ); } } diff --git a/Tests/Package/PullsTest.php b/Tests/Package/PullsTest.php index e75bd4d6..bfc3a1b4 100755 --- a/Tests/Package/PullsTest.php +++ b/Tests/Package/PullsTest.php @@ -5,7 +5,7 @@ * @license GNU General Public License version 2 or later; see LICENSE */ -namespace Joomla\Github\Tests; +namespace Joomla\Github\Tests\Package; use Joomla\Github\Package\Pulls; use Joomla\Github\Tests\Stub\GitHubTestCase; @@ -15,7 +15,7 @@ * * @since 1.0 */ -class JGithubPackagePullsTest extends GitHubTestCase +class PullsTest extends GitHubTestCase { /** * @var Pulls @@ -44,7 +44,7 @@ protected function setUp(): void */ public function testCreate() { - $this->response->code = 201; + $this->response = $this->getResponseObject($this->sampleString, 201); $pull = new \stdClass(); $pull->title = 'My Pull Request'; @@ -55,7 +55,7 @@ public function testCreate() $this->client->expects($this->once()) ->method('post') ->with('/repos/joomla/joomla-platform/pulls', json_encode($pull)) - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->assertThat( $this->object->create( @@ -79,8 +79,7 @@ public function testCreateFailure() { $this->expectException(\DomainException::class); - $this->response->code = 501; - $this->response->body = $this->errorString; + $this->getResponseObject($this->errorString, 501); $pull = new \stdClass(); $pull->title = 'My Pull Request'; @@ -91,7 +90,7 @@ public function testCreateFailure() $this->client->expects($this->once()) ->method('post') ->with('/repos/joomla/joomla-platform/pulls', json_encode($pull)) - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->object->create( 'joomla', @@ -110,7 +109,7 @@ public function testCreateFailure() */ public function testCreateFromIssue() { - $this->response->code = 201; + $this->response = $this->getResponseObject($this->sampleString, 201); $pull = new \stdClass(); $pull->issue = 254; @@ -120,7 +119,7 @@ public function testCreateFromIssue() $this->client->expects($this->once()) ->method('post') ->with('/repos/joomla/joomla-platform/pulls', json_encode($pull)) - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->assertThat( $this->object->createFromIssue('joomla', 'joomla-platform', 254, 'staging', 'joomla-jenkins:mychanges'), @@ -137,8 +136,7 @@ public function testCreateFromIssueFailure() { $this->expectException(\DomainException::class); - $this->response->code = 501; - $this->response->body = $this->errorString; + $this->response = $this->getResponseObject($this->errorString, 501); $pull = new \stdClass(); $pull->issue = 254; @@ -148,7 +146,7 @@ public function testCreateFromIssueFailure() $this->client->expects($this->once()) ->method('post') ->with('/repos/joomla/joomla-platform/pulls', json_encode($pull)) - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->object->createFromIssue('joomla', 'joomla-platform', 254, 'staging', 'joomla-jenkins:mychanges'); } @@ -169,7 +167,7 @@ public function testEdit() $this->client->expects($this->once()) ->method('patch') ->with('/repos/joomla/joomla-platform/pulls/523', json_encode($pull)) - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->assertThat( $this->object->edit('joomla', 'joomla-platform', 523, 'My Pull Request', 'These are my changes - please review them', 'Closed', 'new'), @@ -186,8 +184,7 @@ public function testEditFailure() { $this->expectException(\DomainException::class); - $this->response->code = 500; - $this->response->body = $this->errorString; + $this->response = $this->getResponseObject($this->errorString, 500); $pull = new \stdClass(); $pull->title = 'My Pull Request'; @@ -196,7 +193,7 @@ public function testEditFailure() $this->client->expects($this->once()) ->method('patch') ->with('/repos/joomla/joomla-platform/pulls/523', json_encode($pull)) - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->object->edit('joomla', 'joomla-platform', 523, 'My Pull Request', 'These are my changes - please review them'); } @@ -211,7 +208,7 @@ public function testGet() $this->client->expects($this->once()) ->method('get') ->with('/repos/joomla/joomla-platform/pulls/523') - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->assertThat( $this->object->get('joomla', 'joomla-platform', 523), @@ -228,13 +225,12 @@ public function testGetFailure() { $this->expectException(\DomainException::class); - $this->response->code = 500; - $this->response->body = $this->errorString; + $this->response = $this->getResponseObject($this->errorString, 500); $this->client->expects($this->once()) ->method('get') ->with('/repos/joomla/joomla-platform/pulls/523') - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->object->get('joomla', 'joomla-platform', 523); } @@ -249,7 +245,7 @@ public function testGetCommits() $this->client->expects($this->once()) ->method('get') ->with('/repos/joomla/joomla-platform/pulls/523/commits') - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->assertThat( $this->object->getCommits('joomla', 'joomla-platform', 523), @@ -266,13 +262,12 @@ public function testGetCommitsFailure() { $this->expectException(\DomainException::class); - $this->response->code = 500; - $this->response->body = $this->errorString; + $this->response = $this->getResponseObject($this->errorString, 500); $this->client->expects($this->once()) ->method('get') ->with('/repos/joomla/joomla-platform/pulls/523/commits') - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->object->getCommits('joomla', 'joomla-platform', 523); } @@ -287,7 +282,7 @@ public function testGetFiles() $this->client->expects($this->once()) ->method('get') ->with('/repos/joomla/joomla-platform/pulls/523/files') - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->assertThat( $this->object->getFiles('joomla', 'joomla-platform', 523), @@ -304,13 +299,12 @@ public function testGetFilesFailure() { $this->expectException(\DomainException::class); - $this->response->code = 500; - $this->response->body = $this->errorString; + $this->response = $this->getResponseObject($this->errorString, 500); $this->client->expects($this->once()) ->method('get') ->with('/repos/joomla/joomla-platform/pulls/523/files') - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->object->getFiles('joomla', 'joomla-platform', 523); } @@ -325,7 +319,7 @@ public function testGetList() $this->client->expects($this->once()) ->method('get') ->with('/repos/joomla/joomla-platform/pulls?state=closed') - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->assertThat( $this->object->getList('joomla', 'joomla-platform', 'closed'), @@ -342,13 +336,12 @@ public function testGetListFailure() { $this->expectException(\DomainException::class); - $this->response->code = 500; - $this->response->body = $this->errorString; + $this->response = $this->getResponseObject($this->errorString, 500); $this->client->expects($this->once()) ->method('get') ->with('/repos/joomla/joomla-platform/pulls') - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->object->getList('joomla', 'joomla-platform'); } @@ -360,12 +353,12 @@ public function testGetListFailure() */ public function testIsMergedTrue() { - $this->response->code = 204; + $this->response = $this->getResponseObject($this->sampleString, 204); $this->client->expects($this->once()) ->method('get') ->with('/repos/joomla/joomla-platform/pulls/523/merge') - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->assertThat( $this->object->isMerged('joomla', 'joomla-platform', 523), @@ -380,12 +373,12 @@ public function testIsMergedTrue() */ public function testIsMergedFalse() { - $this->response->code = 404; + $this->response = $this->getResponseObject($this->sampleString, 404); $this->client->expects($this->once()) ->method('get') ->with('/repos/joomla/joomla-platform/pulls/523/merge') - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->assertThat( $this->object->isMerged('joomla', 'joomla-platform', 523), @@ -402,13 +395,12 @@ public function testIsMergedFailure() { $this->expectException(\DomainException::class); - $this->response->code = 504; - $this->response->body = $this->errorString; + $this->response = $this->getResponseObject($this->errorString, 504); $this->client->expects($this->once()) ->method('get') ->with('/repos/joomla/joomla-platform/pulls/523/merge') - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->object->isMerged('joomla', 'joomla-platform', 523); } @@ -423,7 +415,7 @@ public function testMerge() $this->client->expects($this->once()) ->method('put') ->with('/repos/joomla/joomla-platform/pulls/523/merge') - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->assertThat( $this->object->merge('joomla', 'joomla-platform', 523), @@ -440,13 +432,12 @@ public function testMergeFailure() { $this->expectException(\DomainException::class); - $this->response->code = 500; - $this->response->body = $this->errorString; + $this->response = $this->getResponseObject($this->errorString, 500); $this->client->expects($this->once()) ->method('put') ->with('/repos/joomla/joomla-platform/pulls/523/merge') - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->object->merge('joomla', 'joomla-platform', 523); } diff --git a/Tests/Package/Repositories/BranchesTest.php b/Tests/Package/Repositories/BranchesTest.php index c9899301..c2b29391 100644 --- a/Tests/Package/Repositories/BranchesTest.php +++ b/Tests/Package/Repositories/BranchesTest.php @@ -51,7 +51,7 @@ public function testGetList() $this->client->expects($this->once()) ->method('get') ->with('/repos/{owner}/{repo}/branches') - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->assertThat( $this->object->getList('{owner}', '{repo}'), @@ -71,7 +71,7 @@ public function testGet() $this->client->expects($this->once()) ->method('get') ->with('/repos/{owner}/{repo}/branches/{branch}') - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->assertThat( $this->object->get('{owner}', '{repo}', '{branch}'), diff --git a/Tests/Package/Repositories/CollaboratorsTest.php b/Tests/Package/Repositories/CollaboratorsTest.php index d365db94..e7d69317 100644 --- a/Tests/Package/Repositories/CollaboratorsTest.php +++ b/Tests/Package/Repositories/CollaboratorsTest.php @@ -47,7 +47,7 @@ public function testGetList() $this->client->expects($this->once()) ->method('get') ->with('/repos/joomla/joomla-framework/collaborators') - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->assertThat( $this->object->getList('joomla', 'joomla-framework'), @@ -62,17 +62,18 @@ public function testGetList() */ public function testGet() { - $this->response->code = 204; - $this->response->body = true; + $this->response = $this->getResponseObject(true, 204); $this->client->expects($this->once()) ->method('get') ->with('/repos/joomla/joomla-framework/collaborators/elkuku') - ->will($this->returnValue($this->response)); + ->willReturn($this->response); - $this->assertThat( - $this->object->get('joomla', 'joomla-framework', 'elkuku'), - $this->equalTo($this->response->body) + $response = (string) $this->response->getBody(); + + $this->assertEquals( + $response, + $this->object->get('joomla', 'joomla-framework', 'elkuku') ); } @@ -83,17 +84,18 @@ public function testGet() */ public function testGetNegative() { - $this->response->code = 404; - $this->response->body = false; + $this->response = $this->getResponseObject(false, 404); $this->client->expects($this->once()) ->method('get') ->with('/repos/joomla/joomla-framework/collaborators/elkuku') - ->will($this->returnValue($this->response)); + ->willReturn($this->response); - $this->assertThat( - $this->object->get('joomla', 'joomla-framework', 'elkuku'), - $this->equalTo($this->response->body) + $response = (string) $this->response->getBody(); + + $this->assertEquals( + $response, + $this->object->get('joomla', 'joomla-framework', 'elkuku') ); } @@ -104,19 +106,20 @@ public function testGetNegative() */ public function testGetUnexpected() { - $this->expectException(\UnexpectedValueException::class); + $this->expectException(\Laminas\Diactoros\Exception\InvalidArgumentException::class); - $this->response->code = 666; - $this->response->body = null; + $this->response = $this->getResponseObject(null, 666); $this->client->expects($this->once()) ->method('get') ->with('/repos/joomla/joomla-framework/collaborators/elkuku') - ->will($this->returnValue($this->response)); + ->willReturn($this->response); - $this->assertThat( - $this->object->get('joomla', 'joomla-framework', 'elkuku'), - $this->equalTo($this->response->body) + $response = (string) $this->response->getBody(); + + $this->assertEquals( + $response, + $this->object->get('joomla', 'joomla-framework', 'elkuku') ); } @@ -127,12 +130,12 @@ public function testGetUnexpected() */ public function testAdd() { - $this->response->code = 204; + $this->response = $this->getResponseObject($this->sampleString, 204); $this->client->expects($this->once()) ->method('put') ->with('/repos/joomla/joomla-framework/collaborators/elkuku') - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->assertThat( $this->object->add('joomla', 'joomla-framework', 'elkuku'), @@ -147,12 +150,12 @@ public function testAdd() */ public function testRemove() { - $this->response->code = 204; + $this->response = $this->getResponseObject($this->sampleString, 204); $this->client->expects($this->once()) ->method('delete') ->with('/repos/joomla/joomla-framework/collaborators/elkuku') - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->assertThat( $this->object->remove('joomla', 'joomla-framework', 'elkuku'), diff --git a/Tests/Package/Repositories/CommentsTest.php b/Tests/Package/Repositories/CommentsTest.php index 0b6e441d..1912fb13 100644 --- a/Tests/Package/Repositories/CommentsTest.php +++ b/Tests/Package/Repositories/CommentsTest.php @@ -47,7 +47,7 @@ public function testGetListRepository() $this->client->expects($this->once()) ->method('get') ->with('/repos/joomla/joomla-framework/comments') - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->assertThat( $this->object->getListRepository('joomla', 'joomla-framework'), @@ -65,7 +65,7 @@ public function testGetList() $this->client->expects($this->once()) ->method('get') ->with('/repos/joomla/joomla-framework/commits/123/comments') - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->assertThat( $this->object->getList('joomla', 'joomla-framework', '123'), @@ -83,7 +83,7 @@ public function testGet() $this->client->expects($this->once()) ->method('get') ->with('/repos/joomla/joomla-framework/comments/123') - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->assertThat( $this->object->get('joomla', 'joomla-framework', 123), @@ -101,7 +101,7 @@ public function testEdit() $this->client->expects($this->once()) ->method('patch') ->with('/repos/joomla/joomla-framework/comments/123') - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->assertThat( $this->object->edit('joomla', 'joomla-framework', 123, 'My Comment'), @@ -116,12 +116,12 @@ public function testEdit() */ public function testDelete() { - $this->response->code = 204; + $this->response = $this->getResponseObject($this->sampleString, 204); $this->client->expects($this->once()) ->method('delete') ->with('/repos/joomla/joomla-framework/comments/123') - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->assertThat( $this->object->delete('joomla', 'joomla-framework', 123), @@ -136,12 +136,12 @@ public function testDelete() */ public function testCreate() { - $this->response->code = 201; + $this->response = $this->getResponseObject($this->sampleString, 201); $this->client->expects($this->once()) ->method('post') ->with('/repos/joomla/joomla-framework/commits/123abc/comments') - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->assertThat( $this->object->create('joomla', 'joomla-framework', '123abc', 'My Comment', 456, 'path/file.php', 789), diff --git a/Tests/Package/Repositories/CommitsTest.php b/Tests/Package/Repositories/CommitsTest.php index 1d7e9065..319c4a57 100644 --- a/Tests/Package/Repositories/CommitsTest.php +++ b/Tests/Package/Repositories/CommitsTest.php @@ -55,7 +55,7 @@ public function testGet() $this->client->expects($this->once()) ->method('get') ->with('/repos/joomla/joomla-platform/commits/abc1234') - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->assertThat( $this->object->get('joomla', 'joomla-platform', 'abc1234'), @@ -77,13 +77,12 @@ public function testGetFailure() $this->expectException(\DomainException::class); $this->expectExceptionMessage('Generic Error'); - $this->response->code = 500; - $this->response->body = $this->errorString; + $this->response = $this->getResponseObject($this->errorString, 500); $this->client->expects($this->once()) ->method('get') ->with('/repos/joomla/joomla-platform/commits/abc1234') - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->object->get('joomla', 'joomla-platform', 'abc1234'); } @@ -102,7 +101,7 @@ public function testGetList() $this->client->expects($this->once()) ->method('get') ->with('/repos/joomla/joomla-platform/commits') - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->assertThat( $this->object->getList('joomla', 'joomla-platform'), @@ -124,13 +123,12 @@ public function testGetListFailure() $this->expectException(\DomainException::class); $this->expectExceptionMessage('Generic Error'); - $this->response->code = 500; - $this->response->body = $this->errorString; + $this->response = $this->getResponseObject($this->errorString, 500); $this->client->expects($this->once()) ->method('get') ->with('/repos/joomla/joomla-platform/commits') - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->object->getList('joomla', 'joomla-platform'); } @@ -149,7 +147,7 @@ public function testCompare() $this->client->expects($this->once()) ->method('get') ->with('/repos/joomla/joomla-platform/compare/123abc...456def') - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->assertThat( $this->object->compare('joomla', 'joomla-platform', '123abc', '456def'), @@ -171,7 +169,7 @@ public function testgetSha() $this->client->expects($this->once()) ->method('get') ->with('/repos/{user}/{repo}/commits/{ref}') - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->assertThat( $this->object->getSha('{user}', '{repo}', '{ref}'), @@ -190,15 +188,14 @@ public function testgetSha() */ public function testgetShaFailure() { - $this->expectException(UnexpectedResponseException::class); - $this->expectExceptionMessage('Invalid response received from GitHub.'); + $this->expectException(\Laminas\Diactoros\Exception\InvalidArgumentException::class); - $this->response->code = 666; + $this->response = $this->getResponseObject($this->sampleString, 666); $this->client->expects($this->once()) ->method('get') ->with('/repos/{user}/{repo}/commits/{ref}') - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->assertThat( $this->object->getSha('{user}', '{repo}', '{ref}'), diff --git a/Tests/Package/Repositories/ContentsTest.php b/Tests/Package/Repositories/ContentsTest.php index a3467a42..b0e84e8e 100644 --- a/Tests/Package/Repositories/ContentsTest.php +++ b/Tests/Package/Repositories/ContentsTest.php @@ -47,7 +47,7 @@ public function testGetReadme() $this->client->expects($this->once()) ->method('get') ->with('/repos/joomla/joomla-platform/readme') - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->assertThat( $this->object->getReadme('joomla', 'joomla-platform'), @@ -65,7 +65,7 @@ public function testGetReadmeRef() $this->client->expects($this->once()) ->method('get') ->with('/repos/joomla/joomla-platform/readme?ref=123abc') - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->assertThat( $this->object->getReadme('joomla', 'joomla-platform', '123abc'), @@ -83,7 +83,7 @@ public function testGet() $this->client->expects($this->once()) ->method('get') ->with('/repos/joomla/joomla-platform/contents/path/to/file.php') - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->assertThat( $this->object->get('joomla', 'joomla-platform', 'path/to/file.php'), @@ -101,7 +101,7 @@ public function testGetRef() $this->client->expects($this->once()) ->method('get') ->with('/repos/joomla/joomla-platform/contents/path/to/file.php?ref=123abc') - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->assertThat( $this->object->get('joomla', 'joomla-platform', 'path/to/file.php', '123abc'), @@ -116,12 +116,12 @@ public function testGetRef() */ public function testGetArchiveLink() { - $this->response->code = 302; + $this->response = $this->getResponseObject($this->sampleString, 302); $this->client->expects($this->once()) ->method('get') ->with('/repos/joomla/joomla-platform/zipball') - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->assertThat( $this->object->getArchiveLink('joomla', 'joomla-platform'), @@ -136,12 +136,12 @@ public function testGetArchiveLink() */ public function testGetArchiveLinkRef() { - $this->response->code = 302; + $this->response = $this->getResponseObject($this->sampleString, 302); $this->client->expects($this->once()) ->method('get') ->with('/repos/joomla/joomla-platform/zipball?ref=123abc') - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->assertThat( $this->object->getArchiveLink('joomla', 'joomla-platform', 'zipball', '123abc'), @@ -158,7 +158,7 @@ public function testGetArchiveLinkInvalidFormat() { $this->expectException(\UnexpectedValueException::class); - $this->response->code = 302; + $this->response = $this->getResponseObject($this->sampleString, 302); $this->object->getArchiveLink('joomla', 'joomla-platform', 'invalid'); } @@ -170,12 +170,12 @@ public function testGetArchiveLinkInvalidFormat() */ public function testCreate() { - $this->response->code = 201; + $this->response = $this->getResponseObject($this->sampleString, 201); $this->client->expects($this->once()) ->method('put') ->with('/repos/joomla/joomla-platform/contents/src/foo') - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->assertThat( $this->object->create( @@ -250,7 +250,7 @@ public function testUpdate() $this->client->expects($this->once()) ->method('put') ->with('/repos/joomla/joomla-platform/contents/src/foo') - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->assertThat( $this->object->update( @@ -328,7 +328,7 @@ public function testDelete() $this->client->expects($this->once()) ->method('delete') ->with('/repos/joomla/joomla-platform/contents/src/foo') - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->assertThat( $this->object->delete( diff --git a/Tests/Package/Repositories/DeploymentsTest.php b/Tests/Package/Repositories/DeploymentsTest.php index a135b672..82f9c26a 100644 --- a/Tests/Package/Repositories/DeploymentsTest.php +++ b/Tests/Package/Repositories/DeploymentsTest.php @@ -47,7 +47,7 @@ public function testGetList() $this->client->expects($this->once()) ->method('get') ->with('/repos/{owner}/{repo}/deployments?sha={sha}&ref={ref}&task={task}&environment={environment}') - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->assertThat( $this->object->getList('{owner}', '{repo}', '{sha}', '{ref}', '{task}', '{environment}'), @@ -62,12 +62,12 @@ public function testGetList() */ public function testCreate() { - $this->response->code = 201; + $this->response = $this->getResponseObject($this->sampleString, 201); $this->client->expects($this->once()) ->method('post') ->with('/repos/{owner}/{repo}/deployments') - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->assertThat( $this->object->create( @@ -94,12 +94,12 @@ public function testCreateMergeConflict() { $this->expectException(\RuntimeException::class); - $this->response->code = 409; + $this->response = $this->getResponseObject($this->sampleString, 409); $this->client->expects($this->once()) ->method('post') ->with('/repos/{owner}/{repo}/deployments') - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->assertThat( $this->object->create('{owner}', '{repo}', '{ref}'), @@ -114,14 +114,14 @@ public function testCreateMergeConflict() */ public function testCreateFailure() { - $this->expectException(\UnexpectedValueException::class); + $this->expectException(\Laminas\Diactoros\Exception\InvalidArgumentException::class); - $this->response->code = 666; + $this->response = $this->getResponseObject($this->sampleString, 666); $this->client->expects($this->once()) ->method('post') ->with('/repos/{owner}/{repo}/deployments') - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->assertThat( $this->object->create('{owner}', '{repo}', '{ref}'), @@ -139,7 +139,7 @@ public function testGetDeploymentStatuses() $this->client->expects($this->once()) ->method('get') ->with('/repos/{owner}/{repo}/deployments/123/statuses') - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->assertThat( $this->object->getDeploymentStatuses('{owner}', '{repo}', 123), @@ -154,12 +154,12 @@ public function testGetDeploymentStatuses() */ public function testCreateStatus() { - $this->response->code = 201; + $this->response = $this->getResponseObject($this->sampleString, 201); $this->client->expects($this->once()) ->method('post') ->with('/repos/{owner}/{repo}/deployments/123/statuses') - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->assertThat( $this->object->createStatus('{owner}', '{repo}', 123, 'success', '{targetUrl}', '{description}'), diff --git a/Tests/Package/Repositories/DownloadsTest.php b/Tests/Package/Repositories/DownloadsTest.php index 9e11539e..189a7c5d 100644 --- a/Tests/Package/Repositories/DownloadsTest.php +++ b/Tests/Package/Repositories/DownloadsTest.php @@ -47,7 +47,7 @@ public function testGetList() $this->client->expects($this->once()) ->method('get') ->with('/repos/joomla/joomla-platform/downloads') - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->assertThat( $this->object->getList('joomla', 'joomla-platform'), @@ -65,7 +65,7 @@ public function testGet() $this->client->expects($this->once()) ->method('get') ->with('/repos/joomla/joomla-platform/downloads/123abc') - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->assertThat( $this->object->get('joomla', 'joomla-platform', '123abc'), @@ -119,12 +119,12 @@ public function testUpload() */ public function testDelete() { - $this->response->code = 204; + $this->response = $this->getResponseObject($this->sampleString, 204); $this->client->expects($this->once()) ->method('delete') ->with('/repos/joomla/joomla-platform/downloads/123') - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->assertThat( $this->object->delete('joomla', 'joomla-platform', 123), diff --git a/Tests/Package/Repositories/ForksTest.php b/Tests/Package/Repositories/ForksTest.php index a6b6cc20..504607a7 100755 --- a/Tests/Package/Repositories/ForksTest.php +++ b/Tests/Package/Repositories/ForksTest.php @@ -45,7 +45,7 @@ protected function setUp(): void */ public function testCreate() { - $this->response->code = 202; + $this->response = $this->getResponseObject($this->sampleString, 202); // Build the request data. $data = json_encode( @@ -57,7 +57,7 @@ public function testCreate() $this->client->expects($this->once()) ->method('post') ->with('/repos/joomla/joomla-platform/forks', $data) - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->assertThat( $this->object->create('joomla', 'joomla-platform', 'jenkins-jools'), @@ -74,8 +74,7 @@ public function testCreateFailure() { $this->expectException(\DomainException::class); - $this->response->code = 500; - $this->response->body = $this->errorString; + $this->response = $this->getResponseObject($this->errorString, 500); // Build the request data. $data = json_encode( @@ -85,7 +84,7 @@ public function testCreateFailure() $this->client->expects($this->once()) ->method('post') ->with('/repos/joomla/joomla-platform/forks', $data) - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->object->create('joomla', 'joomla-platform', ''); } @@ -100,11 +99,13 @@ public function testGetList() $this->client->expects($this->once()) ->method('get') ->with('/repos/joomla/joomla-platform/forks') - ->will($this->returnValue($this->response)); + ->willReturn($this->response); - $this->assertThat( - $this->object->getList('joomla', 'joomla-platform'), - $this->equalTo(json_decode($this->response->body)) + $response = json_decode((string) $this->response->getBody()); + + $this->assertEquals( + $response, + $this->object->getList('joomla', 'joomla-platform') ); } @@ -117,13 +118,12 @@ public function testGetListFailure() { $this->expectException(\DomainException::class); - $this->response->code = 500; - $this->response->body = $this->errorString; + $this->response = $this->getResponseObject($this->errorString, 500); $this->client->expects($this->once()) ->method('get') ->with('/repos/joomla/joomla-platform/forks') - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->object->getList('joomla', 'joomla-platform'); } diff --git a/Tests/Package/Repositories/HooksTest.php b/Tests/Package/Repositories/HooksTest.php index 4bf84c16..51cb92dd 100644 --- a/Tests/Package/Repositories/HooksTest.php +++ b/Tests/Package/Repositories/HooksTest.php @@ -51,7 +51,7 @@ protected function setUp(): void */ public function testCreate() { - $this->response->code = 201; + $this->response = $this->getResponseObject($this->sampleString, 201); $hook = new \stdClass(); $hook->name = 'acunote'; @@ -62,7 +62,7 @@ public function testCreate() $this->client->expects($this->once()) ->method('post') ->with('/repos/joomla/joomla-platform/hooks', json_encode($hook)) - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->assertThat( $this->object->create('joomla', 'joomla-platform', 'acunote', ['token' => '123456789'], ['push', 'public']), @@ -83,8 +83,7 @@ public function testCreateFailure() { $exception = false; - $this->response->code = 500; - $this->response->body = $this->errorString; + $this->response = $this->getResponseObject($this->errorString, 500); $hook = new \stdClass(); $hook->name = 'acunote'; @@ -95,7 +94,7 @@ public function testCreateFailure() $this->client->expects($this->once()) ->method('post') ->with('/repos/joomla/joomla-platform/hooks', json_encode($hook)) - ->will($this->returnValue($this->response)); + ->willReturn($this->response); try { $this->object->create('joomla', 'joomla-platform', 'acunote', ['token' => '123456789'], ['push', 'public']); @@ -140,12 +139,12 @@ public function testCreateUnauthorisedEvent() */ public function testDelete() { - $this->response->code = 204; + $this->response = $this->getResponseObject($this->sampleString, 204); $this->client->expects($this->once()) ->method('delete') ->with('/repos/joomla/joomla-platform/hooks/42') - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->assertThat( $this->object->delete('joomla', 'joomla-platform', 42), @@ -168,13 +167,12 @@ public function testDeleteFailure() { $exception = false; - $this->response->code = 500; - $this->response->body = $this->errorString; + $this->response = $this->getResponseObject($this->errorString, 500); $this->client->expects($this->once()) ->method('delete') ->with('/repos/joomla/joomla-platform/hooks/42') - ->will($this->returnValue($this->response)); + ->willReturn($this->response); try { $this->object->delete('joomla', 'joomla-platform', 42); @@ -209,7 +207,7 @@ public function testEdit() $this->client->expects($this->once()) ->method('patch') ->with('/repos/joomla/joomla-platform/hooks/42', $hook) - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->assertThat( $this->object->edit( @@ -241,8 +239,7 @@ public function testEditFailure() { $exception = false; - $this->response->code = 500; - $this->response->body = $this->errorString; + $this->response = $this->getResponseObject($this->errorString, 500); $hook = '{' . '"name":"acunote","config":{"token":"123456789"},"events":["push","public"],' @@ -252,7 +249,7 @@ public function testEditFailure() $this->client->expects($this->once()) ->method('patch') ->with('/repos/joomla/joomla-platform/hooks/42', $hook) - ->will($this->returnValue($this->response)); + ->willReturn($this->response); try { $this->object->edit( @@ -354,7 +351,7 @@ public function testGet() $this->client->expects($this->once()) ->method('get') ->with('/repos/joomla/joomla-platform/hooks/42') - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->assertThat( $this->object->get('joomla', 'joomla-platform', 42), @@ -377,13 +374,12 @@ public function testGetFailure() { $this->expectException(\DomainException::class); - $this->response->code = 500; - $this->response->body = $this->errorString; + $this->response = $this->getResponseObject($this->errorString, 500); $this->client->expects($this->once()) ->method('get') ->with('/repos/joomla/joomla-platform/hooks/42') - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->object->get('joomla', 'joomla-platform', 42); } @@ -402,7 +398,7 @@ public function testGetList() $this->client->expects($this->once()) ->method('get') ->with('/repos/joomla/joomla-platform/hooks') - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->assertThat( $this->object->getList('joomla', 'joomla-platform'), @@ -425,13 +421,12 @@ public function testGetListFailure() { $this->expectException(\DomainException::class); - $this->response->code = 500; - $this->response->body = $this->errorString; + $this->response = $this->getResponseObject($this->errorString, 500); $this->client->expects($this->once()) ->method('get') ->with('/repos/joomla/joomla-platform/hooks') - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->object->getList('joomla', 'joomla-platform'); } @@ -447,12 +442,12 @@ public function testGetListFailure() */ public function testTest() { - $this->response->code = 204; + $this->response = $this->getResponseObject($this->sampleString, 204); $this->client->expects($this->once()) ->method('post') ->with('/repos/joomla/joomla-platform/hooks/42/test') - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->assertThat( $this->object->test('joomla', 'joomla-platform', 42), @@ -475,13 +470,12 @@ public function testTestFailure() { $this->expectException(\DomainException::class); - $this->response->code = 500; - $this->response->body = $this->errorString; + $this->response = $this->getResponseObject($this->errorString, 500); $this->client->expects($this->once()) ->method('post') ->with('/repos/joomla/joomla-platform/hooks/42/test') - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->object->test('joomla', 'joomla-platform', 42); } @@ -497,12 +491,12 @@ public function testTestFailure() */ public function testPing() { - $this->response->code = 204; + $this->response = $this->getResponseObject($this->sampleString, 204); $this->client->expects($this->once()) ->method('post') ->with('/repos/{user}/{repo}/hooks/42/pings') - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->assertThat( $this->object->ping('{user}', '{repo}', 42), diff --git a/Tests/Package/Repositories/KeysTest.php b/Tests/Package/Repositories/KeysTest.php index 0243ff46..935690dc 100644 --- a/Tests/Package/Repositories/KeysTest.php +++ b/Tests/Package/Repositories/KeysTest.php @@ -47,7 +47,7 @@ public function testGetList() $this->client->expects($this->once()) ->method('get') ->with('/repos/joomla/joomla-platform/keys') - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->assertThat( $this->object->getList('joomla', 'joomla-platform'), @@ -65,7 +65,7 @@ public function testGet() $this->client->expects($this->once()) ->method('get') ->with('/repos/joomla/joomla-platform/keys/1') - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->assertThat( $this->object->get('joomla', 'joomla-platform', 1), @@ -80,12 +80,12 @@ public function testGet() */ public function testCreate() { - $this->response->code = 201; + $this->response = $this->getResponseObject($this->sampleString, 201); $this->client->expects($this->once()) ->method('post') ->with('/repos/joomla/joomla-platform/keys') - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->assertThat( $this->object->create('joomla', 'joomla-platform', 'email@example.com', '123abc'), @@ -103,7 +103,7 @@ public function testEdit() $this->client->expects($this->once()) ->method('patch') ->with('/repos/joomla/joomla-platform/keys/1') - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->assertThat( $this->object->edit('joomla', 'joomla-platform', 1, 'email@example.com', '123abc'), @@ -118,17 +118,16 @@ public function testEdit() */ public function testDelete() { - $this->response->code = 204; - $this->response->body = true; + $this->response = $this->getResponseObject(true, 204); $this->client->expects($this->once()) ->method('delete') ->with('/repos/joomla/joomla-platform/keys/1') - ->will($this->returnValue($this->response)); + ->willReturn($this->response); - $this->assertThat( - $this->object->delete('joomla', 'joomla-platform', 1), - $this->equalTo($this->response->body) + $this->assertEquals( + true, + $this->object->delete('joomla', 'joomla-platform', 1) ); } } diff --git a/Tests/Package/Repositories/MergingTest.php b/Tests/Package/Repositories/MergingTest.php index c7e0c3f1..c050e1dd 100644 --- a/Tests/Package/Repositories/MergingTest.php +++ b/Tests/Package/Repositories/MergingTest.php @@ -45,12 +45,12 @@ protected function setUp(): void */ public function testPerform() { - $this->response->code = 201; + $this->response = $this->getResponseObject($this->sampleString, 201); $this->client->expects($this->once()) ->method('post') ->with('/repos/joomla/joomla-platform/merges') - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->assertThat( $this->object->perform('joomla', 'joomla-platform', '123', '456', 'My Message'), @@ -67,12 +67,12 @@ public function testPerformNoOp() { $this->expectException(\UnexpectedValueException::class); - $this->response->code = 204; + $this->response = $this->getResponseObject($this->sampleString, 204); $this->client->expects($this->once()) ->method('post') ->with('/repos/joomla/joomla-platform/merges') - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->assertThat( $this->object->perform('joomla', 'joomla-platform', '123', '456', 'My Message'), @@ -89,12 +89,12 @@ public function testPerformMissing() { $this->expectException(\UnexpectedValueException::class); - $this->response->code = 404; + $this->response = $this->getResponseObject($this->sampleString, 404); $this->client->expects($this->once()) ->method('post') ->with('/repos/joomla/joomla-platform/merges') - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->assertThat( $this->object->perform('joomla', 'joomla-platform', '123', '456', 'My Message'), @@ -111,12 +111,12 @@ public function testPerformConflict() { $this->expectException(\UnexpectedValueException::class); - $this->response->code = 409; + $this->response = $this->getResponseObject($this->sampleString, 409); $this->client->expects($this->once()) ->method('post') ->with('/repos/joomla/joomla-platform/merges') - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->assertThat( $this->object->perform('joomla', 'joomla-platform', '123', '456', 'My Message'), @@ -131,14 +131,14 @@ public function testPerformConflict() */ public function testPerformUnexpected() { - $this->expectException(\UnexpectedValueException::class); + $this->expectException(\Laminas\Diactoros\Exception\InvalidArgumentException::class); - $this->response->code = 666; + $this->response = $this->getResponseObject($this->sampleString, 666); $this->client->expects($this->once()) ->method('post') ->with('/repos/joomla/joomla-platform/merges') - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->assertThat( $this->object->perform('joomla', 'joomla-platform', '123', '456', 'My Message'), diff --git a/Tests/Package/Repositories/PagesTest.php b/Tests/Package/Repositories/PagesTest.php index e723d41d..7111e223 100644 --- a/Tests/Package/Repositories/PagesTest.php +++ b/Tests/Package/Repositories/PagesTest.php @@ -46,7 +46,7 @@ public function testGetInfo() $this->client->expects($this->once()) ->method('get') ->with('/repos/{owner}/{repo}/pages') - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->assertThat( $this->object->getInfo('{owner}', '{repo}'), @@ -64,7 +64,7 @@ public function testGetList() $this->client->expects($this->once()) ->method('get') ->with('/repos/{owner}/{repo}/pages/builds') - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->assertThat( $this->object->getList('{owner}', '{repo}'), @@ -82,7 +82,7 @@ public function testGetLatest() $this->client->expects($this->once()) ->method('get') ->with('/repos/{owner}/{repo}/pages/builds/latest') - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->assertThat( $this->object->getLatest('{owner}', '{repo}'), diff --git a/Tests/Package/Repositories/ReleasesTest.php b/Tests/Package/Repositories/ReleasesTest.php index ddd596c8..1ecf4844 100644 --- a/Tests/Package/Repositories/ReleasesTest.php +++ b/Tests/Package/Repositories/ReleasesTest.php @@ -4,10 +4,11 @@ * @license GNU General Public License version 2 or later; see LICENSE */ -namespace Joomla\Github\Tests; +namespace Joomla\Github\Tests\Package\Repositories; use Joomla\Github\Package\Repositories\Releases; use Joomla\Github\Tests\Stub\GitHubTestCase; +use Joomla\Http\Response; /** * Test class for the GitHub API package. @@ -47,11 +48,13 @@ public function testGet() $this->client->expects($this->once()) ->method('get') ->with('/repos/joomla/joomla-platform/releases/12345', [], 0) - ->will($this->returnValue($this->response)); + ->willReturn($this->response); - $this->assertThat( - $this->object->get('joomla', 'joomla-platform', '12345'), - $this->equalTo(json_decode($this->response->body)) + $response = json_decode((string) $this->response->getBody()); + + $this->assertEquals( + $response, + $this->object->get('joomla', 'joomla-platform', '12345') ); } @@ -62,17 +65,19 @@ public function testGet() */ public function testCreate() { - $this->response->code = 201; + $this->response = $this->getResponseObject($this->sampleString, 201); $data = '{"tag_name":"0.1","target_commitish":"targetCommitish","name":"master","body":"New release","draft":false,"prerelease":false}'; $this->client->expects($this->once()) ->method('post') ->with('/repos/joomla/joomla-platform/releases', $data, [], 0) - ->will($this->returnValue($this->response)); + ->willReturn($this->response); + + $response = json_decode((string) $this->response->getBody()); - $this->assertThat( - $this->object->create('joomla', 'joomla-platform', '0.1', 'targetCommitish', 'master', 'New release', false, false), - $this->equalTo(json_decode($this->response->body)) + $this->assertEquals( + $response, + $this->object->create('joomla', 'joomla-platform', '0.1', 'targetCommitish', 'master', 'New release', false, false) ); } @@ -83,17 +88,19 @@ public function testCreate() */ public function testCreateFailure() { - $this->response->code = 201; + $this->response = $this->getResponseObject($this->sampleString, 201); $data = '{"tag_name":"0.1","target_commitish":"targetCommitish","name":"master","body":"New release","draft":false,"prerelease":false}'; $this->client->expects($this->once()) ->method('post') ->with('/repos/joomla/joomla-platform/releases', $data, [], 0) - ->will($this->returnValue($this->response)); + ->willReturn($this->response); + + $response = json_decode((string) $this->response->getBody()); - $this->assertThat( - $this->object->create('joomla', 'joomla-platform', '0.1', 'targetCommitish', 'master', 'New release', false, false), - $this->equalTo(json_decode($this->response->body)) + $this->assertEquals( + $response, + $this->object->create('joomla', 'joomla-platform', '0.1', 'targetCommitish', 'master', 'New release', false, false) ); } @@ -111,11 +118,13 @@ public function testEdit() ->method('patch') ->with('/repos/joomla/joomla-platform/releases/' . $releaseId, $data, [], 0) - ->will($this->returnValue($this->response)); + ->willReturn($this->response); - $this->assertThat( - $this->object->edit('joomla', 'joomla-platform', $releaseId, 'tagName', 'targetCommitish', 'name', 'body', 'draft', 'preRelease'), - $this->equalTo(json_decode($this->response->body)) + $response = json_decode((string) $this->response->getBody()); + + $this->assertEquals( + $response, + $this->object->edit('joomla', 'joomla-platform', $releaseId, 'tagName', 'targetCommitish', 'name', 'body', 'draft', 'preRelease') ); } @@ -126,23 +135,24 @@ public function testEdit() */ public function testGetList() { - $this->response->code = 200; - $this->response->body = '[{"tag_name":"1"},{"tag_name":"2"}]'; + $this->response = $this->getResponseObject('[{"tag_name":"1"},{"tag_name":"2"}]', 200); $releases = []; - foreach (json_decode($this->response->body) as $i => $release) { + foreach (json_decode((string) $this->response->getBody()) as $i => $release) { $releases[$i + 1] = $release; } $this->client->expects($this->once()) ->method('get') ->with('/repos/joomla/joomla-platform/releases', [], 0) - ->will($this->returnValue($this->response)); + ->willReturn($this->response); + + $response = json_decode((string) $this->response->getBody()); - $this->assertThat( - $this->object->getList('joomla', 'joomla-platform'), - $this->equalTo($releases) + $this->assertEquals( + $releases, + $this->object->getList('joomla', 'joomla-platform') ); } @@ -153,16 +163,18 @@ public function testGetList() */ public function testDelete() { - $this->response->code = 204; + $this->response = $this->getResponseObject($this->sampleString, 204); $this->client->expects($this->once()) ->method('delete') ->with('/repos/joomla/joomla-platform/releases/123') - ->will($this->returnValue($this->response)); + ->willReturn($this->response); + + $response = json_decode((string) $this->response->getBody()); - $this->assertThat( - $this->object->delete('joomla', 'joomla-platform', '123'), - $this->equalTo(json_decode($this->response->body)) + $this->assertEquals( + $response, + $this->object->delete('joomla', 'joomla-platform', '123') ); } @@ -173,19 +185,20 @@ public function testDelete() */ public function testGetLatest() { - $this->response->code = 200; - $this->response->body = '[]'; + $this->response = $this->getResponseObject('[]'); $releases = []; $this->client->expects($this->once()) ->method('get') ->with('/repos/joomla/joomla-platform/releases/latest', [], 0) - ->will($this->returnValue($this->response)); + ->willReturn($this->response); - $this->assertThat( - $this->object->getLatest('joomla', 'joomla-platform'), - $this->equalTo($releases) + $response = json_decode((string) $this->response->getBody()); + + $this->assertEquals( + $response, + $this->object->getLatest('joomla', 'joomla-platform') ); } @@ -199,11 +212,13 @@ public function testGetByTag() $this->client->expects($this->once()) ->method('get') ->with('/repos/joomla/joomla-platform/releases/tags/{tag}', [], 0) - ->will($this->returnValue($this->response)); + ->willReturn($this->response); + + $response = json_decode((string) $this->response->getBody()); - $this->assertThat( - $this->object->getByTag('joomla', 'joomla-platform', '{tag}'), - $this->equalTo(json_decode($this->response->body)) + $this->assertEquals( + $response, + $this->object->getByTag('joomla', 'joomla-platform', '{tag}') ); } @@ -217,11 +232,13 @@ public function testGetListAssets() $this->client->expects($this->once()) ->method('get') ->with('/repos/joomla/joomla-platform/releases/123/assets', [], 0) - ->will($this->returnValue($this->response)); + ->willReturn($this->response); + + $response = json_decode((string) $this->response->getBody()); - $this->assertThat( - $this->object->getListAssets('joomla', 'joomla-platform', 123), - $this->equalTo(json_decode($this->response->body)) + $this->assertEquals( + $response, + $this->object->getListAssets('joomla', 'joomla-platform', 123) ); } @@ -235,11 +252,13 @@ public function testGetAsset() $this->client->expects($this->once()) ->method('get') ->with('/repos/joomla/joomla-platform/releases/assets/123', [], 0) - ->will($this->returnValue($this->response)); + ->willReturn($this->response); - $this->assertThat( - $this->object->getAsset('joomla', 'joomla-platform', 123), - $this->equalTo(json_decode($this->response->body)) + $response = json_decode((string) $this->response->getBody()); + + $this->assertEquals( + $response, + $this->object->getAsset('joomla', 'joomla-platform', 123) ); } @@ -255,11 +274,13 @@ public function testEditAsset() $this->client->expects($this->once()) ->method('patch') ->with('/repos/joomla/joomla-platform/releases/assets/123', $data, [], 0) - ->will($this->returnValue($this->response)); + ->willReturn($this->response); + + $response = json_decode((string) $this->response->getBody()); - $this->assertThat( - $this->object->editAsset('joomla', 'joomla-platform', 123, '{name}', '{label}'), - $this->equalTo(json_decode($this->response->body)) + $this->assertEquals( + $response, + $this->object->editAsset('joomla', 'joomla-platform', 123, '{name}', '{label}') ); } @@ -270,17 +291,16 @@ public function testEditAsset() */ public function testDeleteAsset() { - $this->response->code = 204; - $this->response->body = true; + $this->response = new Response('data://text/plain,true', 204); $this->client->expects($this->once()) ->method('delete') ->with('/repos/joomla/joomla-platform/releases/assets/123', [], 0) - ->will($this->returnValue($this->response)); + ->willReturn($this->response); - $this->assertThat( - $this->object->deleteAsset('joomla', 'joomla-platform', 123), - $this->equalTo($this->response->body) + $this->assertEquals( + 'true', + $this->object->deleteAsset('joomla', 'joomla-platform', 123) ); } } diff --git a/Tests/Package/Repositories/StatisticsTest.php b/Tests/Package/Repositories/StatisticsTest.php index 4aefac24..48dcc42e 100644 --- a/Tests/Package/Repositories/StatisticsTest.php +++ b/Tests/Package/Repositories/StatisticsTest.php @@ -47,7 +47,7 @@ public function testContributors() $this->client->expects($this->once()) ->method('get') ->with('/repos/joomla/joomla-framework/stats/contributors') - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->assertThat( $this->object->getListContributors('joomla', 'joomla-framework'), @@ -65,7 +65,7 @@ public function testActivity() $this->client->expects($this->once()) ->method('get') ->with('/repos/joomla/joomla-framework/stats/commit_activity') - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->assertThat( $this->object->getActivityData('joomla', 'joomla-framework'), @@ -83,7 +83,7 @@ public function testFrequency() $this->client->expects($this->once()) ->method('get') ->with('/repos/joomla/joomla-framework/stats/code_frequency') - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->assertThat( $this->object->getCodeFrequency('joomla', 'joomla-framework'), @@ -101,7 +101,7 @@ public function testParticipation() $this->client->expects($this->once()) ->method('get') ->with('/repos/joomla/joomla-framework/stats/participation') - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->assertThat( $this->object->getParticipation('joomla', 'joomla-framework'), @@ -119,7 +119,7 @@ public function testPunchCard() $this->client->expects($this->once()) ->method('get') ->with('/repos/joomla/joomla-framework/stats/punch_card') - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->assertThat( $this->object->getPunchCard('joomla', 'joomla-framework'), @@ -136,12 +136,12 @@ public function testProcessResponse202() { $this->expectException(\DomainException::class); - $this->response->code = 202; + $this->response = $this->getResponseObject($this->sampleString, 202); $this->client->expects($this->once()) ->method('get') ->with('/repos/joomla/joomla-framework/stats/punch_card') - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->assertThat( $this->object->getPunchCard('joomla', 'joomla-framework'), diff --git a/Tests/Package/Repositories/StatusesTest.php b/Tests/Package/Repositories/StatusesTest.php index d51a6b73..68a0090c 100755 --- a/Tests/Package/Repositories/StatusesTest.php +++ b/Tests/Package/Repositories/StatusesTest.php @@ -48,7 +48,7 @@ protected function setUp(): void */ public function testCreate() { - $this->response->code = 201; + $this->response = $this->getResponseObject($this->sampleString, 201); // Build the request data. $data = json_encode( @@ -63,7 +63,7 @@ public function testCreate() $this->client->expects($this->once()) ->method('post') ->with('/repos/joomla/joomla-platform/statuses/6dcb09b5b57875f334f61aebed695e2e4193db5e', $data) - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->assertThat( $this->object->create( @@ -92,8 +92,7 @@ public function testCreateFailure() { $this->expectException(\DomainException::class); - $this->response->code = 501; - $this->response->body = $this->errorString; + $this->response = $this->getResponseObject($this->errorString, 501); // Build the request data. $data = json_encode( @@ -105,7 +104,7 @@ public function testCreateFailure() $this->client->expects($this->once()) ->method('post') ->with('/repos/joomla/joomla-platform/statuses/6dcb09b5b57875f334f61aebed695e2e4193db5e', $data) - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->object->create('joomla', 'joomla-platform', '6dcb09b5b57875f334f61aebed695e2e4193db5e', 'pending'); } @@ -123,8 +122,7 @@ public function testCreateInvalidState() { $this->expectException(\InvalidArgumentException::class); - $this->response->code = 501; - $this->response->body = $this->errorString; + $this->response = $this->getResponseObject($this->errorString, 501); $this->object->create('joomla', 'joomla-platform', '6dcb09b5b57875f334f61aebed695e2e4193db5e', 'INVALID'); } @@ -141,7 +139,7 @@ public function testGetList() $this->client->expects($this->once()) ->method('get') ->with('/repos/joomla/joomla-platform/statuses/6dcb09b5b57875f334f61aebed695e2e4193db5e') - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->assertThat( $this->object->getList('joomla', 'joomla-platform', '6dcb09b5b57875f334f61aebed695e2e4193db5e'), @@ -162,13 +160,12 @@ public function testGetListFailure() { $this->expectException(\DomainException::class); - $this->response->code = 500; - $this->response->body = $this->errorString; + $this->response = $this->getResponseObject($this->errorString, 500); $this->client->expects($this->once()) ->method('get') ->with('/repos/joomla/joomla-platform/statuses/6dcb09b5b57875f334f61aebed695e2e4193db5e') - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->object->getList('joomla', 'joomla-platform', '6dcb09b5b57875f334f61aebed695e2e4193db5e'); } @@ -187,7 +184,7 @@ public function testGetCombinedStatus() $this->client->expects($this->once()) ->method('get') ->with('/repos/{user}/{repo}/commits/{sha}/status') - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->assertThat( $this->object->getCombinedStatus('{user}', '{repo}', '{sha}'), diff --git a/Tests/Package/RepositoriesTest.php b/Tests/Package/RepositoriesTest.php index 667d5f0c..30649952 100644 --- a/Tests/Package/RepositoriesTest.php +++ b/Tests/Package/RepositoriesTest.php @@ -46,11 +46,13 @@ public function testGetListOwn() $this->client->expects($this->once()) ->method('get') ->with('/user/repos?type=all&sort=full_name&direction=asc', [], 0) - ->will($this->returnValue($this->response)); + ->willReturn($this->response); - $this->assertThat( - $this->object->getListOwn(), - $this->equalTo(json_decode($this->response->body)) + $response = json_decode((string) $this->response->getBody()); + + $this->assertEquals( + $response, + $this->object->getListOwn() ); } @@ -100,11 +102,13 @@ public function testGetListUser() $this->client->expects($this->once()) ->method('get') ->with('/users/joomla/repos?type=all&sort=full_name&direction=asc', [], 0) - ->will($this->returnValue($this->response)); + ->willReturn($this->response); + + $response = json_decode((string) $this->response->getBody()); - $this->assertThat( - $this->object->getListUser('joomla'), - $this->equalTo(json_decode($this->response->body)) + $this->assertEquals( + $response, + $this->object->getListUser('joomla') ); } @@ -154,11 +158,13 @@ public function testGetListOrg() $this->client->expects($this->once()) ->method('get') ->with('/orgs/joomla/repos?type=all', [], 0) - ->will($this->returnValue($this->response)); + ->willReturn($this->response); - $this->assertThat( - $this->object->getListOrg('joomla'), - $this->equalTo(json_decode($this->response->body)) + $response = json_decode((string) $this->response->getBody()); + + $this->assertEquals( + $response, + $this->object->getListOrg('joomla') ); } @@ -172,11 +178,13 @@ public function testGetList() $this->client->expects($this->once()) ->method('get') ->with('/repositories', [], 0) - ->will($this->returnValue($this->response)); + ->willReturn($this->response); + + $response = json_decode((string) $this->response->getBody()); - $this->assertThat( - $this->object->getList(), - $this->equalTo(json_decode($this->response->body)) + $this->assertEquals( + $response, + $this->object->getList() ); } @@ -187,7 +195,7 @@ public function testGetList() */ public function testCreate() { - $this->response->code = 201; + $this->response = $this->getResponseObject($this->sampleString, 201); $this->client->expects($this->once()) ->method('post') @@ -198,11 +206,13 @@ public function testCreate() [], 0 ) - ->will($this->returnValue($this->response)); + ->willReturn($this->response); - $this->assertThat( - $this->object->create('joomla-test'), - $this->equalTo(json_decode($this->response->body)) + $response = json_decode((string) $this->response->getBody()); + + $this->assertEquals( + $response, + $this->object->create('joomla-test') ); } @@ -213,7 +223,7 @@ public function testCreate() */ public function testCreateWithOrg() { - $this->response->code = 201; + $this->response = $this->getResponseObject($this->sampleString, 201); $this->client->expects($this->once()) ->method('post') @@ -224,11 +234,13 @@ public function testCreateWithOrg() [], 0 ) - ->will($this->returnValue($this->response)); + ->willReturn($this->response); + + $response = json_decode((string) $this->response->getBody()); - $this->assertThat( - $this->object->create('joomla-test', 'joomla.org'), - $this->equalTo(json_decode($this->response->body)) + $this->assertEquals( + $response, + $this->object->create('joomla-test', 'joomla.org') ); } @@ -242,11 +254,13 @@ public function testGet() $this->client->expects($this->once()) ->method('get') ->with('/repos/joomla/joomla-cms', [], 0) - ->will($this->returnValue($this->response)); + ->willReturn($this->response); + + $response = json_decode((string) $this->response->getBody()); - $this->assertThat( - $this->object->get('joomla', 'joomla-cms'), - $this->equalTo(json_decode($this->response->body)) + $this->assertEquals( + $response, + $this->object->get('joomla', 'joomla-cms') ); } @@ -277,11 +291,13 @@ public function testEdit() . 'false,"has_issues":false,"has_wiki":false,"has_downloads":false,"default_branch":""}', [] ) - ->will($this->returnValue($this->response)); + ->willReturn($this->response); - $this->assertThat( - $this->object->edit('joomla', 'joomla-test', 'joomla-test-1'), - $this->equalTo(json_decode($this->response->body)) + $response = json_decode((string) $this->response->getBody()); + + $this->assertEquals( + $response, + $this->object->edit('joomla', 'joomla-test', 'joomla-test-1') ); } @@ -295,11 +311,13 @@ public function testGetListContributors() $this->client->expects($this->once()) ->method('get') ->with('/repos/joomla/joomla-cms/contributors', [], 0) - ->will($this->returnValue($this->response)); + ->willReturn($this->response); + + $response = json_decode((string) $this->response->getBody()); - $this->assertThat( - $this->object->getListContributors('joomla', 'joomla-cms'), - $this->equalTo(json_decode($this->response->body)) + $this->assertEquals( + $response, + $this->object->getListContributors('joomla', 'joomla-cms') ); } @@ -313,11 +331,13 @@ public function testGetListLanguages() $this->client->expects($this->once()) ->method('get') ->with('/repos/joomla/joomla-cms/languages', [], 0) - ->will($this->returnValue($this->response)); + ->willReturn($this->response); + + $response = json_decode((string) $this->response->getBody()); - $this->assertThat( - $this->object->getListLanguages('joomla', 'joomla-cms'), - $this->equalTo(json_decode($this->response->body)) + $this->assertEquals( + $response, + $this->object->getListLanguages('joomla', 'joomla-cms') ); } @@ -331,11 +351,13 @@ public function testGetListTeams() $this->client->expects($this->once()) ->method('get') ->with('/repos/joomla/joomla-cms/teams', [], 0) - ->will($this->returnValue($this->response)); + ->willReturn($this->response); - $this->assertThat( - $this->object->getListTeams('joomla', 'joomla-cms'), - $this->equalTo(json_decode($this->response->body)) + $response = json_decode((string) $this->response->getBody()); + + $this->assertEquals( + $response, + $this->object->getListTeams('joomla', 'joomla-cms') ); } @@ -349,11 +371,13 @@ public function testGetListTags() $this->client->expects($this->once()) ->method('get') ->with('/repos/joomla/joomla-cms/tags', [], 0) - ->will($this->returnValue($this->response)); + ->willReturn($this->response); + + $response = json_decode((string) $this->response->getBody()); - $this->assertThat( - $this->object->getListTags('joomla', 'joomla-cms'), - $this->equalTo(json_decode($this->response->body)) + $this->assertEquals( + $response, + $this->object->getListTags('joomla', 'joomla-cms') ); } @@ -367,11 +391,13 @@ public function testDelete() $this->client->expects($this->once()) ->method('delete') ->with('/repos/joomla/joomla-cms', [], 0) - ->will($this->returnValue($this->response)); + ->willReturn($this->response); + + $response = json_decode((string) $this->response->getBody()); - $this->assertThat( - $this->object->delete('joomla', 'joomla-cms'), - $this->equalTo(json_decode($this->response->body)) + $this->assertEquals( + $response, + $this->object->delete('joomla', 'joomla-cms') ); } } diff --git a/Tests/Package/SearchTest.php b/Tests/Package/SearchTest.php index ea8c758f..7f1e636f 100644 --- a/Tests/Package/SearchTest.php +++ b/Tests/Package/SearchTest.php @@ -46,11 +46,11 @@ public function testIssues() $this->client->expects($this->once()) ->method('get') ->with('/legacy/issues/search/joomla/joomla-platform/open/github') - ->will($this->returnValue($this->response)); + ->willReturn($this->response); - $this->assertThat( - $this->object->issues('joomla', 'joomla-platform', 'open', 'github'), - $this->equalTo(json_decode($this->sampleString)) + $this->assertEquals( + json_decode($this->sampleString), + $this->object->issues('joomla', 'joomla-platform', 'open', 'github') ); } @@ -76,7 +76,7 @@ public function testRepositories() $this->client->expects($this->once()) ->method('get') ->with('/legacy/repos/search/joomla') - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->assertThat( $this->object->repositories('joomla'), @@ -94,7 +94,7 @@ public function testUsers() $this->client->expects($this->once()) ->method('get') ->with('/legacy/user/search/joomla') - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->assertThat( $this->object->users('joomla'), @@ -112,7 +112,7 @@ public function testEmail() $this->client->expects($this->once()) ->method('get') ->with('/legacy/user/email/email@joomla') - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->assertThat( $this->object->email('email@joomla'), diff --git a/Tests/Package/Users/EmailsTest.php b/Tests/Package/Users/EmailsTest.php index a08eda6b..15fa56c8 100644 --- a/Tests/Package/Users/EmailsTest.php +++ b/Tests/Package/Users/EmailsTest.php @@ -46,7 +46,7 @@ public function testGetList() $this->client->expects($this->once()) ->method('get') ->with('/user/emails') - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->assertThat( $this->object->getList(), @@ -61,12 +61,12 @@ public function testGetList() */ public function testAdd() { - $this->response->code = 201; + $this->response = $this->getResponseObject($this->sampleString, 201); $this->client->expects($this->once()) ->method('post') ->with('/user/emails') - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->assertThat( $this->object->add('email@example.com'), @@ -81,12 +81,12 @@ public function testAdd() */ public function testDelete() { - $this->response->code = 204; + $this->response = $this->getResponseObject($this->sampleString, 204); $this->client->expects($this->once()) ->method('delete') ->with('/user/emails') - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->assertThat( $this->object->delete('email@example.com'), diff --git a/Tests/Package/Users/FollowersTest.php b/Tests/Package/Users/FollowersTest.php index 00a1c247..2ec8bb15 100644 --- a/Tests/Package/Users/FollowersTest.php +++ b/Tests/Package/Users/FollowersTest.php @@ -50,7 +50,7 @@ public function testGetList() $this->client->expects($this->once()) ->method('get') ->with('/user/followers') - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->assertThat( $this->object->getList(), @@ -70,7 +70,7 @@ public function testGetListWithUser() $this->client->expects($this->once()) ->method('get') ->with('/users/joomla/followers') - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->assertThat( $this->object->getList('joomla'), @@ -90,7 +90,7 @@ public function testGetListFollowedBy() $this->client->expects($this->once()) ->method('get') ->with('/user/following') - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->assertThat( $this->object->getListFollowedBy(), @@ -110,7 +110,7 @@ public function testGetListFollowedByWithUser() $this->client->expects($this->once()) ->method('get') ->with('/users/joomla/following') - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->assertThat( $this->object->getListFollowedBy('joomla'), @@ -129,17 +129,18 @@ public function testGetListFollowedByWithUser() */ public function testCheck() { - $this->response->code = 204; - $this->response->body = true; + $this->response = $this->getResponseObject(true, 204); $this->client->expects($this->once()) ->method('get') ->with('/user/following/joomla') - ->will($this->returnValue($this->response)); + ->willReturn($this->response); - $this->assertThat( - $this->object->check('joomla'), - $this->equalTo($this->response->body) + $response = json_decode((string) $this->response->getBody()); + + $this->assertEquals( + $response, + $this->object->check('joomla') ); } @@ -154,17 +155,18 @@ public function testCheck() */ public function testCheckNo() { - $this->response->code = 404; - $this->response->body = false; + $this->response = $this->getResponseObject(false, 404); $this->client->expects($this->once()) ->method('get') ->with('/user/following/joomla') - ->will($this->returnValue($this->response)); + ->willReturn($this->response); - $this->assertThat( - $this->object->check('joomla'), - $this->equalTo($this->response->body) + $response = (string) $this->response->getBody(); + + $this->assertEquals( + $response, + $this->object->check('joomla') ); } @@ -177,19 +179,20 @@ public function testCheckNo() */ public function testCheckUnexpected() { - $this->expectException(\UnexpectedValueException::class); + $this->expectException(\Laminas\Diactoros\Exception\InvalidArgumentException::class); - $this->response->code = 666; - $this->response->body = false; + $this->response = $this->getResponseObject(false, 666); $this->client->expects($this->once()) ->method('get') ->with('/user/following/joomla') - ->will($this->returnValue($this->response)); + ->willReturn($this->response); - $this->assertThat( - $this->object->check('joomla'), - $this->equalTo($this->response->body) + $response = json_decode((string) $this->response->getBody()); + + $this->assertEquals( + $response, + $this->object->check('joomla') ); } @@ -202,17 +205,18 @@ public function testCheckUnexpected() */ public function testFollow() { - $this->response->code = 204; - $this->response->body = ''; + $this->response = $this->getResponseObject('', 204); $this->client->expects($this->once()) ->method('put') ->with('/user/following/joomla') - ->will($this->returnValue($this->response)); + ->willReturn($this->response); - $this->assertThat( - $this->object->follow('joomla'), - $this->equalTo($this->response->body) + $response = json_decode((string) $this->response->getBody()); + + $this->assertEquals( + $response, + $this->object->follow('joomla') ); } @@ -225,17 +229,18 @@ public function testFollow() */ public function testUnfollow() { - $this->response->code = 204; - $this->response->body = ''; + $this->response = $this->getResponseObject('', 204); $this->client->expects($this->once()) ->method('delete') ->with('/user/following/joomla') - ->will($this->returnValue($this->response)); + ->willReturn($this->response); - $this->assertThat( - $this->object->unfollow('joomla'), - $this->equalTo($this->response->body) + $response = json_decode((string) $this->response->getBody()); + + $this->assertEquals( + $response, + $this->object->unfollow('joomla') ); } @@ -252,12 +257,12 @@ public function testUnfollow() */ public function testCheckUserFollowing() { - $this->response->code = 204; + $this->response = $this->getResponseObject($this->sampleString, 204); $this->client->expects($this->once()) ->method('get') ->with('/user/{user}/following/{target}') - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->assertThat( $this->object->checkUserFollowing('{user}', '{target}'), @@ -278,12 +283,12 @@ public function testCheckUserFollowing() */ public function testCheckUserFollowingNot() { - $this->response->code = 404; + $this->response = $this->getResponseObject($this->sampleString, 404); $this->client->expects($this->once()) ->method('get') ->with('/user/{user}/following/{target}') - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->assertThat( $this->object->checkUserFollowing('{user}', '{target}'), @@ -304,15 +309,14 @@ public function testCheckUserFollowingNot() */ public function testCheckUserFollowingUnexpected() { - $this->expectException(\UnexpectedValueException::class); - $this->expectExceptionMessage('Unexpected response code: 666'); + $this->expectException(\Laminas\Diactoros\Exception\InvalidArgumentException::class); - $this->response->code = 666; + $this->response = $this->getResponseObject($this->sampleString, 666); $this->client->expects($this->once()) ->method('get') ->with('/user/{user}/following/{target}') - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->assertThat( $this->object->checkUserFollowing('{user}', '{target}'), diff --git a/Tests/Package/Users/KeysTest.php b/Tests/Package/Users/KeysTest.php index a5be5862..5edc5c0e 100644 --- a/Tests/Package/Users/KeysTest.php +++ b/Tests/Package/Users/KeysTest.php @@ -46,7 +46,7 @@ public function testGetListUser() $this->client->expects($this->once()) ->method('get') ->with('/users/joomla/keys') - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->assertThat( $this->object->getListUser('joomla'), @@ -64,7 +64,7 @@ public function testGetList() $this->client->expects($this->once()) ->method('get') ->with('/users/keys') - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->assertThat( $this->object->getList(), @@ -82,7 +82,7 @@ public function testGet() $this->client->expects($this->once()) ->method('get') ->with('/users/keys/1') - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->assertThat( $this->object->get(1), @@ -97,12 +97,12 @@ public function testGet() */ public function testCreate() { - $this->response->code = 201; + $this->response = $this->getResponseObject($this->sampleString, 201); $this->client->expects($this->once()) ->method('post') ->with('/users/keys') - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->assertThat( $this->object->create('email@example.com', '12345'), @@ -120,7 +120,7 @@ public function testEdit() $this->client->expects($this->once()) ->method('patch') ->with('/users/keys/1') - ->will($this->returnValue($this->response)); + ->willReturn($this->response); $this->assertThat( $this->object->edit(1, 'email@example.com', '12345'), @@ -135,16 +135,15 @@ public function testEdit() */ public function testDelete() { - $this->response->code = 204; + $this->response = $this->getResponseObject($this->sampleString, 204); $this->client->expects($this->once()) ->method('delete') ->with('/users/keys/1') - ->will($this->returnValue($this->response)); + ->willReturn($this->response); - $this->assertThat( - $this->object->delete(1), - $this->equalTo(json_decode($this->sampleString)) + $this->assertEquals(json_decode($this->sampleString), + $this->object->delete(1) ); } } diff --git a/Tests/Package/UsersTest.php b/Tests/Package/UsersTest.php index 83845b1c..1d8f965f 100755 --- a/Tests/Package/UsersTest.php +++ b/Tests/Package/UsersTest.php @@ -4,10 +4,11 @@ * @license GNU General Public License version 2 or later; see LICENSE */ -namespace Joomla\Github\Tests; +namespace Joomla\Github\Tests\Package; use Joomla\Github\Package\Users; use Joomla\Github\Tests\Stub\GitHubTestCase; +use Joomla\Http\Response; /** * Test class for Users. @@ -43,8 +44,7 @@ protected function setUp(): void */ public function testGet() { - $this->response->code = 200; - $this->response->body = '{ + $body = '{ "login": "octocat", "id": 1, "avatar_url": "https://github.com/images/error/octocat_happy.gif", @@ -65,15 +65,18 @@ public function testGet() "created_at": "2008-01-14T04:33:35Z", "type": "User" }'; + $this->response = new Response('data://text/plain,' . $body, 200); $this->client->expects($this->once()) ->method('get') ->with('/users/joomla', [], 0) - ->will($this->returnValue($this->response)); + ->willReturn($this->response); - $this->assertThat( - $this->object->get('joomla'), - $this->equalTo(json_decode($this->response->body)) + $response = json_decode((string) $this->response->getBody()); + + $this->assertEquals( + $response, + $this->object->get('joomla') ); } @@ -86,17 +89,18 @@ public function testGetFailure() { $this->expectException(\DomainException::class); - $this->response->code = 404; - $this->response->body = '{"message":"Not Found"}'; + $this->response = new Response('data://text/plain,{"message":"Not Found"}', 404); $this->client->expects($this->once()) ->method('get') ->with('/users/nonexistentuser', [], 0) - ->will($this->returnValue($this->response)); + ->willReturn($this->response); + + $response = json_decode((string) $this->response->getBody()); - $this->assertThat( - $this->object->get('nonexistentuser'), - $this->equalTo(json_decode($this->response->body)) + $this->assertEquals( + $response, + $this->object->get('nonexistentuser') ); } @@ -107,8 +111,7 @@ public function testGetFailure() */ public function testGetAuthenticatedUser() { - $this->response->code = 200; - $this->response->body = '{ + $body = '{ "login": "octocat", "id": 1, "avatar_url": "https://github.com/images/error/octocat_happy.gif", @@ -140,15 +143,18 @@ public function testGetAuthenticatedUser() "private_repos": 20 } }'; + $this->response = new Response('data://text/plain,' . $body, 200); $this->client->expects($this->once()) ->method('get') ->with('/user', [], 0) - ->will($this->returnValue($this->response)); + ->willReturn($this->response); + + $response = json_decode((string) $this->response->getBody()); - $this->assertThat( - $this->object->getAuthenticatedUser(), - $this->equalTo(json_decode($this->response->body)) + $this->assertEquals( + $response, + $this->object->getAuthenticatedUser() ); } @@ -161,17 +167,20 @@ public function testGetAuthenticatedUserFailure() { $this->expectException(\DomainException::class); - $this->response->code = 401; - $this->response->body = '{"message":"Requires authentication"}'; + $body = '{"message":"Requires authentication"}'; + + $this->response = new Response('data://text/plain,' . $body, 401); $this->client->expects($this->once()) ->method('get') ->with('/user', [], 0) - ->will($this->returnValue($this->response)); + ->willReturn($this->response); + + $response = json_decode((string) $this->response->getBody()); - $this->assertThat( - $this->object->getAuthenticatedUser(), - $this->equalTo(json_decode($this->response->body)) + $this->assertEquals( + $response, + $this->object->getAuthenticatedUser() ); } @@ -182,8 +191,7 @@ public function testGetAuthenticatedUserFailure() */ public function testGetList() { - $this->response->code = 200; - $this->response->body = '[ + $body = '[ { "login": "octocat", "id": 1, @@ -201,14 +209,18 @@ public function testGetList() } ]'; + $this->response = new Response('data://text/plain,' . $body, 200); + $this->client->expects($this->once()) ->method('get') ->with('/users', [], 0) - ->will($this->returnValue($this->response)); + ->willReturn($this->response); + + $response = json_decode((string) $this->response->getBody()); - $this->assertThat( - $this->object->getList(), - $this->equalTo(json_decode($this->response->body)) + $this->assertEquals( + $response, + $this->object->getList() ); } @@ -227,8 +239,7 @@ public function testEdit() $hireable = true; $bio = 'There once...'; - $this->response->code = 200; - $this->response->body = '{ + $this->response = new Response('data://text/plain,{ "login": "octocat", "id": 1, "avatar_url": "https://github.com/images/error/octocat_happy.gif", @@ -259,7 +270,7 @@ public function testEdit() "collaborators": 10, "private_repos": 20 } -}'; +}', 200); $input = json_encode( [ @@ -276,11 +287,13 @@ public function testEdit() $this->client->expects($this->once()) ->method('patch') ->with('/user', $input, [], 0) - ->will($this->returnValue($this->response)); + ->willReturn($this->response); + + $response = json_decode((string) $this->response->getBody()); - $this->assertThat( - $this->object->edit($name, $email, $blog, $company, $location, $hireable, $bio), - $this->equalTo(json_decode($this->response->body)) + $this->assertEquals( + $response, + $this->object->edit($name, $email, $blog, $company, $location, $hireable, $bio) ); } @@ -301,8 +314,7 @@ public function testEditFailure() $hireable = true; $bio = 'There once...'; - $this->response->code = 404; - $this->response->body = $this->errorString; + $this->response = new Response('data://text/plain,' . $this->errorString, 404); $input = json_encode( [ @@ -319,13 +331,13 @@ public function testEditFailure() $this->client->expects($this->once()) ->method('patch') ->with('/user', $input, [], 0) - ->will($this->returnValue($this->response)); + ->willReturn($this->response); // $this->object->edit($name, $email, $blog, $company, $location, $hireable, $bio); - $this->assertThat( - $this->object->edit($name, $email, $blog, $company, $location, $hireable, $bio), - $this->equalTo(json_decode($this->response->body)) + $this->assertEquals( + json_decode((string) $this->response->getBody()), + $this->object->edit($name, $email, $blog, $company, $location, $hireable, $bio) ); } } diff --git a/Tests/Package/ZenTest.php b/Tests/Package/ZenTest.php index f7ab1943..f2e80063 100644 --- a/Tests/Package/ZenTest.php +++ b/Tests/Package/ZenTest.php @@ -8,6 +8,7 @@ use Joomla\Github\Package\Zen; use Joomla\Github\Tests\Stub\GitHubTestCase; +use Joomla\Http\Response; /** * Test class for the Zen package. @@ -43,17 +44,18 @@ protected function setUp(): void */ public function testGet() { - $this->response->code = 200; - $this->response->body = 'My Zen'; + $this->response = new Response('data://text/plain,My Zen', 200); $this->client->expects($this->once()) ->method('get') ->with('/zen', [], 0) - ->will($this->returnValue($this->response)); + ->willReturn($this->response); - $this->assertThat( - $this->object->get(), - $this->equalTo($this->response->body) + $response = (string) $this->response->getBody(); + + $this->assertEquals( + $response, + $this->object->get() ); } @@ -66,17 +68,18 @@ public function testGetFailure() { $this->expectException(\RuntimeException::class); - $this->response->code = 400; - $this->response->body = 'My Zen'; + $this->response = new Response('data://text/plain,My Zen', 400); $this->client->expects($this->once()) ->method('get') ->with('/zen', [], 0) - ->will($this->returnValue($this->response)); + ->willReturn($this->response); + + $response = (string) $this->response->getBody(); - $this->assertThat( - $this->object->get(), - $this->equalTo($this->response->body) + $this->assertEquals( + $response, + $this->object->get() ); } } diff --git a/Tests/Stub/GitHubTestCase.php b/Tests/Stub/GitHubTestCase.php index c4c91664..e0eba3de 100644 --- a/Tests/Stub/GitHubTestCase.php +++ b/Tests/Stub/GitHubTestCase.php @@ -6,6 +6,8 @@ namespace Joomla\Github\Tests\Stub; +use Joomla\Http\Http; +use Joomla\Http\Response; use Joomla\Registry\Registry; use PHPUnit\Framework\TestCase; @@ -23,7 +25,7 @@ abstract class GitHubTestCase extends TestCase protected $options; /** - * @var \PHPUnit_Framework_MockObject_MockObject Mock client object. + * @var Http Mock client object. * @since 1.0 */ protected $client; @@ -60,15 +62,13 @@ protected function setUp(): void $this->options = new Registry(); - $this->client = $this->getMockBuilder('\\Joomla\\Http\\Http') - ->setMethods(['get', 'post', 'delete', 'patch', 'put']) - ->getMock(); + $this->client = $this->createMock(Http::class); - $this->response = $this->getMockBuilder('\\Joomla\\Http\\Response') - ->getMock(); + $this->response = $this->getResponseObject($this->sampleString); + } - // Set a default response - $this->response->code = 200; - $this->response->body = $this->sampleString; + protected function getResponseObject($body, $code = 200, $headers = []) + { + return new Response('data://text/plain,' . $body, $code, $headers); } } diff --git a/composer.json b/composer.json index 1d7e806a..49ad2e0a 100644 --- a/composer.json +++ b/composer.json @@ -6,16 +6,16 @@ "homepage": "https://github.com/joomla-framework/github-api", "license": "GPL-2.0-or-later", "require": { - "php": "^8.1.0", - "joomla/http": "^3.0", - "joomla/registry": "^3.0", - "joomla/uri": "^3.0" + "php": "^8.3.0", + "joomla/http": "^4.0", + "joomla/registry": "^4.0", + "joomla/uri": "^4.0" }, "require-dev": { - "phpunit/phpunit": "^9.5.28", + "phpunit/phpunit": "^12.2.7", "squizlabs/php_codesniffer": "^3.7.2", - "phpstan/phpstan": "1.12.27", - "phpstan/phpstan-deprecation-rules": "1.2.1" + "phpstan/phpstan": "^2.1.17", + "phpstan/phpstan-deprecation-rules": "^2.0.3" }, "autoload": { "psr-4": { @@ -27,11 +27,5 @@ "Joomla\\Github\\Tests\\": "Tests/" } }, - "minimum-stability": "dev", - "extra": { - "branch-alias": { - "dev-2.0-dev": "2.0-dev", - "dev-3.x-dev": "3.0-dev" - } - } + "minimum-stability": "dev" } diff --git a/docs/index.md b/docs/index.md index c87f1b49..8ca42a4a 100644 --- a/docs/index.md +++ b/docs/index.md @@ -1 +1,3 @@ * [Overview](overview.md) +* [Updating from v2 to v3](v2-to-v3-update.md) +* [Updating from v3 to v4](v3-to-v4-update.md) diff --git a/docs/v2-to-v3-update.md b/docs/v2-to-v3-update.md new file mode 100644 index 00000000..75a20fbf --- /dev/null +++ b/docs/v2-to-v3-update.md @@ -0,0 +1,7 @@ +## Updating from v2 to v3 + +The following changes were made to the Github API package between v2 and v3. + +### Minimum supported PHP version raised + +All Framework packages now require PHP 8.1 or newer. diff --git a/docs/v3-to-v4-update.md b/docs/v3-to-v4-update.md new file mode 100644 index 00000000..1098ef1e --- /dev/null +++ b/docs/v3-to-v4-update.md @@ -0,0 +1,7 @@ +## Updating from v3 to v4 + +The following changes were made to the Github API package between v3 and v4. + +### Minimum supported PHP version raised + +All Framework packages now require PHP 8.3 or newer. diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 78ed55a6..1f50f1f0 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -1,36 +1,49 @@ parameters: ignoreErrors: - - message: "#^Parameter \\#2 \\$value of method Joomla\\\\Uri\\\\Uri\\:\\:setVar\\(\\) expects string, int\\<1, max\\> given\\.$#" + message: '#^Parameter \#2 \$value of method Joomla\\Uri\\Uri\:\:setVar\(\) expects string, int\<1, max\> given\.$#' + identifier: argument.type count: 2 path: src/AbstractGithubObject.php - - message: "#^Class Joomla\\\\Github\\\\Github referenced with incorrect case\\: Joomla\\\\Github\\\\GitHub\\.$#" + message: '#^Class Joomla\\Github\\Github referenced with incorrect case\: Joomla\\Github\\GitHub\.$#' + identifier: class.nameCase count: 1 path: src/Github.php - - message: "#^Parameter \\#2 \\$value of method Joomla\\\\Uri\\\\Uri\\:\\:setVar\\(\\) expects string, int given\\.$#" + message: '#^Parameter \#2 \$value of method Joomla\\Uri\\Uri\:\:setVar\(\) expects string, int given\.$#' + identifier: argument.type count: 4 path: src/Package/Activity/Notifications.php - - message: "#^Variable \\$labels in isset\\(\\) always exists and is not nullable\\.$#" + message: '#^Variable \$labels in isset\(\) always exists and is not nullable\.$#' + identifier: isset.variable count: 1 path: src/Package/Issues.php - - message: "#^Parameter \\#2 \\$value of method Joomla\\\\Uri\\\\Uri\\:\\:setVar\\(\\) expects string, int\\