diff --git a/.drone.jsonnet b/.drone.jsonnet deleted file mode 100644 index 0bedfefe..00000000 --- a/.drone.jsonnet +++ /dev/null @@ -1,116 +0,0 @@ -local volumes = [ - { - name: "composer-cache", - path: "/tmp/composer-cache", - }, -]; - -local hostvolumes = [ - { - name: "composer-cache", - host: {path: "/tmp/composer-cache"} - }, -]; - -local composer(phpversion, params) = { - name: "composer", - image: "joomlaprojects/docker-images:php" + phpversion, - volumes: volumes, - commands: [ - "php -v", - "composer update " + params, - ] -}; - -local phpunit(phpversion) = { - name: "PHPUnit", - image: "joomlaprojects/docker-images:php" + phpversion, - [if phpversion == "8.2" then "failure"]: "ignore", - commands: ["vendor/bin/phpunit"] -}; - -local pipeline(name, phpversion, params) = { - kind: "pipeline", - name: "PHP " + name, - volumes: hostvolumes, - steps: [ - composer(phpversion, params), - phpunit(phpversion) - ], -}; - -[ - { - kind: "pipeline", - name: "Codequality", - volumes: hostvolumes, - steps: [ - { - name: "composer", - image: "joomlaprojects/docker-images:php7.4", - volumes: volumes, - commands: [ - "php -v", - "composer update", - "composer require phpmd/phpmd phpstan/phpstan" - ] - }, - { - name: "phpcs", - image: "joomlaprojects/docker-images:php7.4", - depends: [ "composer" ], - commands: [ - "vendor/bin/phpcs --config-set installed_paths vendor/joomla/coding-standards", - "vendor/bin/phpcs --standard=ruleset.xml src/" - ] - }, - { - name: "phpmd", - image: "joomlaprojects/docker-images:php7.4", - depends: [ "composer" ], - failure: "ignore", - commands: [ - "vendor/bin/phpmd src text cleancode", - "vendor/bin/phpmd src text codesize", - "vendor/bin/phpmd src text controversial", - "vendor/bin/phpmd src text design", - "vendor/bin/phpmd src text unusedcode", - ] - }, - { - name: "phpstan", - image: "joomlaprojects/docker-images:php7.4", - depends: [ "composer" ], - failure: "ignore", - commands: [ - "vendor/bin/phpstan analyse src", - ] - }, - { - name: "phploc", - image: "joomlaprojects/docker-images:php7.4", - depends: [ "composer" ], - failure: "ignore", - commands: [ - "phploc src", - ] - }, - { - name: "phpcpd", - image: "joomlaprojects/docker-images:php7.4", - depends: [ "composer" ], - failure: "ignore", - commands: [ - "phpcpd src", - ] - } - ] - }, - pipeline("7.2 lowest", "7.2", "--prefer-stable --prefer-lowest"), - pipeline("7.2", "7.2", "--prefer-stable"), - pipeline("7.3", "7.3", "--prefer-stable"), - pipeline("7.4", "7.4", "--prefer-stable"), - pipeline("8.0", "8.0", "--prefer-stable"), - pipeline("8.1", "8.1", "--prefer-stable"), - pipeline("8.2", "8.2", "--prefer-stable --ignore-platform-reqs"), -] diff --git a/.drone.yml b/.drone.yml deleted file mode 100644 index 6a9a6920..00000000 --- a/.drone.yml +++ /dev/null @@ -1,347 +0,0 @@ ---- -{ - "kind": "pipeline", - "name": "Codequality", - "steps": [ - { - "commands": [ - "php -v", - "composer update", - "composer require phpmd/phpmd phpstan/phpstan" - ], - "image": "joomlaprojects/docker-images:php7.4", - "name": "composer", - "volumes": [ - { - "name": "composer-cache", - "path": "/tmp/composer-cache" - } - ] - }, - { - "commands": [ - "vendor/bin/phpcs --config-set installed_paths vendor/joomla/coding-standards", - "vendor/bin/phpcs --standard=ruleset.xml src/" - ], - "depends": [ - "composer" - ], - "image": "joomlaprojects/docker-images:php7.4", - "name": "phpcs" - }, - { - "commands": [ - "vendor/bin/phpmd src text cleancode", - "vendor/bin/phpmd src text codesize", - "vendor/bin/phpmd src text controversial", - "vendor/bin/phpmd src text design", - "vendor/bin/phpmd src text unusedcode" - ], - "depends": [ - "composer" - ], - "failure": "ignore", - "image": "joomlaprojects/docker-images:php7.4", - "name": "phpmd" - }, - { - "commands": [ - "vendor/bin/phpstan analyse src" - ], - "depends": [ - "composer" - ], - "failure": "ignore", - "image": "joomlaprojects/docker-images:php7.4", - "name": "phpstan" - }, - { - "commands": [ - "phploc src" - ], - "depends": [ - "composer" - ], - "failure": "ignore", - "image": "joomlaprojects/docker-images:php7.4", - "name": "phploc" - }, - { - "commands": [ - "phpcpd src" - ], - "depends": [ - "composer" - ], - "failure": "ignore", - "image": "joomlaprojects/docker-images:php7.4", - "name": "phpcpd" - } - ], - "volumes": [ - { - "host": { - "path": "/tmp/composer-cache" - }, - "name": "composer-cache" - } - ] -} ---- -{ - "kind": "pipeline", - "name": "PHP 7.2 lowest", - "steps": [ - { - "commands": [ - "php -v", - "composer update --prefer-stable --prefer-lowest" - ], - "image": "joomlaprojects/docker-images:php7.2", - "name": "composer", - "volumes": [ - { - "name": "composer-cache", - "path": "/tmp/composer-cache" - } - ] - }, - { - "commands": [ - "vendor/bin/phpunit" - ], - "image": "joomlaprojects/docker-images:php7.2", - "name": "PHPUnit" - } - ], - "volumes": [ - { - "host": { - "path": "/tmp/composer-cache" - }, - "name": "composer-cache" - } - ] -} ---- -{ - "kind": "pipeline", - "name": "PHP 7.2", - "steps": [ - { - "commands": [ - "php -v", - "composer update --prefer-stable" - ], - "image": "joomlaprojects/docker-images:php7.2", - "name": "composer", - "volumes": [ - { - "name": "composer-cache", - "path": "/tmp/composer-cache" - } - ] - }, - { - "commands": [ - "vendor/bin/phpunit" - ], - "image": "joomlaprojects/docker-images:php7.2", - "name": "PHPUnit" - } - ], - "volumes": [ - { - "host": { - "path": "/tmp/composer-cache" - }, - "name": "composer-cache" - } - ] -} ---- -{ - "kind": "pipeline", - "name": "PHP 7.3", - "steps": [ - { - "commands": [ - "php -v", - "composer update --prefer-stable" - ], - "image": "joomlaprojects/docker-images:php7.3", - "name": "composer", - "volumes": [ - { - "name": "composer-cache", - "path": "/tmp/composer-cache" - } - ] - }, - { - "commands": [ - "vendor/bin/phpunit" - ], - "image": "joomlaprojects/docker-images:php7.3", - "name": "PHPUnit" - } - ], - "volumes": [ - { - "host": { - "path": "/tmp/composer-cache" - }, - "name": "composer-cache" - } - ] -} ---- -{ - "kind": "pipeline", - "name": "PHP 7.4", - "steps": [ - { - "commands": [ - "php -v", - "composer update --prefer-stable" - ], - "image": "joomlaprojects/docker-images:php7.4", - "name": "composer", - "volumes": [ - { - "name": "composer-cache", - "path": "/tmp/composer-cache" - } - ] - }, - { - "commands": [ - "vendor/bin/phpunit" - ], - "image": "joomlaprojects/docker-images:php7.4", - "name": "PHPUnit" - } - ], - "volumes": [ - { - "host": { - "path": "/tmp/composer-cache" - }, - "name": "composer-cache" - } - ] -} ---- -{ - "kind": "pipeline", - "name": "PHP 8.0", - "steps": [ - { - "commands": [ - "php -v", - "composer update --prefer-stable" - ], - "image": "joomlaprojects/docker-images:php8.0", - "name": "composer", - "volumes": [ - { - "name": "composer-cache", - "path": "/tmp/composer-cache" - } - ] - }, - { - "commands": [ - "vendor/bin/phpunit" - ], - "image": "joomlaprojects/docker-images:php8.0", - "name": "PHPUnit" - } - ], - "volumes": [ - { - "host": { - "path": "/tmp/composer-cache" - }, - "name": "composer-cache" - } - ] -} ---- -{ - "kind": "pipeline", - "name": "PHP 8.1", - "steps": [ - { - "commands": [ - "php -v", - "composer update --prefer-stable" - ], - "image": "joomlaprojects/docker-images:php8.1", - "name": "composer", - "volumes": [ - { - "name": "composer-cache", - "path": "/tmp/composer-cache" - } - ] - }, - { - "commands": [ - "vendor/bin/phpunit" - ], - "image": "joomlaprojects/docker-images:php8.1", - "name": "PHPUnit" - } - ], - "volumes": [ - { - "host": { - "path": "/tmp/composer-cache" - }, - "name": "composer-cache" - } - ] -} ---- -{ - "kind": "pipeline", - "name": "PHP 8.2", - "steps": [ - { - "commands": [ - "php -v", - "composer update --prefer-stable --ignore-platform-reqs" - ], - "image": "joomlaprojects/docker-images:php8.2", - "name": "composer", - "volumes": [ - { - "name": "composer-cache", - "path": "/tmp/composer-cache" - } - ] - }, - { - "commands": [ - "vendor/bin/phpunit" - ], - "failure": "ignore", - "image": "joomlaprojects/docker-images:php8.2", - "name": "PHPUnit" - } - ], - "volumes": [ - { - "host": { - "path": "/tmp/composer-cache" - }, - "name": "composer-cache" - } - ] -} ---- -kind: signature -hmac: 0f630909a1c433137ead18e482d0367110ab613381af2840e3cde18d54fd9ac9 - -... diff --git a/.editorconfig b/.editorconfig index c8bb3e7b..78a64203 100644 --- a/.editorconfig +++ b/.editorconfig @@ -2,7 +2,8 @@ # Unix-style newlines with a newline ending every file [*] -indent_style = tab +indent_style = space +indent_size = 4 end_of_line = lf charset = utf-8 trim_trailing_whitespace = true diff --git a/.gitattributes b/.gitattributes index 4d38e471..839fec09 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,9 +1,9 @@ .github/ export-ignore build/ export-ignore Tests/ export-ignore -.drone.jsonnet export-ignore -.drone.yml export-ignore .gitattributes export-ignore .gitignore export-ignore +phpstan.neon export-ignore +phpstan-baseline.neon export-ignore phpunit.xml.dist export-ignore ruleset.xml export-ignore diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md deleted file mode 100644 index 368ba80a..00000000 --- a/.github/CONTRIBUTING.md +++ /dev/null @@ -1,3 +0,0 @@ -# Contributing to the Joomla! Framework - -Please review [http://framework.joomla.org/contribute](http://framework.joomla.org/contribute) for information on how to contribute to the Framework's development. diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml deleted file mode 100644 index 1914e099..00000000 --- a/.github/FUNDING.yml +++ /dev/null @@ -1,2 +0,0 @@ -github: joomla -custom: https://community.joomla.org/sponsorship-campaigns.html diff --git a/.github/ISSUE_TEMPLATE.md b/.github/ISSUE_TEMPLATE.md deleted file mode 100644 index c275880f..00000000 --- a/.github/ISSUE_TEMPLATE.md +++ /dev/null @@ -1,14 +0,0 @@ -### Steps to reproduce the issue - - -### Expected result - - -### Actual result - - -### System information (as much as possible) - - -### Additional comments - diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index f457c25f..00000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ -Pull Request for Issue # - -### Summary of Changes - -### Testing Instructions - -### Documentation Changes Required diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 00000000..09649838 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,15 @@ +name: CI Joomla Framework + +on: + push: + pull_request: + schedule: + - cron: 15 2 * * 1 + +concurrency: + group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} + cancel-in-progress: true + +jobs: + framework-ci: + uses: joomla-framework/.github/.github/workflows/workflow-v3.yml@main diff --git a/.gitignore b/.gitignore index caa2a39c..425fe5da 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,16 @@ +# IDE Related Files # +.buildpath +.project +.settings +.DS_Store +.idea + +# Composer and test related files # vendor/ composer.phar composer.lock phpunit.xml -build/ +.phpunit.cache/ +.idea/ /.phpunit.result.cache +/.phpunit.cache/ diff --git a/README.md b/README.md index 8296f2b2..5952754a 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# The GitHub Package [](https://ci.joomla.org/joomla-framework/github-api) +# The GitHub Package [](https://github.com/joomla-framework/github-api) [](https://packagist.org/packages/joomla/github) [](https://packagist.org/packages/joomla/github) @@ -482,7 +482,7 @@ $label = $github->issues->labels->get(':owner', ':repo', ':labelName'); $github->issues->labels->create(':owner', ':repo', ':labelName', ':labelColor'); // Update a label -$github->issues->labels->update(':owner', ':repo', ':oldLableName', ':newLabelName', ':labelColor'); +$github->issues->labels->update(':owner', ':repo', ':oldLabelName', ':newLabelName', ':labelColor'); // Delete a label $github->issues->labels->delete(':owner', ':repo', ':labelName'); diff --git a/Tests/GithubObjectTest.php b/Tests/GithubObjectTest.php index b85cb8eb..43bf0795 100755 --- a/Tests/GithubObjectTest.php +++ b/Tests/GithubObjectTest.php @@ -1,4 +1,5 @@ object = new ObjectMock($this->options, $this->client); - } - - /** - * Data provider method for the fetchUrl method tests. - * - * @return array - * - * @since 1.0 - */ - public function fetchUrlData() - { - return array( - 'Standard github - no pagination data' => array( - 'https://api.github.com', - '/gists', - 0, - 0, - 'https://api.github.com/gists' - ), - 'Enterprise github - no pagination data' => array( - 'https://mygithub.com', - '/gists', - 0, - 0, - 'https://mygithub.com/gists' - ), - 'Standard github - page 3' => array( - 'https://api.github.com', - '/gists', - 3, - 0, - 'https://api.github.com/gists?page=3' - ), - 'Enterprise github - page 3, 50 per page' => array( - 'https://mygithub.com', - '/gists', - 3, - 50, - 'https://mygithub.com/gists?page=3&per_page=50' - ), - ); - } - - /** - * Tests the fetchUrl method - * - * @param string $apiUrl @todo - * @param string $path @todo - * @param integer $page @todo - * @param integer $limit @todo - * @param string $expected @todo - * - * @return void - * - * @since 1.0 - * @dataProvider fetchUrlData - */ - public function testFetchUrl($apiUrl, $path, $page, $limit, $expected) - { - $this->options->set('api.url', $apiUrl); - - $this->assertThat( - $this->object->fetchUrl($path, $page, $limit), - $this->equalTo($expected) - ); - } - - /** - * Tests the fetchUrl method with basic authentication data - * - * @return void - * - * @since 1.0 - */ - public function testFetchUrlBasicAuth() - { - $this->options->set('api.url', 'https://api.github.com'); - - $this->options->set('api.username', 'MyTestUser'); - $this->options->set('api.password', 'MyTestPass'); - - $this->assertThat( - $this->object->fetchUrl('/gists', 0, 0), - $this->equalTo('https://MyTestUser:MyTestPass@api.github.com/gists'), - 'URL is not as expected.' - ); - } - - /** - * Tests the fetchUrl method using an oAuth token. - * - * @return void - */ - public function testFetchUrlToken() - { - $this->options->set('api.url', 'https://api.github.com'); - - $this->options->set('gh.token', 'MyTestToken'); - - $this->assertThat( - (string) $this->object->fetchUrl('/gists', 0, 0), - $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.' - ); - } + /** + * @var ObjectMock Object under test. + * @since 1.0 + */ + protected $object; + + /** + * Sets up the fixture, for example, opens a network connection. + * This method is called before a test is executed. + * + * @return void + * + * @since 1.0 + */ + protected function setUp(): void + { + parent::setUp(); + + $this->object = new ObjectMock($this->options, $this->client); + } + + /** + * Data provider method for the fetchUrl method tests. + * + * @return array + * + * @since 1.0 + */ + public function fetchUrlData() + { + return [ + 'Standard github - no pagination data' => [ + 'https://api.github.com', + '/gists', + 0, + 0, + 'https://api.github.com/gists', + ], + 'Enterprise github - no pagination data' => [ + 'https://mygithub.com', + '/gists', + 0, + 0, + 'https://mygithub.com/gists', + ], + 'Standard github - page 3' => [ + 'https://api.github.com', + '/gists', + 3, + 0, + 'https://api.github.com/gists?page=3', + ], + 'Enterprise github - page 3, 50 per page' => [ + 'https://mygithub.com', + '/gists', + 3, + 50, + 'https://mygithub.com/gists?page=3&per_page=50', + ], + ]; + } + + /** + * Tests the fetchUrl method + * + * @param string $apiUrl @todo + * @param string $path @todo + * @param integer $page @todo + * @param integer $limit @todo + * @param string $expected @todo + * + * @return void + * + * @since 1.0 + * @dataProvider fetchUrlData + */ + public function testFetchUrl($apiUrl, $path, $page, $limit, $expected) + { + $this->options->set('api.url', $apiUrl); + + $this->assertThat( + $this->object->fetchUrl($path, $page, $limit), + $this->equalTo($expected) + ); + } + + /** + * Tests the fetchUrl method with basic authentication data + * + * @return void + * + * @since 1.0 + */ + public function testFetchUrlBasicAuth() + { + $this->options->set('api.url', 'https://api.github.com'); + + $this->options->set('api.username', 'MyTestUser'); + $this->options->set('api.password', 'MyTestPass'); + + $this->assertThat( + $this->object->fetchUrl('/gists', 0, 0), + $this->equalTo('https://MyTestUser:MyTestPass@api.github.com/gists'), + 'URL is not as expected.' + ); + } + + /** + * Tests the fetchUrl method using an oAuth token. + * + * @return void + */ + public function testFetchUrlToken() + { + $this->options->set('api.url', 'https://api.github.com'); + + $this->options->set('gh.token', 'MyTestToken'); + + $this->assertThat( + (string) $this->object->fetchUrl('/gists', 0, 0), + $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/GithubTest.php b/Tests/GithubTest.php index 68960064..f372a0cb 100755 --- a/Tests/GithubTest.php +++ b/Tests/GithubTest.php @@ -1,4 +1,5 @@ object = new Github($this->options, $this->client); - } - - /** - * Tests the magic __get method - forks - * - * @return void - * - * @since 1.0 - */ - public function testGetForks() - { - $this->assertThat( - $this->object->repositories->forks, - $this->isInstanceOf('Joomla\Github\Package\Repositories\Forks') - ); - } - - /** - * Tests the magic __get method - commits - * - * @return void - * - * @since 1.0 - */ - public function testGetCommits() - { - $this->assertThat( - $this->object->repositories->commits, - $this->isInstanceOf('Joomla\Github\Package\Repositories\Commits') - ); - } - - /** - * Tests the magic __get method - statuses - * - * @return void - * - * @since 1.0 - */ - public function testGetStatuses() - { - $this->assertThat( - $this->object->repositories->statuses, - $this->isInstanceOf('Joomla\Github\Package\Repositories\Statuses') - ); - } - - /** - * Tests the magic __get method - hooks - * - * @return void - * - * @since 1.0 - */ - public function testGetHooks() - { - $this->assertThat( - $this->object->repositories->hooks, - $this->isInstanceOf('Joomla\Github\Package\Repositories\Hooks') - ); - } - - /** - * Tests the magic __get method - failure - * - * @return void - * - * @since 1.0 - */ - public function testGetFailure() - { - $this->expectException(\InvalidArgumentException::class); - - $this->object->other; - } - - /** - * Tests the setOption method - * - * @return void - * - * @since 1.0 - */ - public function testSetOption() - { - $this->object->setOption('api.url', 'https://example.com/settest'); - - $this->assertThat( - $this->options->get('api.url'), - $this->equalTo('https://example.com/settest') - ); - } - - /** - * Tests the getOption method - * - * @return void - * - * @since 1.0 - */ - public function testGetOption() - { - $this->options->set('api.url', 'https://example.com/gettest'); - - $this->assertThat( - $this->object->getOption('api.url'), - $this->equalTo('https://example.com/gettest') - ); - } + /** + * @var Github Object under test. + * @since 1.0 + */ + protected $object; + + /** + * Sets up the fixture, for example, opens a network connection. + * This method is called before a test is executed. + * + * @return void + * + * @since 1.0 + */ + protected function setUp(): void + { + parent::setUp(); + + $this->object = new Github($this->options, $this->client); + } + + /** + * Tests the magic __get method - forks + * + * @return void + * + * @since 1.0 + */ + public function testGetForks() + { + $this->assertThat( + $this->object->repositories->forks, + $this->isInstanceOf('Joomla\Github\Package\Repositories\Forks') + ); + } + + /** + * Tests the magic __get method - commits + * + * @return void + * + * @since 1.0 + */ + public function testGetCommits() + { + $this->assertThat( + $this->object->repositories->commits, + $this->isInstanceOf('Joomla\Github\Package\Repositories\Commits') + ); + } + + /** + * Tests the magic __get method - statuses + * + * @return void + * + * @since 1.0 + */ + public function testGetStatuses() + { + $this->assertThat( + $this->object->repositories->statuses, + $this->isInstanceOf('Joomla\Github\Package\Repositories\Statuses') + ); + } + + /** + * Tests the magic __get method - hooks + * + * @return void + * + * @since 1.0 + */ + public function testGetHooks() + { + $this->assertThat( + $this->object->repositories->hooks, + $this->isInstanceOf('Joomla\Github\Package\Repositories\Hooks') + ); + } + + /** + * Tests the magic __get method - failure + * + * @return void + * + * @since 1.0 + */ + public function testGetFailure() + { + $this->expectException(\InvalidArgumentException::class); + + $this->object->other; + } + + /** + * Tests the setOption method + * + * @return void + * + * @since 1.0 + */ + public function testSetOption() + { + $this->object->setOption('api.url', 'https://example.com/settest'); + + $this->assertThat( + $this->options->get('api.url'), + $this->equalTo('https://example.com/settest') + ); + } + + /** + * Tests the getOption method + * + * @return void + * + * @since 1.0 + */ + public function testGetOption() + { + $this->options->set('api.url', 'https://example.com/gettest'); + + $this->assertThat( + $this->object->getOption('api.url'), + $this->equalTo('https://example.com/gettest') + ); + } } diff --git a/Tests/Package/Activity/EventsTest.php b/Tests/Package/Activity/EventsTest.php index c214f922..1e39801c 100644 --- a/Tests/Package/Activity/EventsTest.php +++ b/Tests/Package/Activity/EventsTest.php @@ -1,4 +1,5 @@ object = new Events($this->options, $this->client); - } - - /** - * Tests the getPublic method - * - * @return void - */ - public function testGetPublic() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/events') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->getPublic(), - $this->equalTo(json_decode($this->response->body)) - ); - } - - /** - * Tests the getRepository method - * - * @return void - */ - public function testGetRepository() - { - $path = '/repos/' . $this->owner . '/' . $this->repo . '/events'; - - $this->client->expects($this->once()) - ->method('get') - ->with($path) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->getRepository($this->owner, $this->repo), - $this->equalTo(json_decode($this->response->body)) - ); - } - - /** - * Tests the getIssue method - * - * @return void - */ - public function testGetIssue() - { - $path = '/repos/' . $this->owner . '/' . $this->repo . '/issues/events'; - - $this->client->expects($this->once()) - ->method('get') - ->with($path) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->getIssue($this->owner, $this->repo), - $this->equalTo(json_decode($this->response->body)) - ); - } - - /** - * Tests the getNetwork method - * - * @return void - */ - public function testGetNetwork() - { - $path = '/networks/' . $this->owner . '/' . $this->repo . '/events'; - - $this->client->expects($this->once()) - ->method('get') - ->with($path) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->getNetwork($this->owner, $this->repo), - $this->equalTo(json_decode($this->response->body)) - ); - } - - /** - * Tests the getOrg method - * - * @return void - */ - public function testGetOrg() - { - $path = '/orgs/' . $this->owner . '/events'; - - $this->client->expects($this->once()) - ->method('get') - ->with($path) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->getOrg($this->owner), - $this->equalTo(json_decode($this->response->body)) - ); - } - - /** - * Tests the getUser method - * - * @return void - */ - public function testGetUser() - { - $path = '/users/' . $this->owner . '/received_events'; - - $this->client->expects($this->once()) - ->method('get') - ->with($path) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->getUser($this->owner), - $this->equalTo(json_decode($this->response->body)) - ); - } - - /** - * Tests the getUserPublic method - * - * @return void - */ - public function testGetUserPublic() - { - $path = '/users/' . $this->owner . '/received_events/public'; - - $this->client->expects($this->once()) - ->method('get') - ->with($path) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->getUserPublic($this->owner), - $this->equalTo(json_decode($this->response->body)) - ); - } - - /** - * Tests the getByUser method - * - * @return void - */ - public function testGetByUser() - { - $path = '/users/' . $this->owner . '/events'; - - $this->client->expects($this->once()) - ->method('get') - ->with($path) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->getByUser($this->owner), - $this->equalTo(json_decode($this->response->body)) - ); - } - - /** - * Tests the getByUserPublic method - * - * @return void - */ - public function testGetByUserPublic() - { - $path = '/users/' . $this->owner . '/events/public'; - - $this->client->expects($this->once()) - ->method('get') - ->with($path) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->getByUserPublic($this->owner), - $this->equalTo(json_decode($this->response->body)) - ); - } - - /** - * Tests the getUserOrg method - * - * @return void - */ - public function testGetUserOrg() - { - $path = '/users/' . $this->owner . '/events/orgs/' . $this->repo; - - $this->client->expects($this->once()) - ->method('get') - ->with($path) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->getUserOrg($this->owner, $this->repo), - $this->equalTo(json_decode($this->response->body)) - ); - } + /** + * @var Events Object under test. + * @since 1.0 + */ + protected $object; + + /** + * @var string + * @since 1.0 + */ + protected $owner = 'joomla'; + + /** + * @var string + * @since 1.0 + */ + protected $repo = 'joomla-framework'; + + /** + * Sets up the fixture, for example, opens a network connection. + * This method is called before a test is executed. + * + * @since 1.0 + * + * @return void + */ + protected function setUp(): void + { + parent::setUp(); + + $this->object = new Events($this->options, $this->client); + } + + /** + * Tests the getPublic method + * + * @return void + */ + public function testGetPublic() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/events') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->getPublic(), + $this->equalTo(json_decode($this->response->body)) + ); + } + + /** + * Tests the getRepository method + * + * @return void + */ + public function testGetRepository() + { + $path = '/repos/' . $this->owner . '/' . $this->repo . '/events'; + + $this->client->expects($this->once()) + ->method('get') + ->with($path) + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->getRepository($this->owner, $this->repo), + $this->equalTo(json_decode($this->response->body)) + ); + } + + /** + * Tests the getIssue method + * + * @return void + */ + public function testGetIssue() + { + $path = '/repos/' . $this->owner . '/' . $this->repo . '/issues/events'; + + $this->client->expects($this->once()) + ->method('get') + ->with($path) + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->getIssue($this->owner, $this->repo), + $this->equalTo(json_decode($this->response->body)) + ); + } + + /** + * Tests the getNetwork method + * + * @return void + */ + public function testGetNetwork() + { + $path = '/networks/' . $this->owner . '/' . $this->repo . '/events'; + + $this->client->expects($this->once()) + ->method('get') + ->with($path) + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->getNetwork($this->owner, $this->repo), + $this->equalTo(json_decode($this->response->body)) + ); + } + + /** + * Tests the getOrg method + * + * @return void + */ + public function testGetOrg() + { + $path = '/orgs/' . $this->owner . '/events'; + + $this->client->expects($this->once()) + ->method('get') + ->with($path) + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->getOrg($this->owner), + $this->equalTo(json_decode($this->response->body)) + ); + } + + /** + * Tests the getUser method + * + * @return void + */ + public function testGetUser() + { + $path = '/users/' . $this->owner . '/received_events'; + + $this->client->expects($this->once()) + ->method('get') + ->with($path) + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->getUser($this->owner), + $this->equalTo(json_decode($this->response->body)) + ); + } + + /** + * Tests the getUserPublic method + * + * @return void + */ + public function testGetUserPublic() + { + $path = '/users/' . $this->owner . '/received_events/public'; + + $this->client->expects($this->once()) + ->method('get') + ->with($path) + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->getUserPublic($this->owner), + $this->equalTo(json_decode($this->response->body)) + ); + } + + /** + * Tests the getByUser method + * + * @return void + */ + public function testGetByUser() + { + $path = '/users/' . $this->owner . '/events'; + + $this->client->expects($this->once()) + ->method('get') + ->with($path) + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->getByUser($this->owner), + $this->equalTo(json_decode($this->response->body)) + ); + } + + /** + * Tests the getByUserPublic method + * + * @return void + */ + public function testGetByUserPublic() + { + $path = '/users/' . $this->owner . '/events/public'; + + $this->client->expects($this->once()) + ->method('get') + ->with($path) + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->getByUserPublic($this->owner), + $this->equalTo(json_decode($this->response->body)) + ); + } + + /** + * Tests the getUserOrg method + * + * @return void + */ + public function testGetUserOrg() + { + $path = '/users/' . $this->owner . '/events/orgs/' . $this->repo; + + $this->client->expects($this->once()) + ->method('get') + ->with($path) + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->getUserOrg($this->owner, $this->repo), + $this->equalTo(json_decode($this->response->body)) + ); + } } diff --git a/Tests/Package/Activity/FeedsTest.php b/Tests/Package/Activity/FeedsTest.php index bb8c8d2e..173c7010 100644 --- a/Tests/Package/Activity/FeedsTest.php +++ b/Tests/Package/Activity/FeedsTest.php @@ -1,4 +1,5 @@ object = new Feeds($this->options, $this->client); - } - - /** - * Tests the getFeeds method - * - * @return void - */ - public function testGetFeeds() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/feeds') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->getFeeds(), - $this->equalTo(json_decode($this->response->body)) - ); - } + /** + * @var Feeds Object under test. + * @since 1.4.0 + */ + protected $object; + + /** + * Sets up the fixture, for example, opens a network connection. + * This method is called before a test is executed. + * + * @since 1.4.0 + * + * @return void + */ + protected function setUp(): void + { + parent::setUp(); + + $this->object = new Feeds($this->options, $this->client); + } + + /** + * Tests the getFeeds method + * + * @return void + */ + public function testGetFeeds() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/feeds') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->getFeeds(), + $this->equalTo(json_decode($this->response->body)) + ); + } } diff --git a/Tests/Package/Activity/NotificationsTest.php b/Tests/Package/Activity/NotificationsTest.php index ade094b7..66d06e7b 100644 --- a/Tests/Package/Activity/NotificationsTest.php +++ b/Tests/Package/Activity/NotificationsTest.php @@ -1,4 +1,5 @@ object = new Notifications($this->options, $this->client); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Activity\Notifications::getList() - * - * @return void - */ - 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', array(), 0) - ->will($this->returnValue($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)) - ); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Activity\Notifications::getListRepository() - * - * @return void - */ - public function testGetListRepository() - { - $args = 'all=1&participating=1&since=2005-08-17T00:00:00+00:00&before=2005-08-17T00:00:00+00:00'; - - $this->client->expects($this->once()) - ->method('get') - ->with('/repos/{owner}/{repo}/notifications?' . $args, array(), 0) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->getListRepository( - '{owner}', - '{repo}', - 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)) - ); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Activity\Notifications::markRead() - * - * @return void - */ - public function testMarkRead() - { - $this->response->code = 205; - $this->response->body = ''; - - $this->client->expects($this->once()) - ->method('put') - ->with('/notifications', '{"unread":true,"read":true}', array(), 0) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->markRead(), - $this->equalTo($this->response->body) - ); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Activity\Notifications::markRead() - * - * @return void - */ - public function testMarkReadLastRead() - { - $this->response->code = 205; - $this->response->body = ''; - - $date = new \DateTime('1966-09-14', new \DateTimeZone('UTC')); - $data = '{"unread":true,"read":true,"last_read_at":"1966-09-14T00:00:00+00:00"}'; - - $this->client->expects($this->once()) - ->method('put') - ->with('/notifications', $data, array(), 0) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->markRead(true, true, $date), - $this->equalTo($this->response->body) - ); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Activity\Notifications::markReadRepository() - * - * @return void - */ - public function testMarkReadRepository() - { - $this->response->code = 205; - $this->response->body = ''; - - $data = '{"unread":true,"read":true}'; - - $this->client->expects($this->once()) - ->method('put') - ->with('/repos/joomla/joomla-platform/notifications', $data, array(), 0) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->markReadRepository('joomla', 'joomla-platform', true, true), - $this->equalTo($this->response->body) - ); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Activity\Notifications::markReadRepository() - * - * @return void - */ - public function testMarkReadRepositoryLastRead() - { - $this->response->code = 205; - $this->response->body = ''; - - $date = new \DateTime('1966-09-14', new \DateTimeZone('UTC')); - $data = '{"unread":true,"read":true,"last_read_at":"1966-09-14T00:00:00+00:00"}'; - - $this->client->expects($this->once()) - ->method('put') - ->with('/repos/joomla/joomla-platform/notifications', $data, array(), 0) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->markReadRepository('joomla', 'joomla-platform', true, true, $date), - $this->equalTo($this->response->body) - ); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Activity\Notifications::viewThread() - * - * @return void - */ - public function testViewThread() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/notifications/threads/1', array(), 0) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->viewThread(1), - $this->equalTo(json_decode($this->response->body)) - ); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Activity\Notifications::markReadThread() - * - * @return void - */ - public function testMarkReadThread() - { - $this->response->code = 205; - - $this->client->expects($this->once()) - ->method('patch') - ->with('/notifications/threads/1', '{"unread":true,"read":true}', array(), 0) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->markReadThread(1), - $this->equalTo(json_decode($this->response->body)) - ); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Activity\Notifications::getThreadSubscription() - * - * @return void - */ - public function testGetThreadSubscription() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/notifications/threads/1/subscription', array(), 0) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->getThreadSubscription(1), - $this->equalTo(json_decode($this->response->body)) - ); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Activity\Notifications::setThreadSubscription() - * - * @return void - */ - public function testSetThreadSubscription() - { - $this->client->expects($this->once()) - ->method('put') - ->with('/notifications/threads/1/subscription', '{"subscribed":true,"ignored":false}', array(), 0) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->setThreadSubscription(1, true, false), - $this->equalTo(json_decode($this->response->body)) - ); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Activity\Notifications::deleteThreadSubscription() - * - * @return void - */ - public function testDeleteThreadSubscription() - { - $this->response->code = 204; - $this->response->body = ''; - - $this->client->expects($this->once()) - ->method('delete') - ->with('/notifications/threads/1/subscription', array(), 0) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->deleteThreadSubscription(1), - $this->equalTo(json_decode($this->response->body)) - ); - } + /** + * @var Notifications Object under test. + * @since 1.0 + */ + protected $object; + + /** + * Sets up the fixture, for example, opens a network connection. + * This method is called before a test is executed. + * + * @since 1.0 + * + * @return void + */ + protected function setUp(): void + { + parent::setUp(); + + $this->object = new Notifications($this->options, $this->client); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Activity\Notifications::getList() + * + * @return void + */ + 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)); + + $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)) + ); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Activity\Notifications::getListRepository() + * + * @return void + */ + public function testGetListRepository() + { + $args = 'all=1&participating=1&since=2005-08-17T00:00:00+00:00&before=2005-08-17T00:00:00+00:00'; + + $this->client->expects($this->once()) + ->method('get') + ->with('/repos/{owner}/{repo}/notifications?' . $args, [], 0) + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->getListRepository( + '{owner}', + '{repo}', + 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)) + ); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Activity\Notifications::markRead() + * + * @return void + */ + public function testMarkRead() + { + $this->response->code = 205; + $this->response->body = ''; + + $this->client->expects($this->once()) + ->method('put') + ->with('/notifications', '{"unread":true,"read":true}', [], 0) + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->markRead(), + $this->equalTo($this->response->body) + ); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Activity\Notifications::markRead() + * + * @return void + */ + public function testMarkReadLastRead() + { + $this->response->code = 205; + $this->response->body = ''; + + $date = new \DateTime('1966-09-14', new \DateTimeZone('UTC')); + $data = '{"unread":true,"read":true,"last_read_at":"1966-09-14T00:00:00+00:00"}'; + + $this->client->expects($this->once()) + ->method('put') + ->with('/notifications', $data, [], 0) + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->markRead(true, true, $date), + $this->equalTo($this->response->body) + ); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Activity\Notifications::markReadRepository() + * + * @return void + */ + public function testMarkReadRepository() + { + $this->response->code = 205; + $this->response->body = ''; + + $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)); + + $this->assertThat( + $this->object->markReadRepository('joomla', 'joomla-platform', true, true), + $this->equalTo($this->response->body) + ); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Activity\Notifications::markReadRepository() + * + * @return void + */ + public function testMarkReadRepositoryLastRead() + { + $this->response->code = 205; + $this->response->body = ''; + + $date = new \DateTime('1966-09-14', new \DateTimeZone('UTC')); + $data = '{"unread":true,"read":true,"last_read_at":"1966-09-14T00:00:00+00:00"}'; + + $this->client->expects($this->once()) + ->method('put') + ->with('/repos/joomla/joomla-platform/notifications', $data, [], 0) + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->markReadRepository('joomla', 'joomla-platform', true, true, $date), + $this->equalTo($this->response->body) + ); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Activity\Notifications::viewThread() + * + * @return void + */ + public function testViewThread() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/notifications/threads/1', [], 0) + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->viewThread(1), + $this->equalTo(json_decode($this->response->body)) + ); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Activity\Notifications::markReadThread() + * + * @return void + */ + public function testMarkReadThread() + { + $this->response->code = 205; + + $this->client->expects($this->once()) + ->method('patch') + ->with('/notifications/threads/1', '{"unread":true,"read":true}', [], 0) + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->markReadThread(1), + $this->equalTo(json_decode($this->response->body)) + ); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Activity\Notifications::getThreadSubscription() + * + * @return void + */ + public function testGetThreadSubscription() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/notifications/threads/1/subscription', [], 0) + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->getThreadSubscription(1), + $this->equalTo(json_decode($this->response->body)) + ); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Activity\Notifications::setThreadSubscription() + * + * @return void + */ + 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)); + + $this->assertThat( + $this->object->setThreadSubscription(1, true, false), + $this->equalTo(json_decode($this->response->body)) + ); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Activity\Notifications::deleteThreadSubscription() + * + * @return void + */ + public function testDeleteThreadSubscription() + { + $this->response->code = 204; + $this->response->body = ''; + + $this->client->expects($this->once()) + ->method('delete') + ->with('/notifications/threads/1/subscription', [], 0) + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->deleteThreadSubscription(1), + $this->equalTo(json_decode($this->response->body)) + ); + } } diff --git a/Tests/Package/Activity/StarringTest.php b/Tests/Package/Activity/StarringTest.php index cc8b6dc9..c1c4cf8f 100644 --- a/Tests/Package/Activity/StarringTest.php +++ b/Tests/Package/Activity/StarringTest.php @@ -1,4 +1,5 @@ object = new Starring($this->options, $this->client); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Activity\Starring::getList() - * - * @return void - */ - public function testGetList() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/repos/joomla/joomla-platform/stargazers', array(), 0) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->getList('joomla', 'joomla-platform'), - $this->equalTo(json_decode($this->response->body)) - ); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Activity\Starring::getRepositories() - * - * @return void - */ - public function testGetRepositories() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/user/starred?sort=created&direction=desc', array(), 0) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->getRepositories(), - $this->equalTo(json_decode($this->response->body)) - ); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Activity\Starring::getRepositories() - * - * @return void - */ - public function testGetRepositoriesWithName() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/users/{user}/starred?sort=created&direction=desc', array(), 0) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->getRepositories('{user}'), - $this->equalTo(json_decode($this->response->body)) - ); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Activity\Starring::getRepositories() - * - * Invalid sort option - * - * @return void - */ - public function testGetRepositoriesInvalidSort() - { - $this->expectException(\InvalidArgumentException::class); - - $this->object->getRepositories('', 'invalid'); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Activity\Starring::getRepositories() - * - * Invalid direction option - * - * @return void - */ - public function testGetRepositoriesInvalidDirection() - { - $this->expectException(\InvalidArgumentException::class); - - $this->object->getRepositories('', 'created', 'invalid'); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Activity\Starring::check() - * - * @return void - */ - public function testCheck() - { - $this->response->code = 204; - $this->response->body = true; - - $this->client->expects($this->once()) - ->method('get') - ->with('/user/starred/joomla/joomla-platform', array(), 0) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->check('joomla', 'joomla-platform'), - $this->equalTo(json_decode($this->response->body)) - ); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Activity\Starring::check() - * - * @return void - */ - public function testCheckFalse() - { - $this->response->code = 404; - $this->response->body = false; - - $this->client->expects($this->once()) - ->method('get') - ->with('/user/starred/joomla/joomla-platform', array(), 0) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->check('joomla', 'joomla-platform'), - $this->equalTo(json_decode($this->response->body)) - ); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Activity\Starring::check() - * - * @return void - */ - public function testCheckUnexpected() - { - $this->expectException(\UnexpectedValueException::class); - - $this->response->code = 666; - $this->response->body = false; - - $this->client->expects($this->once()) - ->method('get') - ->with('/user/starred/joomla/joomla-platform', array(), 0) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->check('joomla', 'joomla-platform'), - $this->equalTo(json_decode($this->response->body)) - ); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Activity\Starring::star() - * - * @return void - */ - public function testStar() - { - $this->response->code = 204; - - $this->client->expects($this->once()) - ->method('put') - ->with('/user/starred/joomla/joomla-platform', '', array(), 0) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->star('joomla', 'joomla-platform'), - $this->equalTo(json_decode($this->response->body)) - ); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Activity\Starring::unstar() - * - * @return void - */ - public function testUnstar() - { - $this->response->code = 204; - $this->response->body = ''; - - $this->client->expects($this->once()) - ->method('delete') - ->with('/user/starred/joomla/joomla-platform', array(), 0) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->unstar('joomla', 'joomla-platform'), - $this->equalTo(json_decode($this->response->body)) - ); - } + /** + * @var Starring Object under test. + * @since 1.0 + */ + protected $object; + + /** + * Sets up the fixture, for example, opens a network connection. + * This method is called before a test is executed. + * + * @since 1.0 + * + * @return void + */ + protected function setUp(): void + { + parent::setUp(); + + $this->object = new Starring($this->options, $this->client); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Activity\Starring::getList() + * + * @return void + */ + public function testGetList() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/repos/joomla/joomla-platform/stargazers', [], 0) + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->getList('joomla', 'joomla-platform'), + $this->equalTo(json_decode($this->response->body)) + ); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Activity\Starring::getRepositories() + * + * @return void + */ + public function testGetRepositories() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/user/starred?sort=created&direction=desc', [], 0) + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->getRepositories(), + $this->equalTo(json_decode($this->response->body)) + ); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Activity\Starring::getRepositories() + * + * @return void + */ + public function testGetRepositoriesWithName() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/users/{user}/starred?sort=created&direction=desc', [], 0) + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->getRepositories('{user}'), + $this->equalTo(json_decode($this->response->body)) + ); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Activity\Starring::getRepositories() + * + * Invalid sort option + * + * @return void + */ + public function testGetRepositoriesInvalidSort() + { + $this->expectException(\InvalidArgumentException::class); + + $this->object->getRepositories('', 'invalid'); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Activity\Starring::getRepositories() + * + * Invalid direction option + * + * @return void + */ + public function testGetRepositoriesInvalidDirection() + { + $this->expectException(\InvalidArgumentException::class); + + $this->object->getRepositories('', 'created', 'invalid'); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Activity\Starring::check() + * + * @return void + */ + public function testCheck() + { + $this->response->code = 204; + $this->response->body = true; + + $this->client->expects($this->once()) + ->method('get') + ->with('/user/starred/joomla/joomla-platform', [], 0) + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->check('joomla', 'joomla-platform'), + $this->equalTo(json_decode($this->response->body)) + ); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Activity\Starring::check() + * + * @return void + */ + public function testCheckFalse() + { + $this->response->code = 404; + $this->response->body = false; + + $this->client->expects($this->once()) + ->method('get') + ->with('/user/starred/joomla/joomla-platform', [], 0) + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->check('joomla', 'joomla-platform'), + $this->equalTo(json_decode($this->response->body)) + ); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Activity\Starring::check() + * + * @return void + */ + public function testCheckUnexpected() + { + $this->expectException(\UnexpectedValueException::class); + + $this->response->code = 666; + $this->response->body = false; + + $this->client->expects($this->once()) + ->method('get') + ->with('/user/starred/joomla/joomla-platform', [], 0) + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->check('joomla', 'joomla-platform'), + $this->equalTo(json_decode($this->response->body)) + ); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Activity\Starring::star() + * + * @return void + */ + public function testStar() + { + $this->response->code = 204; + + $this->client->expects($this->once()) + ->method('put') + ->with('/user/starred/joomla/joomla-platform', '', [], 0) + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->star('joomla', 'joomla-platform'), + $this->equalTo(json_decode($this->response->body)) + ); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Activity\Starring::unstar() + * + * @return void + */ + public function testUnstar() + { + $this->response->code = 204; + $this->response->body = ''; + + $this->client->expects($this->once()) + ->method('delete') + ->with('/user/starred/joomla/joomla-platform', [], 0) + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->unstar('joomla', 'joomla-platform'), + $this->equalTo(json_decode($this->response->body)) + ); + } } diff --git a/Tests/Package/Activity/WatchingTest.php b/Tests/Package/Activity/WatchingTest.php index fca3fdef..5bc9b1e5 100644 --- a/Tests/Package/Activity/WatchingTest.php +++ b/Tests/Package/Activity/WatchingTest.php @@ -1,4 +1,5 @@ object = new Watching($this->options, $this->client); - } - - /** - * Tests the getList method - * - * @return void - */ - public function testGetList() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/repos/joomla/joomla-platform/subscribers', array(), 0) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->getList('joomla', 'joomla-platform'), - $this->equalTo(json_decode($this->response->body)) - ); - } - - /** - * Tests the getRepositories method - * - * @return void - */ - public function testGetRepositories() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/user/subscriptions', array(), 0) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->getRepositories(), - $this->equalTo(json_decode($this->response->body)) - ); - } - - /** - * Tests the getRepositoriesUser method - * - * @return void - */ - public function testGetRepositoriesUser() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/users/joomla/subscriptions', array(), 0) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->getRepositories('joomla'), - $this->equalTo(json_decode($this->response->body)) - ); - } - - /** - * Tests the getSubscription method - * - * @return void - */ - public function testGetSubscription() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/repos/joomla/joomla-platform/subscription', array(), 0) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->getSubscription('joomla', 'joomla-platform'), - $this->equalTo(json_decode($this->response->body)) - ); - } - - /** - * Tests the setSubscription method - * - * @return void - */ - public function testSetSubscription() - { - $this->client->expects($this->once()) - ->method('put') - ->with('/repos/joomla/joomla-platform/subscription', '{"subscribed":true,"ignored":false}', array(), 0) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->setSubscription('joomla', 'joomla-platform', true, false), - $this->equalTo(json_decode($this->response->body)) - ); - } - - /** - * Tests the deleteSubscription method - * - * @return void - */ - public function testDeleteSubscription() - { - $this->response->code = 204; - $this->response->body = ''; - - $this->client->expects($this->once()) - ->method('delete') - ->with('/repos/joomla/joomla-platform/subscription', array(), 0) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->deleteSubscription('joomla', 'joomla-platform'), - $this->equalTo($this->response->body) - ); - } - - /** - * Tests the check method - * - * @return void - */ - public function testCheck() - { - $this->response->code = 204; - $this->response->body = ''; - - $this->client->expects($this->once()) - ->method('get') - ->with('/user/subscriptions/joomla/joomla-platform', array(), 0) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->check('joomla', 'joomla-platform'), - $this->equalTo(true) - ); - } - - /** - * Tests the checkFalse method - * - * @return void - */ - public function testCheckFalse() - { - $this->response->code = 404; - $this->response->body = ''; - - $this->client->expects($this->once()) - ->method('get') - ->with('/user/subscriptions/joomla/joomla-platform', array(), 0) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->check('joomla', 'joomla-platform'), - $this->equalTo(false) - ); - } - - /** - * Tests the checkUnexpected method - * - * @return void - */ - public function testCheckUnexpected() - { - $this->expectException(\UnexpectedValueException::class); - - $this->response->code = 666; - $this->response->body = ''; - - $this->client->expects($this->once()) - ->method('get') - ->with('/user/subscriptions/joomla/joomla-platform', array(), 0) - ->will($this->returnValue($this->response)); - - $this->object->check('joomla', 'joomla-platform'); - } - - /** - * Tests the watch method - * - * @return void - */ - public function testWatch() - { - $this->response->code = 204; - $this->response->body = ''; - - $this->client->expects($this->once()) - ->method('put') - ->with('/user/subscriptions/joomla/joomla-platform', '', array(), 0) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->watch('joomla', 'joomla-platform'), - $this->equalTo($this->response->body) - ); - } - - /** - * Tests the unwatch method - * - * @return void - */ - public function testUnwatch() - { - $this->response->code = 204; - $this->response->body = ''; - - $this->client->expects($this->once()) - ->method('delete') - ->with('/user/subscriptions/joomla/joomla-platform', array(), 0) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->unwatch('joomla', 'joomla-platform'), - $this->equalTo($this->response->body) - ); - } + /** + * @var Watching Object under test. + * @since 1.0 + */ + protected $object; + + /** + * Sets up the fixture, for example, opens a network connection. + * This method is called before a test is executed. + * + * @since 1.0 + * + * @return void + */ + protected function setUp(): void + { + parent::setUp(); + + $this->object = new Watching($this->options, $this->client); + } + + /** + * Tests the getList method + * + * @return void + */ + public function testGetList() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/repos/joomla/joomla-platform/subscribers', [], 0) + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->getList('joomla', 'joomla-platform'), + $this->equalTo(json_decode($this->response->body)) + ); + } + + /** + * Tests the getRepositories method + * + * @return void + */ + public function testGetRepositories() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/user/subscriptions', [], 0) + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->getRepositories(), + $this->equalTo(json_decode($this->response->body)) + ); + } + + /** + * Tests the getRepositoriesUser method + * + * @return void + */ + public function testGetRepositoriesUser() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/users/joomla/subscriptions', [], 0) + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->getRepositories('joomla'), + $this->equalTo(json_decode($this->response->body)) + ); + } + + /** + * Tests the getSubscription method + * + * @return void + */ + public function testGetSubscription() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/repos/joomla/joomla-platform/subscription', [], 0) + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->getSubscription('joomla', 'joomla-platform'), + $this->equalTo(json_decode($this->response->body)) + ); + } + + /** + * Tests the setSubscription method + * + * @return void + */ + 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)); + + $this->assertThat( + $this->object->setSubscription('joomla', 'joomla-platform', true, false), + $this->equalTo(json_decode($this->response->body)) + ); + } + + /** + * Tests the deleteSubscription method + * + * @return void + */ + public function testDeleteSubscription() + { + $this->response->code = 204; + $this->response->body = ''; + + $this->client->expects($this->once()) + ->method('delete') + ->with('/repos/joomla/joomla-platform/subscription', [], 0) + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->deleteSubscription('joomla', 'joomla-platform'), + $this->equalTo($this->response->body) + ); + } + + /** + * Tests the check method + * + * @return void + */ + public function testCheck() + { + $this->response->code = 204; + $this->response->body = ''; + + $this->client->expects($this->once()) + ->method('get') + ->with('/user/subscriptions/joomla/joomla-platform', [], 0) + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->check('joomla', 'joomla-platform'), + $this->equalTo(true) + ); + } + + /** + * Tests the checkFalse method + * + * @return void + */ + public function testCheckFalse() + { + $this->response->code = 404; + $this->response->body = ''; + + $this->client->expects($this->once()) + ->method('get') + ->with('/user/subscriptions/joomla/joomla-platform', [], 0) + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->check('joomla', 'joomla-platform'), + $this->equalTo(false) + ); + } + + /** + * Tests the checkUnexpected method + * + * @return void + */ + public function testCheckUnexpected() + { + $this->expectException(\UnexpectedValueException::class); + + $this->response->code = 666; + $this->response->body = ''; + + $this->client->expects($this->once()) + ->method('get') + ->with('/user/subscriptions/joomla/joomla-platform', [], 0) + ->will($this->returnValue($this->response)); + + $this->object->check('joomla', 'joomla-platform'); + } + + /** + * Tests the watch method + * + * @return void + */ + public function testWatch() + { + $this->response->code = 204; + $this->response->body = ''; + + $this->client->expects($this->once()) + ->method('put') + ->with('/user/subscriptions/joomla/joomla-platform', '', [], 0) + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->watch('joomla', 'joomla-platform'), + $this->equalTo($this->response->body) + ); + } + + /** + * Tests the unwatch method + * + * @return void + */ + public function testUnwatch() + { + $this->response->code = 204; + $this->response->body = ''; + + $this->client->expects($this->once()) + ->method('delete') + ->with('/user/subscriptions/joomla/joomla-platform', [], 0) + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->unwatch('joomla', 'joomla-platform'), + $this->equalTo($this->response->body) + ); + } } diff --git a/Tests/Package/ActivityTest.php b/Tests/Package/ActivityTest.php index da2d6a54..8d56ef88 100644 --- a/Tests/Package/ActivityTest.php +++ b/Tests/Package/ActivityTest.php @@ -1,4 +1,5 @@ object = new Activity($this->options, $this->client); - } + $this->object = new Activity($this->options, $this->client); + } - /** - * Test method. - * - * @covers \Joomla\Github\Package\Activity::__construct() - * - * @return void - * - * @since 1.0 - */ - public function testConstruct() - { - // Dummy to make PHPUnit "happy" - self::assertEquals(true, true); - } + /** + * Test method. + * + * @covers \Joomla\Github\Package\Activity::__construct() + * + * @return void + * + * @since 1.0 + */ + public function testConstruct() + { + // Dummy to make PHPUnit "happy" + self::assertEquals(true, true); + } } diff --git a/Tests/Package/AuthorizationsTest.php b/Tests/Package/AuthorizationsTest.php index 5314e433..0a303f9a 100644 --- a/Tests/Package/AuthorizationsTest.php +++ b/Tests/Package/AuthorizationsTest.php @@ -1,4 +1,5 @@ object = new Authorization($this->options, $this->client); - } - - /** - * Tests the createAuthorisation method - * - * @return void - * - * @since 1.0 - */ - public function testCreate() - { - $this->response->code = 201; - - $authorisation = '{' - . '"scopes":["public_repo"],' - . '"note":"My test app",' - . '"note_url":"http:\/\/www.joomla.org"' - . '}'; - - $this->client->expects($this->once()) - ->method('post') - ->with('/authorizations', $authorisation) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->create(array('public_repo'), 'My test app', 'http://www.joomla.org'), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Tests the createAuthorisation method - simulated failure - * - * @return void - * - * @since 1.0 - */ - public function testCreateFailure() - { - $exception = false; - - $this->response->code = 500; - $this->response->body = $this->errorString; - - $authorisation = '{' - . '"scopes":["public_repo"],' - . '"note":"My test app",' - . '"note_url":"http:\/\/www.joomla.org"' - . '}'; - - $this->client->expects($this->once()) - ->method('post') - ->with('/authorizations', $authorisation) - ->will($this->returnValue($this->response)); - - try - { - $this->object->create(array('public_repo'), 'My test app', 'http://www.joomla.org'); - } - catch (\DomainException $e) - { - $exception = true; - - $this->assertThat( - $e->getMessage(), - $this->equalTo(json_decode($this->errorString)->message) - ); - } - - $this->assertTrue($exception); - } - - /** - * Tests the delete method - * - * @return void - * - * @since 1.0 - */ - public function testDelete() - { - $this->response->code = 204; - - $this->client->expects($this->once()) - ->method('delete') - ->with('/authorizations/42') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->delete(42), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Tests the delete method - simulated failure - * - * @return void - * - * @since 1.0 - */ - public function testDeleteFailure() - { - $exception = false; - - $this->response->code = 500; - $this->response->body = $this->errorString; - - $this->client->expects($this->once()) - ->method('delete') - ->with('/authorizations/42') - ->will($this->returnValue($this->response)); - - try - { - $this->object->delete(42); - } - catch (\DomainException $e) - { - $exception = true; - - $this->assertThat( - $e->getMessage(), - $this->equalTo(json_decode($this->errorString)->message) - ); - } - - $this->assertTrue($exception); - } - - /** - * Tests the deleteGrant method - * - * @return void - * - * @since 1.0 - */ - public function testDeleteGrant() - { - $this->response->code = 204; - - $this->client->expects($this->once()) - ->method('delete') - ->with('/authorizations/grants/42') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->deleteGrant(42), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Tests the deleteGrant method - simulated failure - * - * @return void - * - * @since 1.0 - */ - public function testDeleteGrantFailure() - { - $exception = false; - - $this->response->code = 500; - $this->response->body = $this->errorString; - - $this->client->expects($this->once()) - ->method('delete') - ->with('/authorizations/grants/42') - ->will($this->returnValue($this->response)); - - try - { - $this->object->deleteGrant(42); - } - catch (\DomainException $e) - { - $exception = true; - - $this->assertThat( - $e->getMessage(), - $this->equalTo(json_decode($this->errorString)->message) - ); - } - - $this->assertTrue($exception); - } - - /** - * Tests the editAuthorisation method - Add scopes - * - * @return void - * - * @since 1.0 - */ - public function testEditAddScopes() - { - $authorisation = '{' - . '"add_scopes":["public_repo","gist"],' - . '"note":"My test app",' - . '"note_url":"http:\/\/www.joomla.org"' - . '}'; - - $this->client->expects($this->once()) - ->method('patch') - ->with('/authorizations/42', $authorisation) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->edit(42, array(), array('public_repo', 'gist'), array(), 'My test app', 'http://www.joomla.org'), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Tests the editAuthorisation method - Remove scopes - * - * @return void - * - * @since 1.0 - */ - public function testEditRemoveScopes() - { - $authorisation = '{' - . '"remove_scopes":["public_repo","gist"],' - . '"note":"My test app",' - . '"note_url":"http:\/\/www.joomla.org"' - . '}'; - - $this->client->expects($this->once()) - ->method('patch') - ->with('/authorizations/42', $authorisation) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->edit(42, array(), array(), array('public_repo', 'gist'), 'My test app', 'http://www.joomla.org'), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Tests the editAuthorisation method - Scopes param - * - * @return void - * - * @since 1.0 - */ - public function testEditScopes() - { - $authorisation = '{' - . '"scopes":["public_repo","gist"],' - . '"note":"My test app",' - . '"note_url":"http:\/\/www.joomla.org"' - . '}'; - - $this->client->expects($this->once()) - ->method('patch') - ->with('/authorizations/42', $authorisation) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->edit(42, array('public_repo', 'gist'), array(), array(), 'My test app', 'http://www.joomla.org'), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Tests the editAuthorisation method - simulated failure - * - * @return void - * - * @since 1.0 - */ - public function testEditFailure() - { - $exception = false; - - $this->response->code = 500; - $this->response->body = $this->errorString; - - $authorisation = '{' - . '"add_scopes":["public_repo","gist"],' - . '"note":"My test app",' - . '"note_url":"http:\/\/www.joomla.org"' - . '}'; - - $this->client->expects($this->once()) - ->method('patch') - ->with('/authorizations/42', $authorisation) - ->will($this->returnValue($this->response)); - - try - { - $this->object->edit(42, array(), array('public_repo', 'gist'), array(), 'My test app', 'http://www.joomla.org'); - } - catch (\DomainException $e) - { - $exception = true; - - $this->assertThat( - $e->getMessage(), - $this->equalTo(json_decode($this->errorString)->message) - ); - } - - $this->assertTrue($exception); - } - - /** - * Tests the editAuthorisation method - too many scope params - * - * @return void - * - * @since 1.0 - */ - public function testEditTooManyScopes() - { - $this->expectException(\RuntimeException::class); - - $this->object->edit(42, array(), array('public_repo', 'gist'), array('public_repo', 'gist'), 'My test app', 'http://www.joomla.org'); - } - - /** - * Tests the get method - * - * @return void - * - * @since 1.0 - */ - public function testGet() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/authorizations/42') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->get(42), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Tests the get method - failure - * - * @return void - * - * @since 1.0 - */ - public function testGetFailure() - { - $this->expectException(\DomainException::class); - - $this->response->code = 500; - $this->response->body = $this->errorString; - - $this->client->expects($this->once()) - ->method('get') - ->with('/authorizations/42') - ->will($this->returnValue($this->response)); - - $this->object->get(42); - } - - /** - * Tests the getGrant method - * - * @return void - * - * @since 1.0 - */ - public function testGetGrant() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/authorizations/grants/42') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->getGrant(42), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Tests the getGrant method - failure - * - * @return void - * - * @since 1.0 - */ - public function testGetGrantFailure() - { - $this->expectException(\DomainException::class); - - $this->response->code = 500; - $this->response->body = $this->errorString; - - $this->client->expects($this->once()) - ->method('get') - ->with('/authorizations/grants/42') - ->will($this->returnValue($this->response)); - - $this->object->getGrant(42); - } - - /** - * Tests the getList method - * - * @return void - * - * @since 1.0 - */ - public function testGetList() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/authorizations') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->getList(), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Tests the getList method - failure - * - * @return void - * - * @since 1.0 - */ - public function testGetListFailure() - { - $this->expectException(\DomainException::class); - - $this->response->code = 500; - $this->response->body = $this->errorString; - - $this->client->expects($this->once()) - ->method('get') - ->with('/authorizations') - ->will($this->returnValue($this->response)); - - $this->object->getList(); - } - - /** - * Tests the getListGrants method - * - * @return void - * - * @since 1.0 - */ - public function testGetListGrants() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/authorizations/grants') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->getListGrants(), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Tests the getListGrants method - failure - * - * @return void - * - * @since 1.0 - */ - public function testGetListGrantsFailure() - { - $this->expectException(\DomainException::class); - - $this->response->code = 500; - $this->response->body = $this->errorString; - - $this->client->expects($this->once()) - ->method('get') - ->with('/authorizations/grants') - ->will($this->returnValue($this->response)); - - $this->object->getListGrants(); - } - - /** - * Tests the getRateLimit method - * - * @return void - * - * @since 1.0 - */ - public function testGetRateLimit() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/rate_limit') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->getRateLimit(), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Tests the getRateLimit method for an unlimited user. - * - * @return void - * - * @since 1.0 - */ - public function testGetRateLimitUnlimited() - { - $this->response->code = 404; - $this->response->body = ''; - - $this->client->expects($this->once()) - ->method('get') - ->with('/rate_limit') - ->will($this->returnValue($this->response)); - - $this->assertFalse($this->object->getRateLimit()->limit, 'The limit should be false for unlimited'); - } - - /** - * Tests the getRateLimit method - failure - * - * @return void - * - * @since 1.0 - */ - public function testGetRateLimitFailure() - { - $this->expectException(\DomainException::class); - - $this->response->code = 500; - $this->response->body = $this->errorString; - - $this->client->expects($this->once()) - ->method('get') - ->with('/rate_limit') - ->will($this->returnValue($this->response)); - - $this->object->getRateLimit(); - } - - /** - * Tests the getAuthorizationLink method - * - * @return void - */ - 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->assertThat( - $this->object->getAuthorizationLink('12345', 'aaa', 'bbb', 'ccc'), - $this->equalTo($this->response->body) - ); - } - - /** - * Tests the requestToken method - * - * @return void - */ - public function testRequestToken() - { - $this->response->code = 200; - $this->response->body = ''; - - $this->client->expects($this->once()) - ->method('post') - ->with('https://github.com/login/oauth/access_token') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->requestToken('12345', 'aaa', 'bbb', 'ccc'), - $this->equalTo($this->response->body) - ); - } - - /** - * Tests the requestTokenJson method - * - * @return void - */ - public function testRequestTokenJson() - { - $this->response->code = 200; - $this->response->body = ''; - - $this->client->expects($this->once()) - ->method('post') - ->with('https://github.com/login/oauth/access_token') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->requestToken('12345', 'aaa', 'bbb', 'ccc', 'json'), - $this->equalTo($this->response->body) - ); - } - - /** - * Tests the requestTokenXml method - * - * @return void - */ - public function testRequestTokenXml() - { - $this->response->code = 200; - $this->response->body = ''; - - $this->client->expects($this->once()) - ->method('post') - ->with('https://github.com/login/oauth/access_token') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->requestToken('12345', 'aaa', 'bbb', 'ccc', 'xml'), - $this->equalTo($this->response->body) - ); - } - - /** - * Tests the requestTokenInvalidFormat method - * - * @return void - */ - public function testRequestTokenInvalidFormat() - { - $this->expectException(\UnexpectedValueException::class); - - $this->response->code = 200; - $this->response->body = ''; - - $this->object->requestToken('12345', 'aaa', 'bbb', 'ccc', 'invalid'); - } - - /** - * Tests the revokeGrantForApplication method - * - * @return void - * - * @since 1.0 - */ - public function testRevokeGrantForApplication() - { - $this->response->code = 204; - - $this->client->expects($this->once()) - ->method('delete') - ->with('/applications/42/grants/1a2b3c') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->revokeGrantForApplication(42, '1a2b3c'), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Tests the revokeGrantForApplication method - failure - * - * @return void - * - * @since 1.0 - */ - public function testRevokeGrantForApplicationFailure() - { - $this->expectException(\DomainException::class); - - $this->response->code = 500; - $this->response->body = $this->errorString; - - $this->client->expects($this->once()) - ->method('delete') - ->with('/applications/42/grants/1a2b3c') - ->will($this->returnValue($this->response)); - - $this->object->revokeGrantForApplication(42, '1a2b3c'); - } + /** + * @var Authorization + */ + protected $object; + + /** + * Sets up the fixture, for example, opens a network connection. + * This method is called before a test is executed. + * + * @return void + * + * @since 1.0 + */ + protected function setUp(): void + { + parent::setUp(); + + $this->object = new Authorization($this->options, $this->client); + } + + /** + * Tests the createAuthorisation method + * + * @return void + * + * @since 1.0 + */ + public function testCreate() + { + $this->response->code = 201; + + $authorisation = '{' + . '"scopes":["public_repo"],' + . '"note":"My test app",' + . '"note_url":"http:\/\/www.joomla.org"' + . '}'; + + $this->client->expects($this->once()) + ->method('post') + ->with('/authorizations', $authorisation) + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->create(['public_repo'], 'My test app', 'http://www.joomla.org'), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Tests the createAuthorisation method - simulated failure + * + * @return void + * + * @since 1.0 + */ + public function testCreateFailure() + { + $exception = false; + + $this->response->code = 500; + $this->response->body = $this->errorString; + + $authorisation = '{' + . '"scopes":["public_repo"],' + . '"note":"My test app",' + . '"note_url":"http:\/\/www.joomla.org"' + . '}'; + + $this->client->expects($this->once()) + ->method('post') + ->with('/authorizations', $authorisation) + ->will($this->returnValue($this->response)); + + try { + $this->object->create(['public_repo'], 'My test app', 'http://www.joomla.org'); + } catch (\DomainException $e) { + $exception = true; + + $this->assertThat( + $e->getMessage(), + $this->equalTo(json_decode($this->errorString)->message) + ); + } + + $this->assertTrue($exception); + } + + /** + * Tests the delete method + * + * @return void + * + * @since 1.0 + */ + public function testDelete() + { + $this->response->code = 204; + + $this->client->expects($this->once()) + ->method('delete') + ->with('/authorizations/42') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->delete(42), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Tests the delete method - simulated failure + * + * @return void + * + * @since 1.0 + */ + public function testDeleteFailure() + { + $exception = false; + + $this->response->code = 500; + $this->response->body = $this->errorString; + + $this->client->expects($this->once()) + ->method('delete') + ->with('/authorizations/42') + ->will($this->returnValue($this->response)); + + try { + $this->object->delete(42); + } catch (\DomainException $e) { + $exception = true; + + $this->assertThat( + $e->getMessage(), + $this->equalTo(json_decode($this->errorString)->message) + ); + } + + $this->assertTrue($exception); + } + + /** + * Tests the deleteGrant method + * + * @return void + * + * @since 1.0 + */ + public function testDeleteGrant() + { + $this->response->code = 204; + + $this->client->expects($this->once()) + ->method('delete') + ->with('/authorizations/grants/42') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->deleteGrant(42), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Tests the deleteGrant method - simulated failure + * + * @return void + * + * @since 1.0 + */ + public function testDeleteGrantFailure() + { + $exception = false; + + $this->response->code = 500; + $this->response->body = $this->errorString; + + $this->client->expects($this->once()) + ->method('delete') + ->with('/authorizations/grants/42') + ->will($this->returnValue($this->response)); + + try { + $this->object->deleteGrant(42); + } catch (\DomainException $e) { + $exception = true; + + $this->assertThat( + $e->getMessage(), + $this->equalTo(json_decode($this->errorString)->message) + ); + } + + $this->assertTrue($exception); + } + + /** + * Tests the editAuthorisation method - Add scopes + * + * @return void + * + * @since 1.0 + */ + public function testEditAddScopes() + { + $authorisation = '{' + . '"add_scopes":["public_repo","gist"],' + . '"note":"My test app",' + . '"note_url":"http:\/\/www.joomla.org"' + . '}'; + + $this->client->expects($this->once()) + ->method('patch') + ->with('/authorizations/42', $authorisation) + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->edit(42, [], ['public_repo', 'gist'], [], 'My test app', 'http://www.joomla.org'), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Tests the editAuthorisation method - Remove scopes + * + * @return void + * + * @since 1.0 + */ + public function testEditRemoveScopes() + { + $authorisation = '{' + . '"remove_scopes":["public_repo","gist"],' + . '"note":"My test app",' + . '"note_url":"http:\/\/www.joomla.org"' + . '}'; + + $this->client->expects($this->once()) + ->method('patch') + ->with('/authorizations/42', $authorisation) + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->edit(42, [], [], ['public_repo', 'gist'], 'My test app', 'http://www.joomla.org'), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Tests the editAuthorisation method - Scopes param + * + * @return void + * + * @since 1.0 + */ + public function testEditScopes() + { + $authorisation = '{' + . '"scopes":["public_repo","gist"],' + . '"note":"My test app",' + . '"note_url":"http:\/\/www.joomla.org"' + . '}'; + + $this->client->expects($this->once()) + ->method('patch') + ->with('/authorizations/42', $authorisation) + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->edit(42, ['public_repo', 'gist'], [], [], 'My test app', 'http://www.joomla.org'), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Tests the editAuthorisation method - simulated failure + * + * @return void + * + * @since 1.0 + */ + public function testEditFailure() + { + $exception = false; + + $this->response->code = 500; + $this->response->body = $this->errorString; + + $authorisation = '{' + . '"add_scopes":["public_repo","gist"],' + . '"note":"My test app",' + . '"note_url":"http:\/\/www.joomla.org"' + . '}'; + + $this->client->expects($this->once()) + ->method('patch') + ->with('/authorizations/42', $authorisation) + ->will($this->returnValue($this->response)); + + try { + $this->object->edit(42, [], ['public_repo', 'gist'], [], 'My test app', 'http://www.joomla.org'); + } catch (\DomainException $e) { + $exception = true; + + $this->assertThat( + $e->getMessage(), + $this->equalTo(json_decode($this->errorString)->message) + ); + } + + $this->assertTrue($exception); + } + + /** + * Tests the editAuthorisation method - too many scope params + * + * @return void + * + * @since 1.0 + */ + public function testEditTooManyScopes() + { + $this->expectException(\RuntimeException::class); + + $this->object->edit(42, [], ['public_repo', 'gist'], ['public_repo', 'gist'], 'My test app', 'http://www.joomla.org'); + } + + /** + * Tests the get method + * + * @return void + * + * @since 1.0 + */ + public function testGet() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/authorizations/42') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->get(42), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Tests the get method - failure + * + * @return void + * + * @since 1.0 + */ + public function testGetFailure() + { + $this->expectException(\DomainException::class); + + $this->response->code = 500; + $this->response->body = $this->errorString; + + $this->client->expects($this->once()) + ->method('get') + ->with('/authorizations/42') + ->will($this->returnValue($this->response)); + + $this->object->get(42); + } + + /** + * Tests the getGrant method + * + * @return void + * + * @since 1.0 + */ + public function testGetGrant() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/authorizations/grants/42') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->getGrant(42), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Tests the getGrant method - failure + * + * @return void + * + * @since 1.0 + */ + public function testGetGrantFailure() + { + $this->expectException(\DomainException::class); + + $this->response->code = 500; + $this->response->body = $this->errorString; + + $this->client->expects($this->once()) + ->method('get') + ->with('/authorizations/grants/42') + ->will($this->returnValue($this->response)); + + $this->object->getGrant(42); + } + + /** + * Tests the getList method + * + * @return void + * + * @since 1.0 + */ + public function testGetList() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/authorizations') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->getList(), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Tests the getList method - failure + * + * @return void + * + * @since 1.0 + */ + public function testGetListFailure() + { + $this->expectException(\DomainException::class); + + $this->response->code = 500; + $this->response->body = $this->errorString; + + $this->client->expects($this->once()) + ->method('get') + ->with('/authorizations') + ->will($this->returnValue($this->response)); + + $this->object->getList(); + } + + /** + * Tests the getListGrants method + * + * @return void + * + * @since 1.0 + */ + public function testGetListGrants() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/authorizations/grants') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->getListGrants(), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Tests the getListGrants method - failure + * + * @return void + * + * @since 1.0 + */ + public function testGetListGrantsFailure() + { + $this->expectException(\DomainException::class); + + $this->response->code = 500; + $this->response->body = $this->errorString; + + $this->client->expects($this->once()) + ->method('get') + ->with('/authorizations/grants') + ->will($this->returnValue($this->response)); + + $this->object->getListGrants(); + } + + /** + * Tests the getRateLimit method + * + * @return void + * + * @since 1.0 + */ + public function testGetRateLimit() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/rate_limit') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->getRateLimit(), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Tests the getRateLimit method for an unlimited user. + * + * @return void + * + * @since 1.0 + */ + public function testGetRateLimitUnlimited() + { + $this->response->code = 404; + $this->response->body = ''; + + $this->client->expects($this->once()) + ->method('get') + ->with('/rate_limit') + ->will($this->returnValue($this->response)); + + $this->assertFalse($this->object->getRateLimit()->limit, 'The limit should be false for unlimited'); + } + + /** + * Tests the getRateLimit method - failure + * + * @return void + * + * @since 1.0 + */ + public function testGetRateLimitFailure() + { + $this->expectException(\DomainException::class); + + $this->response->code = 500; + $this->response->body = $this->errorString; + + $this->client->expects($this->once()) + ->method('get') + ->with('/rate_limit') + ->will($this->returnValue($this->response)); + + $this->object->getRateLimit(); + } + + /** + * Tests the getAuthorizationLink method + * + * @return void + */ + 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->assertThat( + $this->object->getAuthorizationLink('12345', 'aaa', 'bbb', 'ccc'), + $this->equalTo($this->response->body) + ); + } + + /** + * Tests the requestToken method + * + * @return void + */ + public function testRequestToken() + { + $this->response->code = 200; + $this->response->body = ''; + + $this->client->expects($this->once()) + ->method('post') + ->with('https://github.com/login/oauth/access_token') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->requestToken('12345', 'aaa', 'bbb', 'ccc'), + $this->equalTo($this->response->body) + ); + } + + /** + * Tests the requestTokenJson method + * + * @return void + */ + public function testRequestTokenJson() + { + $this->response->code = 200; + $this->response->body = ''; + + $this->client->expects($this->once()) + ->method('post') + ->with('https://github.com/login/oauth/access_token') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->requestToken('12345', 'aaa', 'bbb', 'ccc', 'json'), + $this->equalTo($this->response->body) + ); + } + + /** + * Tests the requestTokenXml method + * + * @return void + */ + public function testRequestTokenXml() + { + $this->response->code = 200; + $this->response->body = ''; + + $this->client->expects($this->once()) + ->method('post') + ->with('https://github.com/login/oauth/access_token') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->requestToken('12345', 'aaa', 'bbb', 'ccc', 'xml'), + $this->equalTo($this->response->body) + ); + } + + /** + * Tests the requestTokenInvalidFormat method + * + * @return void + */ + public function testRequestTokenInvalidFormat() + { + $this->expectException(\UnexpectedValueException::class); + + $this->response->code = 200; + $this->response->body = ''; + + $this->object->requestToken('12345', 'aaa', 'bbb', 'ccc', 'invalid'); + } + + /** + * Tests the revokeGrantForApplication method + * + * @return void + * + * @since 1.0 + */ + public function testRevokeGrantForApplication() + { + $this->response->code = 204; + + $this->client->expects($this->once()) + ->method('delete') + ->with('/applications/42/grants/1a2b3c') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->revokeGrantForApplication(42, '1a2b3c'), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Tests the revokeGrantForApplication method - failure + * + * @return void + * + * @since 1.0 + */ + public function testRevokeGrantForApplicationFailure() + { + $this->expectException(\DomainException::class); + + $this->response->code = 500; + $this->response->body = $this->errorString; + + $this->client->expects($this->once()) + ->method('delete') + ->with('/applications/42/grants/1a2b3c') + ->will($this->returnValue($this->response)); + + $this->object->revokeGrantForApplication(42, '1a2b3c'); + } } diff --git a/Tests/Package/Data/BlobsTest.php b/Tests/Package/Data/BlobsTest.php index f84a2330..856fabd5 100644 --- a/Tests/Package/Data/BlobsTest.php +++ b/Tests/Package/Data/BlobsTest.php @@ -1,4 +1,5 @@ object = new Blobs($this->options, $this->client); - } + $this->object = new Blobs($this->options, $this->client); + } - /** - * Tests the get method - * - * @return void - */ - public function testGet() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/repos/joomla/joomla-platform/git/blobs/12345', array(), 0) - ->will($this->returnValue($this->response)); + /** + * Tests the get method + * + * @return void + */ + public function testGet() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/repos/joomla/joomla-platform/git/blobs/12345', [], 0) + ->will($this->returnValue($this->response)); - $this->assertThat( - $this->object->get('joomla', 'joomla-platform', '12345'), - $this->equalTo(json_decode($this->response->body)) - ); - } + $this->assertThat( + $this->object->get('joomla', 'joomla-platform', '12345'), + $this->equalTo(json_decode($this->response->body)) + ); + } - /** - * Tests the create method - * - * @return void - */ - public function testCreate() - { - $this->response->code = 201; + /** + * Tests the create method + * + * @return void + */ + public function testCreate() + { + $this->response->code = 201; - $this->client->expects($this->once()) - ->method('post') - ->with('/repos/joomla/joomla-platform/git/blobs', '{"content":"Hello w\u00f6rld","encoding":"utf-8"}', array(), 0) - ->will($this->returnValue($this->response)); + $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)); - $this->assertThat( - $this->object->create('joomla', 'joomla-platform', 'Hello wörld'), - $this->equalTo(json_decode($this->response->body)) - ); - } + $this->assertThat( + $this->object->create('joomla', 'joomla-platform', 'Hello wörld'), + $this->equalTo(json_decode($this->response->body)) + ); + } } diff --git a/Tests/Package/Data/CommitsTest.php b/Tests/Package/Data/CommitsTest.php index c9f129e0..21b8f959 100644 --- a/Tests/Package/Data/CommitsTest.php +++ b/Tests/Package/Data/CommitsTest.php @@ -1,4 +1,5 @@ object = new Commits($this->options, $this->client); - } + $this->object = new Commits($this->options, $this->client); + } - /** - * Tests the get method - * - * @return void - */ - public function testGet() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/repos/joomla/joomla-platform/git/commits/12345', array(), 0) - ->will($this->returnValue($this->response)); + /** + * Tests the get method + * + * @return void + */ + public function testGet() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/repos/joomla/joomla-platform/git/commits/12345', [], 0) + ->will($this->returnValue($this->response)); - $this->assertThat( - $this->object->get('joomla', 'joomla-platform', '12345'), - $this->equalTo(json_decode($this->response->body)) - ); - } + $this->assertThat( + $this->object->get('joomla', 'joomla-platform', '12345'), + $this->equalTo(json_decode($this->response->body)) + ); + } - /** - * Tests the create method - * - * @return void - */ - public function testCreate() - { - $this->response->code = 201; + /** + * Tests the create method + * + * @return void + */ + public function testCreate() + { + $this->response->code = 201; - $this->client->expects($this->once()) - ->method('post') - ->with('/repos/joomla/joomla-platform/git/commits', '{"message":"My Message","tree":"12345","parents":[]}', array(), 0) - ->will($this->returnValue($this->response)); + $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)); - $this->assertThat( - $this->object->create('joomla', 'joomla-platform', 'My Message', '12345'), - $this->equalTo(json_decode($this->response->body)) - ); - } + $this->assertThat( + $this->object->create('joomla', 'joomla-platform', 'My Message', '12345'), + $this->equalTo(json_decode($this->response->body)) + ); + } } diff --git a/Tests/Package/Data/RefsTest.php b/Tests/Package/Data/RefsTest.php index ce2ba7e9..36af0dc5 100755 --- a/Tests/Package/Data/RefsTest.php +++ b/Tests/Package/Data/RefsTest.php @@ -1,4 +1,5 @@ object = new Refs($this->options, $this->client); - } - - /** - * Tests the get method - * - * @return void - */ - public function testGet() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/repos/joomla/joomla-platform/git/refs/heads/master') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->get('joomla', 'joomla-platform', 'heads/master'), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Tests the get method - * - * @return void - */ - public function testGetFailure() - { - $this->expectException(\DomainException::class); - - $this->response->code = 500; - $this->response->body = $this->errorString; - - $this->client->expects($this->once()) - ->method('get') - ->with('/repos/joomla/joomla-platform/git/refs/heads/master') - ->will($this->returnValue($this->response)); - - $this->object->get('joomla', 'joomla-platform', 'heads/master'); - } - - /** - * Tests the create method - * - * @return void - */ - public function testCreate() - { - $this->response->code = 201; - - // Build the request data. - $data = json_encode( - array( - 'ref' => '/ref/heads/myhead', - 'sha' => 'This is the sha' - ) - ); - - $this->client->expects($this->once()) - ->method('post') - ->with('/repos/joomla/joomla-platform/git/refs', $data) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->create('joomla', 'joomla-platform', '/ref/heads/myhead', 'This is the sha'), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Tests the create method - failure - * - * @return void - */ - public function testCreateFailure() - { - $this->expectException(\DomainException::class); - - $this->response->code = 501; - $this->response->body = $this->errorString; - - // Build the request data. - $data = json_encode( - array( - 'ref' => '/ref/heads/myhead', - 'sha' => 'This is the sha' - ) - ); - - $this->client->expects($this->once()) - ->method('post') - ->with('/repos/joomla/joomla-platform/git/refs', $data) - ->will($this->returnValue($this->response)); - - $this->object->create('joomla', 'joomla-platform', '/ref/heads/myhead', 'This is the sha'); - } - - /** - * Tests the edit method - * - * @return void - */ - public function testEdit() - { - // Build the request data. - $data = json_encode( - array( - 'force' => true, - 'sha' => 'This is the sha' - ) - ); - - $this->client->expects($this->once()) - ->method('patch') - ->with('/repos/joomla/joomla-platform/git/refs/heads/master', $data) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->edit('joomla', 'joomla-platform', 'heads/master', 'This is the sha', true), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Tests the edit method - failure - * - * @return void - */ - public function testEditFailure() - { - $this->expectException(\DomainException::class); - - $this->response->code = 500; - $this->response->body = $this->errorString; - - // Build the request data. - $data = json_encode( - array( - 'sha' => 'This is the sha' - ) - ); - - $this->client->expects($this->once()) - ->method('patch') - ->with('/repos/joomla/joomla-platform/git/refs/heads/master', $data) - ->will($this->returnValue($this->response)); - - $this->object->edit('joomla', 'joomla-platform', 'heads/master', 'This is the sha'); - } - - /** - * Tests the getList method - * - * @return void - */ - public function testGetList() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/repos/joomla/joomla-platform/git/refs') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->getList('joomla', 'joomla-platform'), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Tests the getList method with a namespace - * - * @return void - */ - public function testGetListWithNamespace() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/repos/joomla/joomla-platform/git/refs/tags') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->getList('joomla', 'joomla-platform', 'tags'), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Tests the getList method - failure - * - * @return void - */ - public function testGetListFailure() - { - $this->expectException(\DomainException::class); - - $this->response->code = 500; - $this->response->body = $this->errorString; - - $this->client->expects($this->once()) - ->method('get') - ->with('/repos/joomla/joomla-platform/git/refs') - ->will($this->returnValue($this->response)); - - $this->object->getList('joomla', 'joomla-platform'); - } - - /** - * Tests the delete method - * - * @return void - */ - public function testDelete() - { - $this->response->code = 204; - $this->response->body = ''; - - $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)); - - $this->assertThat( - $this->object->delete('joomla', 'joomla-platform', $ref), - $this->equalTo('') - ); - } - - /** - * Tests the delete method - failure - * - * @return void - */ - public function testDeleteFailure() - { - $this->expectException(\DomainException::class); - - $this->response->code = 500; - $this->response->body = $this->errorString; - - $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)); - - $this->object->delete('joomla', 'joomla-platform', $ref); - } + /** + * @var Refs Object under test. + * @since 1.0 + */ + protected $object; + + /** + * Sets up the fixture, for example, opens a network connection. + * This method is called before a test is executed. + * + * @access protected + * + * @return void + */ + protected function setUp(): void + { + parent::setUp(); + + $this->object = new Refs($this->options, $this->client); + } + + /** + * Tests the get method + * + * @return void + */ + public function testGet() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/repos/joomla/joomla-platform/git/refs/heads/master') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->get('joomla', 'joomla-platform', 'heads/master'), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Tests the get method + * + * @return void + */ + public function testGetFailure() + { + $this->expectException(\DomainException::class); + + $this->response->code = 500; + $this->response->body = $this->errorString; + + $this->client->expects($this->once()) + ->method('get') + ->with('/repos/joomla/joomla-platform/git/refs/heads/master') + ->will($this->returnValue($this->response)); + + $this->object->get('joomla', 'joomla-platform', 'heads/master'); + } + + /** + * Tests the create method + * + * @return void + */ + public function testCreate() + { + $this->response->code = 201; + + // Build the request data. + $data = json_encode( + [ + 'ref' => '/ref/heads/myhead', + 'sha' => 'This is the sha', + ] + ); + + $this->client->expects($this->once()) + ->method('post') + ->with('/repos/joomla/joomla-platform/git/refs', $data) + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->create('joomla', 'joomla-platform', '/ref/heads/myhead', 'This is the sha'), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Tests the create method - failure + * + * @return void + */ + public function testCreateFailure() + { + $this->expectException(\DomainException::class); + + $this->response->code = 501; + $this->response->body = $this->errorString; + + // Build the request data. + $data = json_encode( + [ + 'ref' => '/ref/heads/myhead', + 'sha' => 'This is the sha', + ] + ); + + $this->client->expects($this->once()) + ->method('post') + ->with('/repos/joomla/joomla-platform/git/refs', $data) + ->will($this->returnValue($this->response)); + + $this->object->create('joomla', 'joomla-platform', '/ref/heads/myhead', 'This is the sha'); + } + + /** + * Tests the edit method + * + * @return void + */ + public function testEdit() + { + // Build the request data. + $data = json_encode( + [ + 'force' => true, + 'sha' => 'This is the sha', + ] + ); + + $this->client->expects($this->once()) + ->method('patch') + ->with('/repos/joomla/joomla-platform/git/refs/heads/master', $data) + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->edit('joomla', 'joomla-platform', 'heads/master', 'This is the sha', true), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Tests the edit method - failure + * + * @return void + */ + public function testEditFailure() + { + $this->expectException(\DomainException::class); + + $this->response->code = 500; + $this->response->body = $this->errorString; + + // Build the request data. + $data = json_encode( + [ + 'sha' => 'This is the sha', + ] + ); + + $this->client->expects($this->once()) + ->method('patch') + ->with('/repos/joomla/joomla-platform/git/refs/heads/master', $data) + ->will($this->returnValue($this->response)); + + $this->object->edit('joomla', 'joomla-platform', 'heads/master', 'This is the sha'); + } + + /** + * Tests the getList method + * + * @return void + */ + public function testGetList() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/repos/joomla/joomla-platform/git/refs') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->getList('joomla', 'joomla-platform'), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Tests the getList method with a namespace + * + * @return void + */ + public function testGetListWithNamespace() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/repos/joomla/joomla-platform/git/refs/tags') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->getList('joomla', 'joomla-platform', 'tags'), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Tests the getList method - failure + * + * @return void + */ + public function testGetListFailure() + { + $this->expectException(\DomainException::class); + + $this->response->code = 500; + $this->response->body = $this->errorString; + + $this->client->expects($this->once()) + ->method('get') + ->with('/repos/joomla/joomla-platform/git/refs') + ->will($this->returnValue($this->response)); + + $this->object->getList('joomla', 'joomla-platform'); + } + + /** + * Tests the delete method + * + * @return void + */ + public function testDelete() + { + $this->response->code = 204; + $this->response->body = ''; + + $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)); + + $this->assertThat( + $this->object->delete('joomla', 'joomla-platform', $ref), + $this->equalTo('') + ); + } + + /** + * Tests the delete method - failure + * + * @return void + */ + public function testDeleteFailure() + { + $this->expectException(\DomainException::class); + + $this->response->code = 500; + $this->response->body = $this->errorString; + + $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)); + + $this->object->delete('joomla', 'joomla-platform', $ref); + } } diff --git a/Tests/Package/Data/TagsTest.php b/Tests/Package/Data/TagsTest.php index 02a4dec4..f3861735 100644 --- a/Tests/Package/Data/TagsTest.php +++ b/Tests/Package/Data/TagsTest.php @@ -1,4 +1,5 @@ object = new Tags($this->options, $this->client); - } + $this->object = new Tags($this->options, $this->client); + } - /** - * Tests the get method - * - * @return void - */ - public function testGet() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/repos/joomla/joomla-platform/git/tags/12345', array(), 0) - ->will($this->returnValue($this->response)); + /** + * Tests the get method + * + * @return void + */ + public function testGet() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/repos/joomla/joomla-platform/git/tags/12345', [], 0) + ->will($this->returnValue($this->response)); - $this->assertThat( - $this->object->get('joomla', 'joomla-platform', '12345'), - $this->equalTo(json_decode($this->response->body)) - ); - } + $this->assertThat( + $this->object->get('joomla', 'joomla-platform', '12345'), + $this->equalTo(json_decode($this->response->body)) + ); + } - /** - * Tests the create method - * - * @return void - */ - public function testCreate() - { - $this->response->code = 201; + /** + * Tests the create method + * + * @return void + */ + public function testCreate() + { + $this->response->code = 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, array(), 0) - ->will($this->returnValue($this->response)); + $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)); - $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->assertThat( + $this->object->create('joomla', 'joomla-platform', '0.1', 'Message', '12345', 'commit', 'elkuku', 'email@example.com', '123456789'), + $this->equalTo(json_decode($this->response->body)) + ); + } } diff --git a/Tests/Package/Data/TreesTest.php b/Tests/Package/Data/TreesTest.php index 5f66eac5..f3459cfd 100644 --- a/Tests/Package/Data/TreesTest.php +++ b/Tests/Package/Data/TreesTest.php @@ -1,4 +1,5 @@ object = new Trees($this->options, $this->client); - } + $this->object = new Trees($this->options, $this->client); + } - /** - * Tests the get method - * - * @return void - */ - public function testGet() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/repos/joomla/joomla-platform/git/trees/12345', array(), 0) - ->will($this->returnValue($this->response)); + /** + * Tests the get method + * + * @return void + */ + public function testGet() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/repos/joomla/joomla-platform/git/trees/12345', [], 0) + ->will($this->returnValue($this->response)); - $this->assertThat( - $this->object->get('joomla', 'joomla-platform', '12345'), - $this->equalTo(json_decode($this->response->body)) - ); - } + $this->assertThat( + $this->object->get('joomla', 'joomla-platform', '12345'), + $this->equalTo(json_decode($this->response->body)) + ); + } - /** - * Tests the getRecursively method - * - * @return void - */ - public function testGetRecursively() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/repos/joomla/joomla-platform/git/trees/12345?recursive=1', array(), 0) - ->will($this->returnValue($this->response)); + /** + * Tests the getRecursively method + * + * @return void + */ + 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)); - $this->assertThat( - $this->object->getRecursively('joomla', 'joomla-platform', '12345'), - $this->equalTo(json_decode($this->response->body)) - ); - } + $this->assertThat( + $this->object->getRecursively('joomla', 'joomla-platform', '12345'), + $this->equalTo(json_decode($this->response->body)) + ); + } - /** - * Tests the create method - * - * @return void - */ - public function testCreate() - { - $this->response->code = 201; + /** + * Tests the create method + * + * @return void + */ + public function testCreate() + { + $this->response->code = 201; - $this->client->expects($this->once()) - ->method('post') - ->with('/repos/joomla/joomla-platform/git/trees', '{"tree":"12345","base_tree":"678"}', array(), 0) - ->will($this->returnValue($this->response)); + $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)); - $this->assertThat( - $this->object->create('joomla', 'joomla-platform', '12345', '678'), - $this->equalTo(json_decode($this->response->body)) - ); - } + $this->assertThat( + $this->object->create('joomla', 'joomla-platform', '12345', '678'), + $this->equalTo(json_decode($this->response->body)) + ); + } } diff --git a/Tests/Package/DataTest.php b/Tests/Package/DataTest.php index 5594c18a..95a997dc 100644 --- a/Tests/Package/DataTest.php +++ b/Tests/Package/DataTest.php @@ -1,4 +1,5 @@ object = new Data($this->options, $this->client); - } + $this->object = new Data($this->options, $this->client); + } - /** - * Test method. - * - * @covers \Joomla\Github\Package\Data::__construct() - * - * @return void - * - * @since 1.0 - */ - public function testConstruct() - { - // Dummy to make PHPUnit "happy" - self::assertEquals(true, true); - } + /** + * Test method. + * + * @covers \Joomla\Github\Package\Data::__construct() + * + * @return void + * + * @since 1.0 + */ + public function testConstruct() + { + // Dummy to make PHPUnit "happy" + self::assertEquals(true, true); + } } diff --git a/Tests/Package/EmojisTest.php b/Tests/Package/EmojisTest.php index 59685a55..0ad9dbd7 100755 --- a/Tests/Package/EmojisTest.php +++ b/Tests/Package/EmojisTest.php @@ -1,4 +1,5 @@ object = new Emojis($this->options, $this->client); - } + $this->object = new Emojis($this->options, $this->client); + } - /** - * Tests the getList method - * - * @return void - */ - public function testGetList() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/emojis') - ->will($this->returnValue($this->response)); + /** + * Tests the getList method + * + * @return void + */ + public function testGetList() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/emojis') + ->will($this->returnValue($this->response)); - $this->assertThat( - $this->object->getList(), - $this->equalTo(json_decode($this->sampleString)) - ); - } + $this->assertThat( + $this->object->getList(), + $this->equalTo(json_decode($this->sampleString)) + ); + } - /** - * Tests the getList method - simulated failure - * - * @return void - */ - public function testGetListFailure() - { - $exception = false; + /** + * Tests the getList method - simulated failure + * + * @return void + */ + public function testGetListFailure() + { + $exception = false; - $this->response->code = 500; - $this->response->body = $this->errorString; + $this->response->code = 500; + $this->response->body = $this->errorString; - $this->client->expects($this->once()) - ->method('get') - ->with('/emojis') - ->will($this->returnValue($this->response)); + $this->client->expects($this->once()) + ->method('get') + ->with('/emojis') + ->will($this->returnValue($this->response)); - try - { - $this->object->getList(); - } - catch (\DomainException $e) - { - $exception = true; + try { + $this->object->getList(); + } catch (\DomainException $e) { + $exception = true; - $this->assertThat( - $e->getMessage(), - $this->equalTo(json_decode($this->errorString)->message) - ); - } + $this->assertThat( + $e->getMessage(), + $this->equalTo(json_decode($this->errorString)->message) + ); + } - $this->assertTrue($exception); - } + $this->assertTrue($exception); + } } diff --git a/Tests/Package/GistsTest.php b/Tests/Package/GistsTest.php index dde9503f..26f5454d 100755 --- a/Tests/Package/GistsTest.php +++ b/Tests/Package/GistsTest.php @@ -1,4 +1,5 @@ object = new Gists($this->options, $this->client); - } - - /** - * Tests the create method - * - * @return void - */ - public function testCreate() - { - $this->response->code = 201; - - // Build the request data. - $data = json_encode( - array( - 'files' => array( - 'file2.txt' => array('content' => 'This is the second file') - ), - 'public' => true, - 'description' => 'This is a gist' - ) - ); - - $this->client->expects($this->once()) - ->method('post') - ->with('/gists', $data) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->create( - array( - 'file2.txt' => 'This is the second file' - ), - true, - 'This is a gist' - ), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Tests the create method loading file content from a file - * - * @return void - */ - public function testCreateGistFromFile() - { - $this->response->code = 201; - - // Build the request data. - $data = json_encode( - array( - 'files' => array( - 'gittest' => array('content' => 'GistContent' . PHP_EOL) - ), - 'public' => true, - 'description' => 'This is a gist' - ) - ); - - $this->client->expects($this->once()) - ->method('post') - ->with('/gists', $data) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->create( - array( - __DIR__ . '/../data/gittest' - ), - true, - 'This is a gist' - ), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Tests the create method loading file content from a file - file does not exist - * - * @return void - */ - public function testCreateGistFromFileNotFound() - { - $this->expectException(\InvalidArgumentException::class); - - $this->response->code = 501; - - $this->object->create( - array( - '/file/not/found' - ), - true, - 'This is a gist' - ); - } - - /** - * Tests the create method - * - * @return void - */ - public function testCreateFailure() - { - $exception = false; - - $this->response->code = 500; - $this->response->body = $this->errorString; - - // Build the request data. - $data = json_encode( - array('files' => array(), 'public' => true, 'description' => 'This is a gist') - ); - - $this->client->expects($this->once()) - ->method('post') - ->with('/gists', $data) - ->will($this->returnValue($this->response)); - - try - { - $this->object->create(array(), true, 'This is a gist'); - } - catch (\DomainException $e) - { - $exception = true; - - $this->assertThat( - $e->getMessage(), - $this->equalTo(json_decode($this->errorString)->message) - ); - } - - $this->assertTrue($exception); - } - - /** - * Tests the createComment method - simulated failure - * - * @return void - */ - public function testCreateComment() - { - $this->response->code = 201; - - $gist = new \stdClass; - $gist->body = 'My Insightful Comment'; - - $this->client->expects($this->once()) - ->method('post') - ->with('/gists/523/comments', json_encode($gist)) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->comments->create(523, 'My Insightful Comment'), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Tests the createComment method - simulated failure - * - * @return void - */ - public function testCreateCommentFailure() - { - $exception = false; - - $this->response->code = 500; - $this->response->body = $this->errorString; - - $gist = new \stdClass; - $gist->body = 'My Insightful Comment'; - - $this->client->expects($this->once()) - ->method('post') - ->with('/gists/523/comments', json_encode($gist)) - ->will($this->returnValue($this->response)); - - try - { - $this->object->comments->create(523, 'My Insightful Comment'); - } - catch (\DomainException $e) - { - $exception = true; - - $this->assertThat( - $e->getMessage(), - $this->equalTo(json_decode($this->errorString)->message) - ); - } - - $this->assertTrue($exception); - } - - /** - * Tests the delete method - * - * @return void - */ - public function testDelete() - { - $this->response->code = 204; - - $this->client->expects($this->once()) - ->method('delete') - ->with('/gists/254') - ->will($this->returnValue($this->response)); - - $this->object->delete(254); - } - - /** - * Tests the delete method - simulated failure - * - * @return void - */ - public function testDeleteFailure() - { - $exception = false; - - $this->response->code = 500; - $this->response->body = $this->errorString; - - $this->client->expects($this->once()) - ->method('delete') - ->with('/gists/254') - ->will($this->returnValue($this->response)); - - try - { - $this->object->delete(254); - } - catch (\DomainException $e) - { - $exception = true; - - $this->assertThat( - $e->getMessage(), - $this->equalTo(json_decode($this->errorString)->message) - ); - } - - $this->assertTrue($exception); - } - - /** - * Tests the deleteComment method - * - * @return void - */ - public function testDeleteComment() - { - $this->response->code = 204; - - $this->client->expects($this->once()) - ->method('delete') - ->with('/gists/comments/254') - ->will($this->returnValue($this->response)); - - $this->object->comments->delete(254); - } - - /** - * Tests the deleteComment method - simulated failure - * - * @return void - */ - public function testDeleteCommentFailure() - { - $exception = false; - - $this->response->code = 500; - $this->response->body = $this->errorString; - - $this->client->expects($this->once()) - ->method('delete') - ->with('/gists/comments/254') - ->will($this->returnValue($this->response)); - - try - { - $this->object->comments->delete(254); - } - catch (\DomainException $e) - { - $exception = true; - - $this->assertThat( - $e->getMessage(), - $this->equalTo(json_decode($this->errorString)->message) - ); - } - - $this->assertTrue($exception); - } - - /** - * Tests the edit method - * - * @return void - */ - public function testEdit() - { - // Build the request data. - $data = json_encode( - array( - 'description' => 'This is a gist', - 'public' => true, - 'files' => array( - 'file1.txt' => array('content' => 'This is the first file'), - 'file2.txt' => array('content' => 'This is the second file') - ) - ) - ); - - $this->client->expects($this->once()) - ->method('patch') - ->with('/gists/512', $data) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->edit( - 512, - array( - 'file1.txt' => 'This is the first file', - 'file2.txt' => 'This is the second file' - ), - true, - 'This is a gist' - ), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Tests the edit method - simulated failure - * - * @return void - */ - public function testEditFailure() - { - $exception = false; - - $this->response->code = 500; - $this->response->body = $this->errorString; - - // Build the request data. - $data = json_encode( - array( - 'description' => 'This is a gist', - 'public' => true, - 'files' => array( - 'file1.txt' => array('content' => 'This is the first file'), - 'file2.txt' => array('content' => 'This is the second file') - ) - ) - ); - - $this->client->expects($this->once()) - ->method('patch') - ->with('/gists/512', $data) - ->will($this->returnValue($this->response)); - - try - { - $this->object->edit( - 512, - array( - 'file1.txt' => 'This is the first file', - 'file2.txt' => 'This is the second file' - ), - true, - 'This is a gist' - ); - } - catch (\DomainException $e) - { - $exception = true; - - $this->assertThat( - $e->getMessage(), - $this->equalTo(json_decode($this->errorString)->message) - ); - } - - $this->assertTrue($exception); - } - - /** - * Tests the editComment method - * - * @return void - */ - public function testEditComment() - { - $gist = new \stdClass; - $gist->body = 'This comment is now even more insightful'; - - $this->client->expects($this->once()) - ->method('patch') - ->with('/gists/comments/523', json_encode($gist)) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->comments->edit(523, 'This comment is now even more insightful'), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Tests the editComment method - simulated failure - * - * @return void - */ - public function testEditCommentFailure() - { - $exception = false; - - $this->response->code = 500; - $this->response->body = $this->errorString; - - $gist = new \stdClass; - $gist->body = 'This comment is now even more insightful'; - - $this->client->expects($this->once()) - ->method('patch') - ->with('/gists/comments/523', json_encode($gist)) - ->will($this->returnValue($this->response)); - - try - { - $this->object->comments->edit(523, 'This comment is now even more insightful'); - } - catch (\DomainException $e) - { - $exception = true; - - $this->assertThat( - $e->getMessage(), - $this->equalTo(json_decode($this->errorString)->message) - ); - } - - $this->assertTrue($exception); - } - - /** - * Tests the fork method - * - * @return void - */ - public function testFork() - { - $this->response->code = 201; - - $this->client->expects($this->once()) - ->method('post') - ->with('/gists/523/forks') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->fork(523), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Tests the fork method - simulated failure - * - * @return void - */ - public function testForkFailure() - { - $exception = false; - - $this->response->code = 501; - $this->response->body = $this->errorString; - - $this->client->expects($this->once()) - ->method('post') - ->with('/gists/523/forks') - ->will($this->returnValue($this->response)); - - try - { - $this->object->fork(523); - } - catch (\DomainException $e) - { - $exception = true; - - $this->assertThat( - $e->getMessage(), - $this->equalTo(json_decode($this->errorString)->message) - ); - } - - $this->assertTrue($exception); - } - - /** - * Tests the get method - * - * @return void - */ - public function testGet() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/gists/523') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->get(523), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Tests the get method - simulated failure - * - * @return void - */ - public function testGetFailure() - { - $exception = false; - - $this->response->code = 500; - $this->response->body = $this->errorString; - - $this->client->expects($this->once()) - ->method('get') - ->with('/gists/523') - ->will($this->returnValue($this->response)); - - try - { - $this->object->get(523); - } - catch (\DomainException $e) - { - $exception = true; - - $this->assertThat( - $e->getMessage(), - $this->equalTo(json_decode($this->errorString)->message) - ); - } - - $this->assertTrue($exception); - } - - /** - * Tests the getComment method - * - * @return void - */ - public function testGetComment() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/gists/comments/523') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->comments->get(523), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Tests the getComment method - simulated failure - * - * @return void - */ - public function testGetCommentFailure() - { - $exception = false; - - $this->response->code = 500; - $this->response->body = $this->errorString; - - $this->client->expects($this->once()) - ->method('get') - ->with('/gists/comments/523') - ->will($this->returnValue($this->response)); - - try - { - $this->object->comments->get(523); - } - catch (\DomainException $e) - { - $exception = true; - - $this->assertThat( - $e->getMessage(), - $this->equalTo(json_decode($this->errorString)->message) - ); - } - - $this->assertTrue($exception); - } - - /** - * Tests the getComments method - * - * @return void - */ - public function testGetComments() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/gists/523/comments') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->comments->getList(523), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Tests the getComments method - simulated failure - * - * @return void - */ - public function testGetCommentsFailure() - { - $exception = false; - - $this->response->code = 500; - $this->response->body = $this->errorString; - - $this->client->expects($this->once()) - ->method('get') - ->with('/gists/523/comments') - ->will($this->returnValue($this->response)); - - try - { - $this->object->comments->getList(523); - } - catch (\DomainException $e) - { - $exception = true; - - $this->assertThat( - $e->getMessage(), - $this->equalTo(json_decode($this->errorString)->message) - ); - } - - $this->assertTrue($exception); - } - - /** - * Tests the getCommitList method - * - * @return void - */ - public function testGetCommitList() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/gists/523/commits') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->getCommitList(523), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Tests the getCommitList method - simulated failure - * - * @return void - */ - public function testGetCommitListFailure() - { - $exception = false; - - $this->response->code = 500; - $this->response->body = $this->errorString; - - $this->client->expects($this->once()) - ->method('get') - ->with('/gists/523/commits') - ->will($this->returnValue($this->response)); - - try - { - $this->object->getCommitList(523); - } - catch (\DomainException $e) - { - $exception = true; - - $this->assertThat( - $e->getMessage(), - $this->equalTo(json_decode($this->errorString)->message) - ); - } - - $this->assertTrue($exception); - } - - /** - * Tests the getForkList method - * - * @return void - */ - public function testGetForkList() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/gists/523/forks') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->getForkList(523), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Tests the getForkList method - simulated failure - * - * @return void - */ - public function testGetForkListFailure() - { - $exception = false; - - $this->response->code = 500; - $this->response->body = $this->errorString; - - $this->client->expects($this->once()) - ->method('get') - ->with('/gists/523/forks') - ->will($this->returnValue($this->response)); - - try - { - $this->object->getForkList(523); - } - catch (\DomainException $e) - { - $exception = true; - - $this->assertThat( - $e->getMessage(), - $this->equalTo(json_decode($this->errorString)->message) - ); - } - - $this->assertTrue($exception); - } - - /** - * Tests the getList method - * - * @return void - */ - public function testGetList() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/gists') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->getList(), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Tests the getList method - simulated failure - * - * @return void - */ - public function testGetListFailure() - { - $exception = false; - - $this->response->code = 500; - $this->response->body = $this->errorString; - - $this->client->expects($this->once()) - ->method('get') - ->with('/gists') - ->will($this->returnValue($this->response)); - - try - { - $this->object->getList(); - } - catch (\DomainException $e) - { - $exception = true; - - $this->assertThat( - $e->getMessage(), - $this->equalTo(json_decode($this->errorString)->message) - ); - } - - $this->assertTrue($exception); - } - - /** - * Tests the getListByUser method - * - * @return void - */ - public function testGetListByUser() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/users/joomla/gists') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->getListByUser('joomla'), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Tests the getListByUser method - simulated failure - * - * @return void - */ - public function testGetListByUserFailure() - { - $exception = false; - - $this->response->code = 500; - $this->response->body = $this->errorString; - - $this->client->expects($this->once()) - ->method('get') - ->with('/users/joomla/gists') - ->will($this->returnValue($this->response)); - - try - { - $this->object->getListByUser('joomla'); - } - catch (\DomainException $e) - { - $exception = true; - - $this->assertThat( - $e->getMessage(), - $this->equalTo(json_decode($this->errorString)->message) - ); - } - - $this->assertTrue($exception); - } - - /** - * Tests the getListPublic method - * - * @return void - */ - public function testGetListPublic() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/gists/public') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->getListPublic(), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Tests the getListPublic method - simulated failure - * - * @return void - */ - public function testGetListPublicFailure() - { - $exception = false; - - $this->response->code = 500; - $this->response->body = $this->errorString; - - $this->client->expects($this->once()) - ->method('get') - ->with('/gists/public') - ->will($this->returnValue($this->response)); - - try - { - $this->object->getListPublic(); - } - catch (\DomainException $e) - { - $exception = true; - - $this->assertThat( - $e->getMessage(), - $this->equalTo(json_decode($this->errorString)->message) - ); - } - - $this->assertTrue($exception); - } - - /** - * Tests the getListStarred method - * - * @return void - */ - public function testGetListStarred() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/gists/starred') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->getListStarred(), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Tests the getListStarred method - simulated failure - * - * @return void - */ - public function testGetListStarredFailure() - { - $exception = false; - - $this->response->code = 500; - $this->response->body = $this->errorString; - - $this->client->expects($this->once()) - ->method('get') - ->with('/gists/starred') - ->will($this->returnValue($this->response)); - - try - { - $this->object->getListStarred(); - } - catch (\DomainException $e) - { - $exception = true; - - $this->assertThat( - $e->getMessage(), - $this->equalTo(json_decode($this->errorString)->message) - ); - } - - $this->assertTrue($exception); - } - - /** - * Tests the getRevision method - * - * @return void - */ - public function testGetRevision() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/gists/523/a1b2c3') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->getRevision(523, 'a1b2c3'), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Tests the getRevision method - simulated failure - * - * @return void - */ - public function testGetRevisionFailure() - { - $exception = false; - - $this->response->code = 500; - $this->response->body = $this->errorString; - - $this->client->expects($this->once()) - ->method('get') - ->with('/gists/523/a1b2c3') - ->will($this->returnValue($this->response)); - - try - { - $this->object->getRevision(523, 'a1b2c3'); - } - catch (\DomainException $e) - { - $exception = true; - - $this->assertThat( - $e->getMessage(), - $this->equalTo(json_decode($this->errorString)->message) - ); - } - - $this->assertTrue($exception); - } - - /** - * Tests the isStarred method when the gist has been starred - * - * @return void - */ - public function testIsStarredTrue() - { - $this->response->code = 204; - - $this->client->expects($this->once()) - ->method('get') - ->with('/gists/523/star') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->isStarred(523), - $this->equalTo(true) - ); - } - - /** - * Tests the isStarred method when the gist has not been starred - * - * @return void - */ - public function testIsStarredFalse() - { - $this->response->code = 404; - - $this->client->expects($this->once()) - ->method('get') - ->with('/gists/523/star') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->isStarred(523), - $this->equalTo(false) - ); - } - - /** - * Tests the isStarred method expecting a failure response - * - * @return void - */ - public function testIsStarredFailure() - { - $exception = false; - - $this->response->code = 500; - $this->response->body = $this->errorString; - - $this->client->expects($this->once()) - ->method('get') - ->with('/gists/523/star') - ->will($this->returnValue($this->response)); - - try - { - $this->object->isStarred(523); - } - catch (\DomainException $e) - { - $exception = true; - - $this->assertThat( - $e->getMessage(), - $this->equalTo(json_decode($this->errorString)->message) - ); - } - - $this->assertTrue($exception); - } - - /** - * Tests the star method - * - * @return void - */ - public function testStar() - { - $this->response->code = 204; - - $this->client->expects($this->once()) - ->method('put') - ->with('/gists/523/star', '') - ->will($this->returnValue($this->response)); - - $this->object->star(523); - } - - /** - * Tests the star method - simulated failure - * - * @return void - */ - public function testStarFailure() - { - $exception = false; - - $this->response->code = 504; - $this->response->body = $this->errorString; - - $this->client->expects($this->once()) - ->method('put') - ->with('/gists/523/star', '') - ->will($this->returnValue($this->response)); - - try - { - $this->object->star(523); - } - catch (\DomainException $e) - { - $exception = true; - - $this->assertThat( - $e->getMessage(), - $this->equalTo(json_decode($this->errorString)->message) - ); - } - - $this->assertTrue($exception); - } - - /** - * Tests the unstar method - * - * @return void - */ - public function testUnstar() - { - $this->response->code = 204; - - $this->client->expects($this->once()) - ->method('delete') - ->with('/gists/523/star') - ->will($this->returnValue($this->response)); - - $this->object->unstar(523); - } - - /** - * Tests the unstar method - simulated failure - * - * @return void - */ - public function testUnstarFailure() - { - $exception = false; - - $this->response->code = 504; - $this->response->body = $this->errorString; - - $this->client->expects($this->once()) - ->method('delete') - ->with('/gists/523/star') - ->will($this->returnValue($this->response)); - - try - { - $this->object->unstar(523); - } - catch (\DomainException $e) - { - $exception = true; - - $this->assertThat( - $e->getMessage(), - $this->equalTo(json_decode($this->errorString)->message) - ); - } - - $this->assertTrue($exception); - } + /** + * @var Gists + */ + protected $object; + + /** + * Sets up the fixture, for example, opens a network connection. + * This method is called before a test is executed. + * + * @access protected + * + * @return void + */ + protected function setUp(): void + { + parent::setUp(); + + $this->object = new Gists($this->options, $this->client); + } + + /** + * Tests the create method + * + * @return void + */ + public function testCreate() + { + $this->response->code = 201; + + // Build the request data. + $data = json_encode( + [ + 'files' => [ + 'file2.txt' => ['content' => 'This is the second file'], + ], + 'public' => true, + 'description' => 'This is a gist', + ] + ); + + $this->client->expects($this->once()) + ->method('post') + ->with('/gists', $data) + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->create( + [ + 'file2.txt' => 'This is the second file', + ], + true, + 'This is a gist' + ), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Tests the create method loading file content from a file + * + * @return void + */ + public function testCreateGistFromFile() + { + $this->response->code = 201; + + // Build the request data. + $data = json_encode( + [ + 'files' => [ + 'gittest' => ['content' => 'GistContent' . PHP_EOL], + ], + 'public' => true, + 'description' => 'This is a gist', + ] + ); + + $this->client->expects($this->once()) + ->method('post') + ->with('/gists', $data) + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->create( + [ + __DIR__ . '/../data/gittest', + ], + true, + 'This is a gist' + ), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Tests the create method loading file content from a file - file does not exist + * + * @return void + */ + public function testCreateGistFromFileNotFound() + { + $this->expectException(\InvalidArgumentException::class); + + $this->response->code = 501; + + $this->object->create( + [ + '/file/not/found', + ], + true, + 'This is a gist' + ); + } + + /** + * Tests the create method + * + * @return void + */ + public function testCreateFailure() + { + $exception = false; + + $this->response->code = 500; + $this->response->body = $this->errorString; + + // Build the request data. + $data = json_encode( + ['files' => [], 'public' => true, 'description' => 'This is a gist'] + ); + + $this->client->expects($this->once()) + ->method('post') + ->with('/gists', $data) + ->will($this->returnValue($this->response)); + + try { + $this->object->create([], true, 'This is a gist'); + } catch (\DomainException $e) { + $exception = true; + + $this->assertThat( + $e->getMessage(), + $this->equalTo(json_decode($this->errorString)->message) + ); + } + + $this->assertTrue($exception); + } + + /** + * Tests the createComment method - simulated failure + * + * @return void + */ + public function testCreateComment() + { + $this->response->code = 201; + + $gist = new \stdClass(); + $gist->body = 'My Insightful Comment'; + + $this->client->expects($this->once()) + ->method('post') + ->with('/gists/523/comments', json_encode($gist)) + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->comments->create(523, 'My Insightful Comment'), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Tests the createComment method - simulated failure + * + * @return void + */ + public function testCreateCommentFailure() + { + $exception = false; + + $this->response->code = 500; + $this->response->body = $this->errorString; + + $gist = new \stdClass(); + $gist->body = 'My Insightful Comment'; + + $this->client->expects($this->once()) + ->method('post') + ->with('/gists/523/comments', json_encode($gist)) + ->will($this->returnValue($this->response)); + + try { + $this->object->comments->create(523, 'My Insightful Comment'); + } catch (\DomainException $e) { + $exception = true; + + $this->assertThat( + $e->getMessage(), + $this->equalTo(json_decode($this->errorString)->message) + ); + } + + $this->assertTrue($exception); + } + + /** + * Tests the delete method + * + * @return void + */ + public function testDelete() + { + $this->response->code = 204; + + $this->client->expects($this->once()) + ->method('delete') + ->with('/gists/254') + ->will($this->returnValue($this->response)); + + $this->object->delete(254); + } + + /** + * Tests the delete method - simulated failure + * + * @return void + */ + public function testDeleteFailure() + { + $exception = false; + + $this->response->code = 500; + $this->response->body = $this->errorString; + + $this->client->expects($this->once()) + ->method('delete') + ->with('/gists/254') + ->will($this->returnValue($this->response)); + + try { + $this->object->delete(254); + } catch (\DomainException $e) { + $exception = true; + + $this->assertThat( + $e->getMessage(), + $this->equalTo(json_decode($this->errorString)->message) + ); + } + + $this->assertTrue($exception); + } + + /** + * Tests the deleteComment method + * + * @return void + */ + public function testDeleteComment() + { + $this->response->code = 204; + + $this->client->expects($this->once()) + ->method('delete') + ->with('/gists/comments/254') + ->will($this->returnValue($this->response)); + + $this->object->comments->delete(254); + } + + /** + * Tests the deleteComment method - simulated failure + * + * @return void + */ + public function testDeleteCommentFailure() + { + $exception = false; + + $this->response->code = 500; + $this->response->body = $this->errorString; + + $this->client->expects($this->once()) + ->method('delete') + ->with('/gists/comments/254') + ->will($this->returnValue($this->response)); + + try { + $this->object->comments->delete(254); + } catch (\DomainException $e) { + $exception = true; + + $this->assertThat( + $e->getMessage(), + $this->equalTo(json_decode($this->errorString)->message) + ); + } + + $this->assertTrue($exception); + } + + /** + * Tests the edit method + * + * @return void + */ + public function testEdit() + { + // Build the request data. + $data = json_encode( + [ + 'description' => 'This is a gist', + 'public' => true, + 'files' => [ + 'file1.txt' => ['content' => 'This is the first file'], + 'file2.txt' => ['content' => 'This is the second file'], + ], + ] + ); + + $this->client->expects($this->once()) + ->method('patch') + ->with('/gists/512', $data) + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->edit( + 512, + [ + 'file1.txt' => 'This is the first file', + 'file2.txt' => 'This is the second file', + ], + true, + 'This is a gist' + ), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Tests the edit method - simulated failure + * + * @return void + */ + public function testEditFailure() + { + $exception = false; + + $this->response->code = 500; + $this->response->body = $this->errorString; + + // Build the request data. + $data = json_encode( + [ + 'description' => 'This is a gist', + 'public' => true, + 'files' => [ + 'file1.txt' => ['content' => 'This is the first file'], + 'file2.txt' => ['content' => 'This is the second file'], + ], + ] + ); + + $this->client->expects($this->once()) + ->method('patch') + ->with('/gists/512', $data) + ->will($this->returnValue($this->response)); + + try { + $this->object->edit( + 512, + [ + 'file1.txt' => 'This is the first file', + 'file2.txt' => 'This is the second file', + ], + true, + 'This is a gist' + ); + } catch (\DomainException $e) { + $exception = true; + + $this->assertThat( + $e->getMessage(), + $this->equalTo(json_decode($this->errorString)->message) + ); + } + + $this->assertTrue($exception); + } + + /** + * Tests the editComment method + * + * @return void + */ + public function testEditComment() + { + $gist = new \stdClass(); + $gist->body = 'This comment is now even more insightful'; + + $this->client->expects($this->once()) + ->method('patch') + ->with('/gists/comments/523', json_encode($gist)) + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->comments->edit(523, 'This comment is now even more insightful'), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Tests the editComment method - simulated failure + * + * @return void + */ + public function testEditCommentFailure() + { + $exception = false; + + $this->response->code = 500; + $this->response->body = $this->errorString; + + $gist = new \stdClass(); + $gist->body = 'This comment is now even more insightful'; + + $this->client->expects($this->once()) + ->method('patch') + ->with('/gists/comments/523', json_encode($gist)) + ->will($this->returnValue($this->response)); + + try { + $this->object->comments->edit(523, 'This comment is now even more insightful'); + } catch (\DomainException $e) { + $exception = true; + + $this->assertThat( + $e->getMessage(), + $this->equalTo(json_decode($this->errorString)->message) + ); + } + + $this->assertTrue($exception); + } + + /** + * Tests the fork method + * + * @return void + */ + public function testFork() + { + $this->response->code = 201; + + $this->client->expects($this->once()) + ->method('post') + ->with('/gists/523/forks') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->fork(523), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Tests the fork method - simulated failure + * + * @return void + */ + public function testForkFailure() + { + $exception = false; + + $this->response->code = 501; + $this->response->body = $this->errorString; + + $this->client->expects($this->once()) + ->method('post') + ->with('/gists/523/forks') + ->will($this->returnValue($this->response)); + + try { + $this->object->fork(523); + } catch (\DomainException $e) { + $exception = true; + + $this->assertThat( + $e->getMessage(), + $this->equalTo(json_decode($this->errorString)->message) + ); + } + + $this->assertTrue($exception); + } + + /** + * Tests the get method + * + * @return void + */ + public function testGet() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/gists/523') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->get(523), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Tests the get method - simulated failure + * + * @return void + */ + public function testGetFailure() + { + $exception = false; + + $this->response->code = 500; + $this->response->body = $this->errorString; + + $this->client->expects($this->once()) + ->method('get') + ->with('/gists/523') + ->will($this->returnValue($this->response)); + + try { + $this->object->get(523); + } catch (\DomainException $e) { + $exception = true; + + $this->assertThat( + $e->getMessage(), + $this->equalTo(json_decode($this->errorString)->message) + ); + } + + $this->assertTrue($exception); + } + + /** + * Tests the getComment method + * + * @return void + */ + public function testGetComment() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/gists/comments/523') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->comments->get(523), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Tests the getComment method - simulated failure + * + * @return void + */ + public function testGetCommentFailure() + { + $exception = false; + + $this->response->code = 500; + $this->response->body = $this->errorString; + + $this->client->expects($this->once()) + ->method('get') + ->with('/gists/comments/523') + ->will($this->returnValue($this->response)); + + try { + $this->object->comments->get(523); + } catch (\DomainException $e) { + $exception = true; + + $this->assertThat( + $e->getMessage(), + $this->equalTo(json_decode($this->errorString)->message) + ); + } + + $this->assertTrue($exception); + } + + /** + * Tests the getComments method + * + * @return void + */ + public function testGetComments() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/gists/523/comments') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->comments->getList(523), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Tests the getComments method - simulated failure + * + * @return void + */ + public function testGetCommentsFailure() + { + $exception = false; + + $this->response->code = 500; + $this->response->body = $this->errorString; + + $this->client->expects($this->once()) + ->method('get') + ->with('/gists/523/comments') + ->will($this->returnValue($this->response)); + + try { + $this->object->comments->getList(523); + } catch (\DomainException $e) { + $exception = true; + + $this->assertThat( + $e->getMessage(), + $this->equalTo(json_decode($this->errorString)->message) + ); + } + + $this->assertTrue($exception); + } + + /** + * Tests the getCommitList method + * + * @return void + */ + public function testGetCommitList() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/gists/523/commits') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->getCommitList(523), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Tests the getCommitList method - simulated failure + * + * @return void + */ + public function testGetCommitListFailure() + { + $exception = false; + + $this->response->code = 500; + $this->response->body = $this->errorString; + + $this->client->expects($this->once()) + ->method('get') + ->with('/gists/523/commits') + ->will($this->returnValue($this->response)); + + try { + $this->object->getCommitList(523); + } catch (\DomainException $e) { + $exception = true; + + $this->assertThat( + $e->getMessage(), + $this->equalTo(json_decode($this->errorString)->message) + ); + } + + $this->assertTrue($exception); + } + + /** + * Tests the getForkList method + * + * @return void + */ + public function testGetForkList() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/gists/523/forks') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->getForkList(523), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Tests the getForkList method - simulated failure + * + * @return void + */ + public function testGetForkListFailure() + { + $exception = false; + + $this->response->code = 500; + $this->response->body = $this->errorString; + + $this->client->expects($this->once()) + ->method('get') + ->with('/gists/523/forks') + ->will($this->returnValue($this->response)); + + try { + $this->object->getForkList(523); + } catch (\DomainException $e) { + $exception = true; + + $this->assertThat( + $e->getMessage(), + $this->equalTo(json_decode($this->errorString)->message) + ); + } + + $this->assertTrue($exception); + } + + /** + * Tests the getList method + * + * @return void + */ + public function testGetList() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/gists') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->getList(), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Tests the getList method - simulated failure + * + * @return void + */ + public function testGetListFailure() + { + $exception = false; + + $this->response->code = 500; + $this->response->body = $this->errorString; + + $this->client->expects($this->once()) + ->method('get') + ->with('/gists') + ->will($this->returnValue($this->response)); + + try { + $this->object->getList(); + } catch (\DomainException $e) { + $exception = true; + + $this->assertThat( + $e->getMessage(), + $this->equalTo(json_decode($this->errorString)->message) + ); + } + + $this->assertTrue($exception); + } + + /** + * Tests the getListByUser method + * + * @return void + */ + public function testGetListByUser() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/users/joomla/gists') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->getListByUser('joomla'), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Tests the getListByUser method - simulated failure + * + * @return void + */ + public function testGetListByUserFailure() + { + $exception = false; + + $this->response->code = 500; + $this->response->body = $this->errorString; + + $this->client->expects($this->once()) + ->method('get') + ->with('/users/joomla/gists') + ->will($this->returnValue($this->response)); + + try { + $this->object->getListByUser('joomla'); + } catch (\DomainException $e) { + $exception = true; + + $this->assertThat( + $e->getMessage(), + $this->equalTo(json_decode($this->errorString)->message) + ); + } + + $this->assertTrue($exception); + } + + /** + * Tests the getListPublic method + * + * @return void + */ + public function testGetListPublic() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/gists/public') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->getListPublic(), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Tests the getListPublic method - simulated failure + * + * @return void + */ + public function testGetListPublicFailure() + { + $exception = false; + + $this->response->code = 500; + $this->response->body = $this->errorString; + + $this->client->expects($this->once()) + ->method('get') + ->with('/gists/public') + ->will($this->returnValue($this->response)); + + try { + $this->object->getListPublic(); + } catch (\DomainException $e) { + $exception = true; + + $this->assertThat( + $e->getMessage(), + $this->equalTo(json_decode($this->errorString)->message) + ); + } + + $this->assertTrue($exception); + } + + /** + * Tests the getListStarred method + * + * @return void + */ + public function testGetListStarred() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/gists/starred') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->getListStarred(), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Tests the getListStarred method - simulated failure + * + * @return void + */ + public function testGetListStarredFailure() + { + $exception = false; + + $this->response->code = 500; + $this->response->body = $this->errorString; + + $this->client->expects($this->once()) + ->method('get') + ->with('/gists/starred') + ->will($this->returnValue($this->response)); + + try { + $this->object->getListStarred(); + } catch (\DomainException $e) { + $exception = true; + + $this->assertThat( + $e->getMessage(), + $this->equalTo(json_decode($this->errorString)->message) + ); + } + + $this->assertTrue($exception); + } + + /** + * Tests the getRevision method + * + * @return void + */ + public function testGetRevision() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/gists/523/a1b2c3') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->getRevision(523, 'a1b2c3'), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Tests the getRevision method - simulated failure + * + * @return void + */ + public function testGetRevisionFailure() + { + $exception = false; + + $this->response->code = 500; + $this->response->body = $this->errorString; + + $this->client->expects($this->once()) + ->method('get') + ->with('/gists/523/a1b2c3') + ->will($this->returnValue($this->response)); + + try { + $this->object->getRevision(523, 'a1b2c3'); + } catch (\DomainException $e) { + $exception = true; + + $this->assertThat( + $e->getMessage(), + $this->equalTo(json_decode($this->errorString)->message) + ); + } + + $this->assertTrue($exception); + } + + /** + * Tests the isStarred method when the gist has been starred + * + * @return void + */ + public function testIsStarredTrue() + { + $this->response->code = 204; + + $this->client->expects($this->once()) + ->method('get') + ->with('/gists/523/star') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->isStarred(523), + $this->equalTo(true) + ); + } + + /** + * Tests the isStarred method when the gist has not been starred + * + * @return void + */ + public function testIsStarredFalse() + { + $this->response->code = 404; + + $this->client->expects($this->once()) + ->method('get') + ->with('/gists/523/star') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->isStarred(523), + $this->equalTo(false) + ); + } + + /** + * Tests the isStarred method expecting a failure response + * + * @return void + */ + public function testIsStarredFailure() + { + $exception = false; + + $this->response->code = 500; + $this->response->body = $this->errorString; + + $this->client->expects($this->once()) + ->method('get') + ->with('/gists/523/star') + ->will($this->returnValue($this->response)); + + try { + $this->object->isStarred(523); + } catch (\DomainException $e) { + $exception = true; + + $this->assertThat( + $e->getMessage(), + $this->equalTo(json_decode($this->errorString)->message) + ); + } + + $this->assertTrue($exception); + } + + /** + * Tests the star method + * + * @return void + */ + public function testStar() + { + $this->response->code = 204; + + $this->client->expects($this->once()) + ->method('put') + ->with('/gists/523/star', '') + ->will($this->returnValue($this->response)); + + $this->object->star(523); + } + + /** + * Tests the star method - simulated failure + * + * @return void + */ + public function testStarFailure() + { + $exception = false; + + $this->response->code = 504; + $this->response->body = $this->errorString; + + $this->client->expects($this->once()) + ->method('put') + ->with('/gists/523/star', '') + ->will($this->returnValue($this->response)); + + try { + $this->object->star(523); + } catch (\DomainException $e) { + $exception = true; + + $this->assertThat( + $e->getMessage(), + $this->equalTo(json_decode($this->errorString)->message) + ); + } + + $this->assertTrue($exception); + } + + /** + * Tests the unstar method + * + * @return void + */ + public function testUnstar() + { + $this->response->code = 204; + + $this->client->expects($this->once()) + ->method('delete') + ->with('/gists/523/star') + ->will($this->returnValue($this->response)); + + $this->object->unstar(523); + } + + /** + * Tests the unstar method - simulated failure + * + * @return void + */ + public function testUnstarFailure() + { + $exception = false; + + $this->response->code = 504; + $this->response->body = $this->errorString; + + $this->client->expects($this->once()) + ->method('delete') + ->with('/gists/523/star') + ->will($this->returnValue($this->response)); + + try { + $this->object->unstar(523); + } catch (\DomainException $e) { + $exception = true; + + $this->assertThat( + $e->getMessage(), + $this->equalTo(json_decode($this->errorString)->message) + ); + } + + $this->assertTrue($exception); + } } diff --git a/Tests/Package/GitignoreTest.php b/Tests/Package/GitignoreTest.php index 536523eb..8a9de29d 100644 --- a/Tests/Package/GitignoreTest.php +++ b/Tests/Package/GitignoreTest.php @@ -1,4 +1,5 @@ object = new Gitignore($this->options, $this->client); - } - - /** - * Tests the getList method. - * - * @return void - * - * @since 1.0 - */ - public function testGetList() - { - $this->response->code = 200; - $this->response->body = '[ + /** + * @var Gitignore + */ + protected $object; + + /** + * Sets up the fixture, for example, opens a network connection. + * This method is called before a test is executed. + * + * @since 1.0 + * + * @return void + */ + protected function setUp(): void + { + parent::setUp(); + + $this->object = new Gitignore($this->options, $this->client); + } + + /** + * Tests the getList method. + * + * @return void + * + * @since 1.0 + */ + public function testGetList() + { + $this->response->code = 200; + $this->response->body = '[ "Actionscript", "Android", "AppceleratorTitanium", @@ -56,55 +57,55 @@ public function testGetList() "C++" ]'; - $this->client->expects($this->once()) - ->method('get') - ->with('/gitignore/templates', array(), 0) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->getList(), - $this->equalTo(json_decode($this->response->body)) - ); - } - - /** - * Tests the get method. - * - * @return void - * - * @since 1.0 - */ - public function testGet() - { - $this->response->code = 200; - $this->response->body = '{ + $this->client->expects($this->once()) + ->method('get') + ->with('/gitignore/templates', [], 0) + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->getList(), + $this->equalTo(json_decode($this->response->body)) + ); + } + + /** + * Tests the get method. + * + * @return void + * + * @since 1.0 + */ + public function testGet() + { + $this->response->code = 200; + $this->response->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" + . '*.dll\n*.so\n*.so.*\n*.dylib\n\n# Executables\n*.exe\n*.out\n*.app\n" }'; - $this->client->expects($this->once()) - ->method('get') - ->with('/gitignore/templates/C', array(), 0) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->get('C'), - $this->equalTo(json_decode($this->response->body)) - ); - } - - /** - * Tests the get method with raw return data. - * - * @return void - * - * @since 1.0 - */ - public function testGetRaw() - { - $this->response->code = 200; - $this->response->body = '# Object files + $this->client->expects($this->once()) + ->method('get') + ->with('/gitignore/templates/C', [], 0) + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->get('C'), + $this->equalTo(json_decode($this->response->body)) + ); + } + + /** + * Tests the get method with raw return data. + * + * @return void + * + * @since 1.0 + */ + public function testGetRaw() + { + $this->response->code = 200; + $this->response->body = '# Object files *.o # Libraries @@ -123,38 +124,38 @@ public function testGetRaw() *.app '; - $this->client->expects($this->once()) - ->method('get') - ->with('/gitignore/templates/C', array('Accept' => 'application/vnd.github.raw+json'), 0) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->get('C', true), - $this->equalTo($this->response->body) - ); - } - - /** - * Tests the get method with failure. - * - * @since 1.0 - * @return void - */ - public function testGetFailure() - { - $this->expectException(\DomainException::class); - - $this->response->code = 404; - $this->response->body = '{"message":"Not found"}'; - - $this->client->expects($this->once()) - ->method('get') - ->with('/gitignore/templates/X', array(), 0) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->get('X'), - $this->equalTo(json_decode($this->response->body)) - ); - } + $this->client->expects($this->once()) + ->method('get') + ->with('/gitignore/templates/C', ['Accept' => 'application/vnd.github.raw+json'], 0) + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->get('C', true), + $this->equalTo($this->response->body) + ); + } + + /** + * Tests the get method with failure. + * + * @since 1.0 + * @return void + */ + public function testGetFailure() + { + $this->expectException(\DomainException::class); + + $this->response->code = 404; + $this->response->body = '{"message":"Not found"}'; + + $this->client->expects($this->once()) + ->method('get') + ->with('/gitignore/templates/X', [], 0) + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->get('X'), + $this->equalTo(json_decode($this->response->body)) + ); + } } diff --git a/Tests/Package/GraphqlTest.php b/Tests/Package/GraphqlTest.php index d36e017a..6538debb 100644 --- a/Tests/Package/GraphqlTest.php +++ b/Tests/Package/GraphqlTest.php @@ -1,4 +1,5 @@ object = new Graphql($this->options, $this->client); - } - - /** - * Tests the create method - * - * @return void - */ - public function testCreate() - { - $this->response->code = 200; - $this->response->body = $this->sampleString; - - // Build the query. - $query = 'foo'; - - // Build the request data. - $data = array( - 'query' => $query, - ); - - // Build the headers. - $headers = array( - 'Accept' => 'application/vnd.github.v4+json', - 'Content-Type' => 'application/json', - ); - - $this->client->expects($this->once()) - ->method('post') - ->with('/graphql', json_encode($data), $headers) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->execute($query), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Tests the create method - * - * @return void - */ - public function testCreateFailure() - { - $exception = false; - - $this->response->code = 500; - $this->response->body = $this->errorString; - - // Build the query. - $query = 'foo'; - - // Build the request data. - $data = array( - 'query' => $query, - ); - - // Build the headers. - $headers = array( - 'Accept' => 'application/vnd.github.v4+json', - 'Content-Type' => 'application/json', - ); - - $this->client->expects($this->once()) - ->method('post') - ->with('/graphql', json_encode($data), $headers) - ->will($this->returnValue($this->response)); - - try - { - $this->object->execute($query); - $this->fail('Exception not thrown'); - } - catch (\DomainException $e) - { - $this->assertThat( - $e->getMessage(), - $this->equalTo(json_decode($this->errorString)->message) - ); - } - } + /** + * @var Graphql + */ + protected $object; + + /** + * Sets up the fixture, for example, opens a network connection. + * This method is called before a test is executed. + * + * @access protected + * + * @return void + */ + protected function setUp(): void + { + parent::setUp(); + + $this->object = new Graphql($this->options, $this->client); + } + + /** + * Tests the create method + * + * @return void + */ + public function testCreate() + { + $this->response->code = 200; + $this->response->body = $this->sampleString; + + // Build the query. + $query = 'foo'; + + // Build the request data. + $data = [ + 'query' => $query, + ]; + + // Build the headers. + $headers = [ + 'Accept' => 'application/vnd.github.v4+json', + 'Content-Type' => 'application/json', + ]; + + $this->client->expects($this->once()) + ->method('post') + ->with('/graphql', json_encode($data), $headers) + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->execute($query), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Tests the create method + * + * @return void + */ + public function testCreateFailure() + { + $exception = false; + + $this->response->code = 500; + $this->response->body = $this->errorString; + + // Build the query. + $query = 'foo'; + + // Build the request data. + $data = [ + 'query' => $query, + ]; + + // Build the headers. + $headers = [ + 'Accept' => 'application/vnd.github.v4+json', + 'Content-Type' => 'application/json', + ]; + + $this->client->expects($this->once()) + ->method('post') + ->with('/graphql', json_encode($data), $headers) + ->will($this->returnValue($this->response)); + + try { + $this->object->execute($query); + $this->fail('Exception not thrown'); + } catch (\DomainException $e) { + $this->assertThat( + $e->getMessage(), + $this->equalTo(json_decode($this->errorString)->message) + ); + } + } } diff --git a/Tests/Package/Issues/AssigneesTest.php b/Tests/Package/Issues/AssigneesTest.php index b17450b1..6ce15ec9 100644 --- a/Tests/Package/Issues/AssigneesTest.php +++ b/Tests/Package/Issues/AssigneesTest.php @@ -1,4 +1,5 @@ object = new Assignees($this->options, $this->client); - } - - /** - * Tests the getList method - * - * @return void - */ - public function testGetList() - { - $this->response->code = 200; - $this->response->body = '[ + /** + * @var Assignees Object under test. + * @since 1.0 + */ + protected $object; + + /** + * @var string + * @since 1.0 + */ + protected $owner = 'joomla'; + + /** + * @var string + * @since 1.0 + */ + protected $repo = 'joomla-framework'; + + /** + * Sets up the fixture, for example, opens a network connection. + * This method is called before a test is executed. + * + * @since 1.0 + * + * @return void + */ + protected function setUp(): void + { + parent::setUp(); + + $this->object = new Assignees($this->options, $this->client); + } + + /** + * Tests the getList method + * + * @return void + */ + public function testGetList() + { + $this->response->code = 200; + $this->response->body = '[ { "login": "octocat", "id": 1, @@ -67,109 +68,109 @@ public function testGetList() } ]'; - $this->client->expects($this->once()) - ->method('get') - ->with('/repos/' . $this->owner . '/' . $this->repo . '/assignees', array(), 0) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->getList($this->owner, $this->repo), - $this->equalTo(json_decode($this->response->body)) - ); - } - - /** - * Tests the getList method - * Response: - * If the given assignee login belongs to an assignee for the repository, - * a 204 header with no content is returned. - * Otherwise a 404 status code is returned. - * - * @return void - */ - public function testCheck() - { - $this->response->code = 204; - $this->response->body = ''; - - $assignee = 'elkuku'; - - $this->client->expects($this->once()) - ->method('get') - ->with('/repos/' . $this->owner . '/' . $this->repo . '/assignees/' . $assignee, array(), 0) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->check($this->owner, $this->repo, $assignee), - $this->equalTo(true) - ); - } - - /** - * Tests the getList method with a negative response - * Response: - * If the given assignee login belongs to an assignee for the repository, - * a 204 header with no content is returned. - * Otherwise a 404 status code is returned. - * - * @return void - */ - public function testCheckNo() - { - $this->response->code = 404; - $this->response->body = ''; - - $assignee = 'elkuku'; - - $this->client->expects($this->once()) - ->method('get') - ->with('/repos/' . $this->owner . '/' . $this->repo . '/assignees/' . $assignee, array(), 0) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->check($this->owner, $this->repo, $assignee), - $this->equalTo(false) - ); - } - - /** - * Tests the getList method with a negative response - * Response: - * If the given assignee login belongs to an assignee for the repository, - * a 204 header with no content is returned. - * Otherwise a 404 status code is returned. - * - * @return void - */ - public function testCheckException() - { - $this->expectException(\DomainException::class); - - $this->response->code = 666; - $this->response->body = ''; - - $assignee = 'elkuku'; - - $this->client->expects($this->once()) - ->method('get') - ->with('/repos/' . $this->owner . '/' . $this->repo . '/assignees/' . $assignee, array(), 0) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->check($this->owner, $this->repo, $assignee), - $this->equalTo(false) - ); - } - - /** - * Tests the add method - * - * @return void - */ - public function testAdd() - { - $this->response->code = 201; - $this->response->body = '[ + $this->client->expects($this->once()) + ->method('get') + ->with('/repos/' . $this->owner . '/' . $this->repo . '/assignees', [], 0) + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->getList($this->owner, $this->repo), + $this->equalTo(json_decode($this->response->body)) + ); + } + + /** + * Tests the getList method + * Response: + * If the given assignee login belongs to an assignee for the repository, + * a 204 header with no content is returned. + * Otherwise a 404 status code is returned. + * + * @return void + */ + public function testCheck() + { + $this->response->code = 204; + $this->response->body = ''; + + $assignee = 'elkuku'; + + $this->client->expects($this->once()) + ->method('get') + ->with('/repos/' . $this->owner . '/' . $this->repo . '/assignees/' . $assignee, [], 0) + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->check($this->owner, $this->repo, $assignee), + $this->equalTo(true) + ); + } + + /** + * Tests the getList method with a negative response + * Response: + * If the given assignee login belongs to an assignee for the repository, + * a 204 header with no content is returned. + * Otherwise a 404 status code is returned. + * + * @return void + */ + public function testCheckNo() + { + $this->response->code = 404; + $this->response->body = ''; + + $assignee = 'elkuku'; + + $this->client->expects($this->once()) + ->method('get') + ->with('/repos/' . $this->owner . '/' . $this->repo . '/assignees/' . $assignee, [], 0) + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->check($this->owner, $this->repo, $assignee), + $this->equalTo(false) + ); + } + + /** + * Tests the getList method with a negative response + * Response: + * If the given assignee login belongs to an assignee for the repository, + * a 204 header with no content is returned. + * Otherwise a 404 status code is returned. + * + * @return void + */ + public function testCheckException() + { + $this->expectException(\DomainException::class); + + $this->response->code = 666; + $this->response->body = ''; + + $assignee = 'elkuku'; + + $this->client->expects($this->once()) + ->method('get') + ->with('/repos/' . $this->owner . '/' . $this->repo . '/assignees/' . $assignee, [], 0) + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->check($this->owner, $this->repo, $assignee), + $this->equalTo(false) + ); + } + + /** + * Tests the add method + * + * @return void + */ + public function testAdd() + { + $this->response->code = 201; + $this->response->body = '[ { "login": "octocat", "id": 1, @@ -179,26 +180,26 @@ public function testAdd() } ]'; - $this->client->expects($this->once()) - ->method('post') - ->with('/repos/' . $this->owner . '/' . $this->repo . '/issues/123/assignees', json_encode(array('assignees' => array('joomla')))) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->add($this->owner, $this->repo, 123, array('joomla')), - $this->equalTo(json_decode($this->response->body)) - ); - } - - /** - * Tests the remove method - * - * @return void - */ - public function testRemove() - { - $this->response->code = 200; - $this->response->body = '[ + $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)); + + $this->assertThat( + $this->object->add($this->owner, $this->repo, 123, ['joomla']), + $this->equalTo(json_decode($this->response->body)) + ); + } + + /** + * Tests the remove method + * + * @return void + */ + public function testRemove() + { + $this->response->code = 200; + $this->response->body = '[ { "login": "octocat", "id": 1, @@ -208,14 +209,14 @@ public function testRemove() } ]'; - $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)); + $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)); - $this->assertThat( - $this->object->remove($this->owner, $this->repo, 123, array('joomla')), - $this->equalTo(json_decode($this->response->body)) - ); - } + $this->assertThat( + $this->object->remove($this->owner, $this->repo, 123, ['joomla']), + $this->equalTo(json_decode($this->response->body)) + ); + } } diff --git a/Tests/Package/Issues/CommentsTest.php b/Tests/Package/Issues/CommentsTest.php index 184baf65..86e13639 100644 --- a/Tests/Package/Issues/CommentsTest.php +++ b/Tests/Package/Issues/CommentsTest.php @@ -1,4 +1,5 @@ object = new Comments($this->options, $this->client); - } - - /** - * Tests the getList method - * - * @return void - */ - public function testGetList() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/repos/joomla/joomla-platform/issues/1/comments', array(), 0) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->getList('joomla', 'joomla-platform', '1'), - $this->equalTo(json_decode($this->response->body)) - ); - } - - /** - * Tests the getRepositoryList method - * - * @return void - */ - public function testGetRepositoryList() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/repos/joomla/joomla-platform/issues/comments?sort=created&direction=asc', array(), 0) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->getRepositoryList('joomla', 'joomla-platform'), - $this->equalTo(json_decode($this->response->body)) - ); - } - - /** - * Tests the getRepositoryListInvalidSort method - * - * @return void - */ - public function testGetRepositoryListInvalidSort() - { - $this->expectException(\UnexpectedValueException::class); - - $this->object->getRepositoryList('joomla', 'joomla-platform', 'invalid'); - } - - /** - * Tests the getRepositoryListInvalidDirection method - * - * @return void - */ - public function testGetRepositoryListInvalidDirection() - { - $this->expectException(\UnexpectedValueException::class); - - $this->object->getRepositoryList('joomla', 'joomla-platform', 'created', 'invalid'); - } - - /** - * Tests the getRepositoryListSince method - * - * @return void - */ - public function testGetRepositoryListSince() - { - $date = new \DateTime('1966-09-15 12:34:56', new \DateTimeZone('UTC')); - - $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', array(), 0) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->getRepositoryList('joomla', 'joomla-platform', 'created', 'asc', $date), - $this->equalTo(json_decode($this->response->body)) - ); - } - - /** - * Tests the get method - * - * @return void - */ - public function testGet() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/repos/joomla/joomla-platform/issues/comments/1', array(), 0) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->get('joomla', 'joomla-platform', 1), - $this->equalTo(json_decode($this->response->body)) - ); - } - - /** - * Tests the edit method - * - * @return void - */ - public function testEdit() - { - $this->client->expects($this->once()) - ->method('patch') - ->with('/repos/joomla/joomla-platform/issues/comments/1', '{"body":"Hello"}', array(), 0) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->edit('joomla', 'joomla-platform', 1, 'Hello'), - $this->equalTo(json_decode($this->response->body)) - ); - } - - /** - * Tests the create method - * - * @return void - */ - public function testCreate() - { - $this->response->code = 201; - - $this->client->expects($this->once()) - ->method('post') - ->with('/repos/joomla/joomla-platform/issues/1/comments', '{"body":"Hello"}', array(), 0) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->create('joomla', 'joomla-platform', 1, 'Hello'), - $this->equalTo(json_decode($this->response->body)) - ); - } - - /** - * Tests the delete method - * - * @return void - */ - public function testDelete() - { - $this->response->code = 204; - $this->response->body = ''; - - $this->client->expects($this->once()) - ->method('delete') - ->with('/repos/joomla/joomla-platform/issues/comments/1', array(), 0) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->delete('joomla', 'joomla-platform', 1), - $this->equalTo(true) - ); - } + /** + * @var Comments Object under test. + * @since 1.0 + */ + protected $object; + + /** + * Sets up the fixture, for example, opens a network connection. + * This method is called before a test is executed. + * + * @since 1.0 + * + * @return void + */ + protected function setUp(): void + { + parent::setUp(); + + $this->object = new Comments($this->options, $this->client); + } + + /** + * Tests the getList method + * + * @return void + */ + public function testGetList() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/repos/joomla/joomla-platform/issues/1/comments', [], 0) + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->getList('joomla', 'joomla-platform', '1'), + $this->equalTo(json_decode($this->response->body)) + ); + } + + /** + * Tests the getRepositoryList method + * + * @return void + */ + 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)); + + $this->assertThat( + $this->object->getRepositoryList('joomla', 'joomla-platform'), + $this->equalTo(json_decode($this->response->body)) + ); + } + + /** + * Tests the getRepositoryListInvalidSort method + * + * @return void + */ + public function testGetRepositoryListInvalidSort() + { + $this->expectException(\UnexpectedValueException::class); + + $this->object->getRepositoryList('joomla', 'joomla-platform', 'invalid'); + } + + /** + * Tests the getRepositoryListInvalidDirection method + * + * @return void + */ + public function testGetRepositoryListInvalidDirection() + { + $this->expectException(\UnexpectedValueException::class); + + $this->object->getRepositoryList('joomla', 'joomla-platform', 'created', 'invalid'); + } + + /** + * Tests the getRepositoryListSince method + * + * @return void + */ + public function testGetRepositoryListSince() + { + $date = new \DateTime('1966-09-15 12:34:56', new \DateTimeZone('UTC')); + + $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)); + + $this->assertThat( + $this->object->getRepositoryList('joomla', 'joomla-platform', 'created', 'asc', $date), + $this->equalTo(json_decode($this->response->body)) + ); + } + + /** + * Tests the get method + * + * @return void + */ + public function testGet() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/repos/joomla/joomla-platform/issues/comments/1', [], 0) + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->get('joomla', 'joomla-platform', 1), + $this->equalTo(json_decode($this->response->body)) + ); + } + + /** + * Tests the edit method + * + * @return void + */ + 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)); + + $this->assertThat( + $this->object->edit('joomla', 'joomla-platform', 1, 'Hello'), + $this->equalTo(json_decode($this->response->body)) + ); + } + + /** + * Tests the create method + * + * @return void + */ + public function testCreate() + { + $this->response->code = 201; + + $this->client->expects($this->once()) + ->method('post') + ->with('/repos/joomla/joomla-platform/issues/1/comments', '{"body":"Hello"}', [], 0) + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->create('joomla', 'joomla-platform', 1, 'Hello'), + $this->equalTo(json_decode($this->response->body)) + ); + } + + /** + * Tests the delete method + * + * @return void + */ + public function testDelete() + { + $this->response->code = 204; + $this->response->body = ''; + + $this->client->expects($this->once()) + ->method('delete') + ->with('/repos/joomla/joomla-platform/issues/comments/1', [], 0) + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->delete('joomla', 'joomla-platform', 1), + $this->equalTo(true) + ); + } } diff --git a/Tests/Package/Issues/EventsTest.php b/Tests/Package/Issues/EventsTest.php index 7347cde3..b0a4189c 100644 --- a/Tests/Package/Issues/EventsTest.php +++ b/Tests/Package/Issues/EventsTest.php @@ -1,4 +1,5 @@ object = new Events($this->options, $this->client); - } + $this->object = new Events($this->options, $this->client); + } - /** - * Tests the getList method - * - * @return void - */ - public function testGetList() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/repos/joomla/joomla-platform/issues/1/events', array(), 0) - ->will($this->returnValue($this->response)); + /** + * Tests the getList method + * + * @return void + */ + public function testGetList() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/repos/joomla/joomla-platform/issues/1/events', [], 0) + ->will($this->returnValue($this->response)); - $this->assertThat( - $this->object->getList('joomla', 'joomla-platform', '1'), - $this->equalTo(json_decode($this->response->body)) - ); - } + $this->assertThat( + $this->object->getList('joomla', 'joomla-platform', '1'), + $this->equalTo(json_decode($this->response->body)) + ); + } - /** - * Tests the getListRepository method - * - * @return void - */ - public function testGetListRepository() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/repos/joomla/joomla-platform/issues/1/comments', array(), 0) - ->will($this->returnValue($this->response)); + /** + * Tests the getListRepository method + * + * @return void + */ + public function testGetListRepository() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/repos/joomla/joomla-platform/issues/1/comments', [], 0) + ->will($this->returnValue($this->response)); - $this->assertThat( - $this->object->getListRepository('joomla', 'joomla-platform', '1'), - $this->equalTo(json_decode($this->response->body)) - ); - } + $this->assertThat( + $this->object->getListRepository('joomla', 'joomla-platform', '1'), + $this->equalTo(json_decode($this->response->body)) + ); + } - /** - * Tests the get method - * - * @return void - */ - public function testGet() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/repos/joomla/joomla-platform/issues/events/1', array(), 0) - ->will($this->returnValue($this->response)); + /** + * Tests the get method + * + * @return void + */ + public function testGet() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/repos/joomla/joomla-platform/issues/events/1', [], 0) + ->will($this->returnValue($this->response)); - $this->assertThat( - $this->object->get('joomla', 'joomla-platform', '1'), - $this->equalTo(json_decode($this->response->body)) - ); - } + $this->assertThat( + $this->object->get('joomla', 'joomla-platform', '1'), + $this->equalTo(json_decode($this->response->body)) + ); + } } diff --git a/Tests/Package/Issues/LabelsTest.php b/Tests/Package/Issues/LabelsTest.php index 4593795f..400e62ea 100644 --- a/Tests/Package/Issues/LabelsTest.php +++ b/Tests/Package/Issues/LabelsTest.php @@ -1,4 +1,5 @@ object = new Labels($this->options, $this->client); - } - - /** - * Tests the getList method - * - * @return void - */ - public function testGetList() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/repos/joomla/joomla-platform/labels', array(), 0) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->getList('joomla', 'joomla-platform'), - $this->equalTo(json_decode($this->response->body)) - ); - } - - /** - * Tests the get method - * - * @return void - */ - public function testGet() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/repos/joomla/joomla-platform/labels/1', array(), 0) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->get('joomla', 'joomla-platform', '1'), - $this->equalTo(json_decode($this->response->body)) - ); - } - - /** - * Tests the create method - * - * @return void - */ - public function testCreate() - { - $this->response->code = 201; - - $this->client->expects($this->once()) - ->method('post') - ->with('/repos/joomla/joomla-platform/labels', '{"name":"foobar","color":"red"}', array(), 0) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->create('joomla', 'joomla-platform', 'foobar', 'red'), - $this->equalTo(json_decode($this->response->body)) - ); - } - - /** - * Tests the createFailure method - * - * @return void - */ - public function testCreateFailure() - { - $this->expectException(\DomainException::class); - - $this->response->code = 404; - $this->response->body = $this->errorString; - - $this->client->expects($this->once()) - ->method('post') - ->with('/repos/joomla/joomla-platform/labels', '{"name":"foobar","color":"red"}', array(), 0) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->create('joomla', 'joomla-platform', 'foobar', 'red'), - $this->equalTo(json_decode($this->response->body)) - ); - } - - /** - * Tests the update method - * - * @return void - */ - public function testUpdate() - { - $this->client->expects($this->once()) - ->method('patch') - ->with('/repos/joomla/joomla-platform/labels/foobar', '{"name":"boofaz","color":"red"}', array(), 0) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->update('joomla', 'joomla-platform', 'foobar', 'boofaz', 'red'), - $this->equalTo(json_decode($this->response->body)) - ); - } - - /** - * Tests the delete method - * - * @return void - */ - public function testDelete() - { - $this->response->code = 204; - - $this->client->expects($this->once()) - ->method('delete') - ->with('/repos/joomla/joomla-platform/labels/foobar', array(), 0) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->delete('joomla', 'joomla-platform', 'foobar'), - $this->equalTo(json_decode($this->response->body)) - ); - } - - /** - * Tests the getListByIssue method - * - * @return void - */ - public function testGetListByIssue() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/repos/joomla/joomla-platform/issues/1/labels', array(), 0) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->getListByIssue('joomla', 'joomla-platform', 1), - $this->equalTo(json_decode($this->response->body)) - ); - } - - /** - * Tests the add method - * - * @return void - */ - public function testAdd() - { - $this->client->expects($this->once()) - ->method('post') - ->with('/repos/joomla/joomla-platform/issues/1/labels', '["A","B"]', array(), 0) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->add('joomla', 'joomla-platform', 1, array('A', 'B')), - $this->equalTo(json_decode($this->response->body)) - ); - } - - /** - * Tests the removeFromIssue method - * - * @return void - */ - public function testRemoveFromIssue() - { - $this->client->expects($this->once()) - ->method('delete') - ->with('/repos/joomla/joomla-platform/issues/1/labels/foobar', array(), 0) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->removeFromIssue('joomla', 'joomla-platform', 1, 'foobar'), - $this->equalTo(json_decode($this->response->body)) - ); - } - - /** - * Tests the replace method - * - * @return void - */ - public function testReplace() - { - $this->client->expects($this->once()) - ->method('put') - ->with('/repos/joomla/joomla-platform/issues/1/labels', '["A","B"]', array(), 0) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->replace('joomla', 'joomla-platform', 1, array('A', 'B')), - $this->equalTo(json_decode($this->response->body)) - ); - } - - /** - * Tests the removeAllFromIssue method - * - * @return void - */ - public function testRemoveAllFromIssue() - { - $this->response->code = 204; - - $this->client->expects($this->once()) - ->method('delete') - ->with('/repos/joomla/joomla-platform/issues/1/labels', array(), 0) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->removeAllFromIssue('joomla', 'joomla-platform', 1), - $this->equalTo(json_decode($this->response->body)) - ); - } - - /** - * Tests the getListByMilestone method - * - * @return void - */ - public function testGetListByMilestone() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/repos/joomla/joomla-platform/milestones/1/labels', array(), 0) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->getListByMilestone('joomla', 'joomla-platform', 1), - $this->equalTo(json_decode($this->response->body)) - ); - } + /** + * @var Labels Object under test. + * @since 1.0 + */ + protected $object; + + /** + * Sets up the fixture, for example, opens a network connection. + * This method is called before a test is executed. + * + * @since 1.0 + * + * @return void + */ + protected function setUp(): void + { + parent::setUp(); + + $this->object = new Labels($this->options, $this->client); + } + + /** + * Tests the getList method + * + * @return void + */ + public function testGetList() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/repos/joomla/joomla-platform/labels', [], 0) + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->getList('joomla', 'joomla-platform'), + $this->equalTo(json_decode($this->response->body)) + ); + } + + /** + * Tests the get method + * + * @return void + */ + public function testGet() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/repos/joomla/joomla-platform/labels/1', [], 0) + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->get('joomla', 'joomla-platform', '1'), + $this->equalTo(json_decode($this->response->body)) + ); + } + + /** + * Tests the create method + * + * @return void + */ + public function testCreate() + { + $this->response->code = 201; + + $this->client->expects($this->once()) + ->method('post') + ->with('/repos/joomla/joomla-platform/labels', '{"name":"foobar","color":"red"}', [], 0) + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->create('joomla', 'joomla-platform', 'foobar', 'red'), + $this->equalTo(json_decode($this->response->body)) + ); + } + + /** + * Tests the createFailure method + * + * @return void + */ + public function testCreateFailure() + { + $this->expectException(\DomainException::class); + + $this->response->code = 404; + $this->response->body = $this->errorString; + + $this->client->expects($this->once()) + ->method('post') + ->with('/repos/joomla/joomla-platform/labels', '{"name":"foobar","color":"red"}', [], 0) + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->create('joomla', 'joomla-platform', 'foobar', 'red'), + $this->equalTo(json_decode($this->response->body)) + ); + } + + /** + * Tests the update method + * + * @return void + */ + 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)); + + $this->assertThat( + $this->object->update('joomla', 'joomla-platform', 'foobar', 'boofaz', 'red'), + $this->equalTo(json_decode($this->response->body)) + ); + } + + /** + * Tests the delete method + * + * @return void + */ + public function testDelete() + { + $this->response->code = 204; + + $this->client->expects($this->once()) + ->method('delete') + ->with('/repos/joomla/joomla-platform/labels/foobar', [], 0) + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->delete('joomla', 'joomla-platform', 'foobar'), + $this->equalTo(json_decode($this->response->body)) + ); + } + + /** + * Tests the getListByIssue method + * + * @return void + */ + public function testGetListByIssue() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/repos/joomla/joomla-platform/issues/1/labels', [], 0) + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->getListByIssue('joomla', 'joomla-platform', 1), + $this->equalTo(json_decode($this->response->body)) + ); + } + + /** + * Tests the add method + * + * @return void + */ + 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)); + + $this->assertThat( + $this->object->add('joomla', 'joomla-platform', 1, ['A', 'B']), + $this->equalTo(json_decode($this->response->body)) + ); + } + + /** + * Tests the removeFromIssue method + * + * @return void + */ + 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)); + + $this->assertThat( + $this->object->removeFromIssue('joomla', 'joomla-platform', 1, 'foobar'), + $this->equalTo(json_decode($this->response->body)) + ); + } + + /** + * Tests the replace method + * + * @return void + */ + 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)); + + $this->assertThat( + $this->object->replace('joomla', 'joomla-platform', 1, ['A', 'B']), + $this->equalTo(json_decode($this->response->body)) + ); + } + + /** + * Tests the removeAllFromIssue method + * + * @return void + */ + public function testRemoveAllFromIssue() + { + $this->response->code = 204; + + $this->client->expects($this->once()) + ->method('delete') + ->with('/repos/joomla/joomla-platform/issues/1/labels', [], 0) + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->removeAllFromIssue('joomla', 'joomla-platform', 1), + $this->equalTo(json_decode($this->response->body)) + ); + } + + /** + * Tests the getListByMilestone method + * + * @return void + */ + public function testGetListByMilestone() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/repos/joomla/joomla-platform/milestones/1/labels', [], 0) + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->getListByMilestone('joomla', 'joomla-platform', 1), + $this->equalTo(json_decode($this->response->body)) + ); + } } diff --git a/Tests/Package/Issues/MilestonesTest.php b/Tests/Package/Issues/MilestonesTest.php index d42a67de..e1fbcee1 100644 --- a/Tests/Package/Issues/MilestonesTest.php +++ b/Tests/Package/Issues/MilestonesTest.php @@ -1,4 +1,5 @@ object = new Milestones($this->options, $this->client); - } - - /** - * Tests the create method - * - * @return void - * - * @since 1.0 - */ - public function testCreate() - { - $this->response->code = 201; - - $milestone = '{' - . '"title":"My Milestone","state":"open","description":"This milestone is impossible","due_on":"2012-12-25T20:09:31Z"' - . '}'; - - $this->client->expects($this->once()) - ->method('post') - ->with('/repos/joomla/joomla-platform/milestones', $milestone) - ->will($this->returnValue($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)) - ); - } - - /** - * Tests the create method - failure - * - * @return void - * - * @since 12.3 - */ - public function testCreateFailure() - { - $this->expectException(\DomainException::class); - - $this->response->code = 501; - $this->response->body = $this->errorString; - - $milestone = '{' - . '"title":"My Milestone","state":"open","description":"This milestone is impossible","due_on":"2012-12-25T20:09:31Z"' - . '}'; - - $this->client->expects($this->once()) - ->method('post') - ->with('/repos/joomla/joomla-platform/milestones', $milestone) - ->will($this->returnValue($this->response)); - - $this->object->create('joomla', 'joomla-platform', 'My Milestone', 'open', 'This milestone is impossible', '2012-12-25T20:09:31Z'); - } - - /** - * Tests the edit method - * - * @return void - * - * @since 12.3 - */ - public function testEdit() - { - $milestone = new \stdClass; - $milestone->state = 'closed'; - - $this->client->expects($this->once()) - ->method('patch') - ->with('/repos/joomla/joomla-platform/milestones/523', json_encode($milestone)) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->edit('joomla', 'joomla-platform', 523, null, 'closed'), - $this->equalTo(json_decode($this->response->body)) - ); - } - - /** - * Tests the edit method with all parameters - * - * @return void - * - * @since 12.3 - */ - public function testEditAllParameters() - { - $milestone = '{' - . '"title":"{title}","state":"closed","description":"{description}","due_on":"2012-12-25T20:09:31Z"' - . '}'; - - $this->client->expects($this->once()) - ->method('patch') - ->with('/repos/{user}/{repo}/milestones/523', $milestone) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->edit('{user}', '{repo}', 523, '{title}', 'closed', '{description}', - '2012-12-25T20:09:31Z' - ), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Tests the edit method - failure - * - * @return void - * - * @since 12.3 - */ - public function testEditFailure() - { - $this->expectException(\DomainException::class); - - $this->response->code = 500; - $this->response->body = $this->errorString; - - $milestone = new \stdClass; - $milestone->state = 'closed'; - - $this->client->expects($this->once()) - ->method('patch') - ->with('/repos/joomla/joomla-platform/milestones/523', json_encode($milestone)) - ->will($this->returnValue($this->response)); - - $this->object->edit('joomla', 'joomla-platform', 523, null, 'closed'); - } - - /** - * Tests the get method - * - * @return void - * - * @since 12.3 - */ - public function testGet() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/repos/joomla/joomla-platform/milestones/523') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->get('joomla', 'joomla-platform', 523), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Tests the get method - failure - * - * @return void - * - * @since 12.3 - */ - public function testGetFailure() - { - $this->expectException(\DomainException::class); - - $this->response->code = 500; - $this->response->body = $this->errorString; - - $this->client->expects($this->once()) - ->method('get') - ->with('/repos/joomla/joomla-platform/milestones/523') - ->will($this->returnValue($this->response)); - - $this->object->get('joomla', 'joomla-platform', 523); - } - - /** - * Tests the getList method - * - * @return void - * - * @since 12.3 - */ - 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)); - - $this->assertThat( - $this->object->getList('joomla', 'joomla-platform'), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Tests the getList method - failure - * - * @return void - * - * @since 12.3 - */ - public function testGetListFailure() - { - $this->expectException(\DomainException::class); - - $this->response->code = 500; - $this->response->body = $this->errorString; - - $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)); - - $this->object->getList('joomla', 'joomla-platform'); - } - - /** - * Tests the delete method - * - * @return void - * - * @since 12.3 - */ - public function testDelete() - { - $this->response->code = 204; - - $this->client->expects($this->once()) - ->method('delete') - ->with('/repos/joomla/joomla-platform/milestones/254') - ->will($this->returnValue($this->response)); - - $this->object->delete('joomla', 'joomla-platform', 254); - } - - /** - * Tests the delete method - failure - * - * @return void - * - * @since 12.3 - */ - public function testDeleteFailure() - { - $this->expectException(\DomainException::class); - - $this->response->code = 504; - $this->response->body = $this->errorString; - - $this->client->expects($this->once()) - ->method('delete') - ->with('/repos/joomla/joomla-platform/milestones/254') - ->will($this->returnValue($this->response)); - - $this->object->delete('joomla', 'joomla-platform', 254); - } + /** + * @var Milestones Object under test. + * @since 1.0 + */ + protected $object; + + /** + * Sets up the fixture, for example, opens a network connection. + * This method is called before a test is executed. + * + * @access protected + * + * @return void + */ + protected function setUp(): void + { + parent::setUp(); + + $this->object = new Milestones($this->options, $this->client); + } + + /** + * Tests the create method + * + * @return void + * + * @since 1.0 + */ + public function testCreate() + { + $this->response->code = 201; + + $milestone = '{' + . '"title":"My Milestone","state":"open","description":"This milestone is impossible","due_on":"2012-12-25T20:09:31Z"' + . '}'; + + $this->client->expects($this->once()) + ->method('post') + ->with('/repos/joomla/joomla-platform/milestones', $milestone) + ->will($this->returnValue($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)) + ); + } + + /** + * Tests the create method - failure + * + * @return void + * + * @since 12.3 + */ + public function testCreateFailure() + { + $this->expectException(\DomainException::class); + + $this->response->code = 501; + $this->response->body = $this->errorString; + + $milestone = '{' + . '"title":"My Milestone","state":"open","description":"This milestone is impossible","due_on":"2012-12-25T20:09:31Z"' + . '}'; + + $this->client->expects($this->once()) + ->method('post') + ->with('/repos/joomla/joomla-platform/milestones', $milestone) + ->will($this->returnValue($this->response)); + + $this->object->create('joomla', 'joomla-platform', 'My Milestone', 'open', 'This milestone is impossible', '2012-12-25T20:09:31Z'); + } + + /** + * Tests the edit method + * + * @return void + * + * @since 12.3 + */ + public function testEdit() + { + $milestone = new \stdClass(); + $milestone->state = 'closed'; + + $this->client->expects($this->once()) + ->method('patch') + ->with('/repos/joomla/joomla-platform/milestones/523', json_encode($milestone)) + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->edit('joomla', 'joomla-platform', 523, null, 'closed'), + $this->equalTo(json_decode($this->response->body)) + ); + } + + /** + * Tests the edit method with all parameters + * + * @return void + * + * @since 12.3 + */ + public function testEditAllParameters() + { + $milestone = '{' + . '"title":"{title}","state":"closed","description":"{description}","due_on":"2012-12-25T20:09:31Z"' + . '}'; + + $this->client->expects($this->once()) + ->method('patch') + ->with('/repos/{user}/{repo}/milestones/523', $milestone) + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->edit( + '{user}', + '{repo}', + 523, + '{title}', + 'closed', + '{description}', + '2012-12-25T20:09:31Z' + ), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Tests the edit method - failure + * + * @return void + * + * @since 12.3 + */ + public function testEditFailure() + { + $this->expectException(\DomainException::class); + + $this->response->code = 500; + $this->response->body = $this->errorString; + + $milestone = new \stdClass(); + $milestone->state = 'closed'; + + $this->client->expects($this->once()) + ->method('patch') + ->with('/repos/joomla/joomla-platform/milestones/523', json_encode($milestone)) + ->will($this->returnValue($this->response)); + + $this->object->edit('joomla', 'joomla-platform', 523, null, 'closed'); + } + + /** + * Tests the get method + * + * @return void + * + * @since 12.3 + */ + public function testGet() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/repos/joomla/joomla-platform/milestones/523') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->get('joomla', 'joomla-platform', 523), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Tests the get method - failure + * + * @return void + * + * @since 12.3 + */ + public function testGetFailure() + { + $this->expectException(\DomainException::class); + + $this->response->code = 500; + $this->response->body = $this->errorString; + + $this->client->expects($this->once()) + ->method('get') + ->with('/repos/joomla/joomla-platform/milestones/523') + ->will($this->returnValue($this->response)); + + $this->object->get('joomla', 'joomla-platform', 523); + } + + /** + * Tests the getList method + * + * @return void + * + * @since 12.3 + */ + 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)); + + $this->assertThat( + $this->object->getList('joomla', 'joomla-platform'), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Tests the getList method - failure + * + * @return void + * + * @since 12.3 + */ + public function testGetListFailure() + { + $this->expectException(\DomainException::class); + + $this->response->code = 500; + $this->response->body = $this->errorString; + + $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)); + + $this->object->getList('joomla', 'joomla-platform'); + } + + /** + * Tests the delete method + * + * @return void + * + * @since 12.3 + */ + public function testDelete() + { + $this->response->code = 204; + + $this->client->expects($this->once()) + ->method('delete') + ->with('/repos/joomla/joomla-platform/milestones/254') + ->will($this->returnValue($this->response)); + + $this->object->delete('joomla', 'joomla-platform', 254); + } + + /** + * Tests the delete method - failure + * + * @return void + * + * @since 12.3 + */ + public function testDeleteFailure() + { + $this->expectException(\DomainException::class); + + $this->response->code = 504; + $this->response->body = $this->errorString; + + $this->client->expects($this->once()) + ->method('delete') + ->with('/repos/joomla/joomla-platform/milestones/254') + ->will($this->returnValue($this->response)); + + $this->object->delete('joomla', 'joomla-platform', 254); + } } diff --git a/Tests/Package/IssuesTest.php b/Tests/Package/IssuesTest.php index 466e7750..5272c0f3 100755 --- a/Tests/Package/IssuesTest.php +++ b/Tests/Package/IssuesTest.php @@ -1,4 +1,5 @@ object = new Issues($this->options, $this->client); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Issues::create() - * - * @return void - */ - public function testCreate() - { - $this->response->code = 201; - - $issue = new \stdClass; - $issue->title = '{title}'; - $issue->milestone = '{milestone}'; - $issue->labels = ['{label1}']; - $issue->body = '{body}'; - $issue->assignee = '{assignee}'; - - $this->client->expects($this->once()) - ->method('post') - ->with('/repos/{user}/{repo}/issues', json_encode($issue)) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->create('{user}', '{repo}', '{title}', '{body}', '{assignee}', '{milestone}', array('{label1}')), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Issues::create() - * - * @return void - */ - public function testCreate2() - { - $this->response->code = 201; - - $issue = new \stdClass; - $issue->title = '{title}'; - $issue->milestone = '{milestone}'; - $issue->labels = array('{label1}'); - $issue->body = '{body}'; - $issue->assignees = array('{assignee1}'); - - $this->client->expects($this->once()) - ->method('post') - ->with('/repos/{user}/{repo}/issues', json_encode($issue)) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->create('{user}', '{repo}', '{title}', '{body}', null, '{milestone}', array('{label1}'), array('{assignee1}')), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Issues::create() - * - * Failure - * - * @return void - */ - public function testCreateFailure() - { - $this->expectException(\DomainException::class); - - $this->response->code = 501; - $this->response->body = $this->errorString; - - $issue = new \stdClass; - $issue->title = '{title}'; - $issue->milestone = '{milestone}'; - $issue->labels = array('{label1}'); - $issue->body = '{body}'; - $issue->assignee = '{assignee}'; - - $this->client->expects($this->once()) - ->method('post') - ->with('/repos/{user}/{repo}/issues', json_encode($issue)) - ->will($this->returnValue($this->response)); - - $this->object->create('{user}', '{repo}', '{title}', '{body}', '{assignee}', '{milestone}', array('{label1}')); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Issues::create() - * - * @return void - */ - public function testCreateComment() - { - $this->response->code = 201; - - $issue = new \stdClass; - $issue->body = 'My Insightful Comment'; - - $this->client->expects($this->once()) - ->method('post') - ->with('/repos/joomla/joomla-platform/issues/523/comments', json_encode($issue)) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->comments->create('joomla', 'joomla-platform', 523, 'My Insightful Comment'), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Issues::create() - * - * Failure - * - * @return void - */ - public function testCreateCommentFailure() - { - $this->expectException(\DomainException::class); - - $this->response->code = 501; - $this->response->body = $this->errorString; - - $issue = new \stdClass; - $issue->body = 'My Insightful Comment'; - - $this->client->expects($this->once()) - ->method('post') - ->with('/repos/joomla/joomla-platform/issues/523/comments', json_encode($issue)) - ->will($this->returnValue($this->response)); - - $this->object->comments->create('joomla', 'joomla-platform', 523, 'My Insightful Comment'); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Issues::edit() - * - * @return void - */ - public function testEdit() - { - $issue = new \stdClass; - $issue->title = 'My issue'; - $issue->body = 'These are my changes - please review them'; - $issue->state = 'Closed'; - $issue->assignee = 'JoeAssignee'; - $issue->milestone = '12.2'; - $issue->labels = array('Fixed'); - - $this->client->expects($this->once()) - ->method('patch') - ->with('/repos/joomla/joomla-platform/issues/523', json_encode($issue)) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->edit('joomla', 'joomla-platform', 523, 'Closed', 'My issue', 'These are my changes - please review them', - 'JoeAssignee', '12.2', array('Fixed') - ), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Issues::edit() - * - * Failure - * - * @return void - */ - public function testEditFailure() - { - $this->expectException(\DomainException::class); - - $this->response->code = 500; - $this->response->body = $this->errorString; - - $issue = new \stdClass; - $issue->title = 'My issue'; - $issue->body = 'These are my changes - please review them'; - $issue->state = 'Closed'; - - $this->client->expects($this->once()) - ->method('patch') - ->with('/repos/joomla/joomla-platform/issues/523', json_encode($issue)) - ->will($this->returnValue($this->response)); - - $this->object->edit('joomla', 'joomla-platform', 523, 'Closed', 'My issue', 'These are my changes - please review them'); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Issues::get() - * - * @return void - */ - public function testGet() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/repos/joomla/joomla-platform/issues/523') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->get('joomla', 'joomla-platform', 523), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Issues::get() - * - * Failure - * - * @return void - */ - public function testGetFailure() - { - $this->expectException(\DomainException::class); - - $this->response->code = 500; - $this->response->body = $this->errorString; - - $this->client->expects($this->once()) - ->method('get') - ->with('/repos/joomla/joomla-platform/issues/523') - ->will($this->returnValue($this->response)); - - $this->object->get('joomla', 'joomla-platform', 523); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Issues::getList() - * - * @return void - */ - public function testGetList() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/issues') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->getList(), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Issues::getList() - * - * @return void - */ - public function testGetListAll() - { - $since = new \DateTime('January 1, 2012 12:12:12', new \DateTimeZone('UTC')); - - $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)); - - $this->assertThat( - $this->object->getList('{filter}', '{state}', '{labels}', '{sort}', '{direction}', $since), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Issues::getList() - * - * Failure - * - * @return void - */ - public function testGetListFailure() - { - $this->expectException(\DomainException::class); - - $this->response->code = 500; - $this->response->body = $this->errorString; - - $this->client->expects($this->once()) - ->method('get') - ->with('/issues') - ->will($this->returnValue($this->response)); - - $this->object->getList(); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Issues::getListByRepository() - * - * @return void - */ - public function testGetListByRepository() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/repos/joomla/joomla-platform/issues') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->getListByRepository('joomla', 'joomla-platform'), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Issues::getListByRepository() - * - * With all parameters - * - * @return void - */ - public function testGetListByRepositoryAll() - { - $date = new \DateTime('January 1, 2012 12:12:12', new \DateTimeZone('UTC')); - - $this->client->expects($this->once()) - ->method('get') - ->with( - '/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)); - - $this->assertThat( - $this->object->getListByRepository( - 'joomla', - 'joomla-platform', - '25', - 'closed', - 'none', - 'joomla-jenkins', - 'bug', - 'created', - 'asc', - $date - ), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Issues::getListByRepository() - * - * Failure - * - * @return void - */ - public function testGetListByRepositoryFailure() - { - $this->expectException(\DomainException::class); - - $this->response->code = 500; - $this->response->body = $this->errorString; - - $this->client->expects($this->once()) - ->method('get') - ->with('/repos/joomla/joomla-platform/issues') - ->will($this->returnValue($this->response)); - - $this->object->getListByRepository('joomla', 'joomla-platform'); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Issues::lock() - * - * @return void - */ - public function testLock() - { - $this->response->code = 204; - - $this->client->expects($this->once()) - ->method('put') - ->with('/repos/joomla/joomla-platform/issues/523/lock') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->lock('joomla', 'joomla-platform', 523), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Issues::lock() - * - * Failure - * - * @return void - */ - public function testLockFailure() - { - $this->expectException(\DomainException::class); - - $this->response->code = 500; - $this->response->body = $this->errorString; - - $this->client->expects($this->once()) - ->method('put') - ->with('/repos/joomla/joomla-platform/issues/523/lock') - ->will($this->returnValue($this->response)); - - $this->object->lock('joomla', 'joomla-platform', 523); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Issues::unlock() - * - * @return void - */ - public function testUnlock() - { - $this->response->code = 204; - - $this->client->expects($this->once()) - ->method('delete') - ->with('/repos/joomla/joomla-platform/issues/523/lock') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->unlock('joomla', 'joomla-platform', 523), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Issues::unlock() - * - * Failure - * - * @return void - */ - public function testUnlockFailure() - { - $this->expectException(\DomainException::class); - - $this->response->code = 500; - $this->response->body = $this->errorString; - - $this->client->expects($this->once()) - ->method('delete') - ->with('/repos/joomla/joomla-platform/issues/523/lock') - ->will($this->returnValue($this->response)); - - $this->object->unlock('joomla', 'joomla-platform', 523); - } + /** + * @var Issues Object under test. + * @since 1.0 + */ + protected $object; + + /** + * Sets up the fixture, for example, opens a network connection. + * This method is called before a test is executed. + * + * @access protected + * + * @return void + */ + protected function setUp(): void + { + parent::setUp(); + + $this->object = new Issues($this->options, $this->client); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Issues::create() + * + * @return void + */ + public function testCreate() + { + $this->response->code = 201; + + $issue = new \stdClass(); + $issue->title = '{title}'; + $issue->milestone = '{milestone}'; + $issue->labels = ['{label1}']; + $issue->body = '{body}'; + $issue->assignee = '{assignee}'; + + $this->client->expects($this->once()) + ->method('post') + ->with('/repos/{user}/{repo}/issues', json_encode($issue)) + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->create('{user}', '{repo}', '{title}', '{body}', '{assignee}', '{milestone}', ['{label1}']), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Issues::create() + * + * @return void + */ + public function testCreate2() + { + $this->response->code = 201; + + $issue = new \stdClass(); + $issue->title = '{title}'; + $issue->milestone = '{milestone}'; + $issue->labels = ['{label1}']; + $issue->body = '{body}'; + $issue->assignees = ['{assignee1}']; + + $this->client->expects($this->once()) + ->method('post') + ->with('/repos/{user}/{repo}/issues', json_encode($issue)) + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->create('{user}', '{repo}', '{title}', '{body}', null, '{milestone}', ['{label1}'], ['{assignee1}']), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Issues::create() + * + * Failure + * + * @return void + */ + public function testCreateFailure() + { + $this->expectException(\DomainException::class); + + $this->response->code = 501; + $this->response->body = $this->errorString; + + $issue = new \stdClass(); + $issue->title = '{title}'; + $issue->milestone = '{milestone}'; + $issue->labels = ['{label1}']; + $issue->body = '{body}'; + $issue->assignee = '{assignee}'; + + $this->client->expects($this->once()) + ->method('post') + ->with('/repos/{user}/{repo}/issues', json_encode($issue)) + ->will($this->returnValue($this->response)); + + $this->object->create('{user}', '{repo}', '{title}', '{body}', '{assignee}', '{milestone}', ['{label1}']); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Issues::create() + * + * @return void + */ + public function testCreateComment() + { + $this->response->code = 201; + + $issue = new \stdClass(); + $issue->body = 'My Insightful Comment'; + + $this->client->expects($this->once()) + ->method('post') + ->with('/repos/joomla/joomla-platform/issues/523/comments', json_encode($issue)) + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->comments->create('joomla', 'joomla-platform', 523, 'My Insightful Comment'), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Issues::create() + * + * Failure + * + * @return void + */ + public function testCreateCommentFailure() + { + $this->expectException(\DomainException::class); + + $this->response->code = 501; + $this->response->body = $this->errorString; + + $issue = new \stdClass(); + $issue->body = 'My Insightful Comment'; + + $this->client->expects($this->once()) + ->method('post') + ->with('/repos/joomla/joomla-platform/issues/523/comments', json_encode($issue)) + ->will($this->returnValue($this->response)); + + $this->object->comments->create('joomla', 'joomla-platform', 523, 'My Insightful Comment'); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Issues::edit() + * + * @return void + */ + public function testEdit() + { + $issue = new \stdClass(); + $issue->title = 'My issue'; + $issue->body = 'These are my changes - please review them'; + $issue->state = 'Closed'; + $issue->assignee = 'JoeAssignee'; + $issue->milestone = '12.2'; + $issue->labels = ['Fixed']; + + $this->client->expects($this->once()) + ->method('patch') + ->with('/repos/joomla/joomla-platform/issues/523', json_encode($issue)) + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->edit( + 'joomla', + 'joomla-platform', + 523, + 'Closed', + 'My issue', + 'These are my changes - please review them', + 'JoeAssignee', + '12.2', + ['Fixed'] + ), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Issues::edit() + * + * Failure + * + * @return void + */ + public function testEditFailure() + { + $this->expectException(\DomainException::class); + + $this->response->code = 500; + $this->response->body = $this->errorString; + + $issue = new \stdClass(); + $issue->title = 'My issue'; + $issue->body = 'These are my changes - please review them'; + $issue->state = 'Closed'; + + $this->client->expects($this->once()) + ->method('patch') + ->with('/repos/joomla/joomla-platform/issues/523', json_encode($issue)) + ->will($this->returnValue($this->response)); + + $this->object->edit('joomla', 'joomla-platform', 523, 'Closed', 'My issue', 'These are my changes - please review them'); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Issues::get() + * + * @return void + */ + public function testGet() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/repos/joomla/joomla-platform/issues/523') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->get('joomla', 'joomla-platform', 523), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Issues::get() + * + * Failure + * + * @return void + */ + public function testGetFailure() + { + $this->expectException(\DomainException::class); + + $this->response->code = 500; + $this->response->body = $this->errorString; + + $this->client->expects($this->once()) + ->method('get') + ->with('/repos/joomla/joomla-platform/issues/523') + ->will($this->returnValue($this->response)); + + $this->object->get('joomla', 'joomla-platform', 523); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Issues::getList() + * + * @return void + */ + public function testGetList() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/issues') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->getList(), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Issues::getList() + * + * @return void + */ + public function testGetListAll() + { + $since = new \DateTime('January 1, 2012 12:12:12', new \DateTimeZone('UTC')); + + $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)); + + $this->assertThat( + $this->object->getList('{filter}', '{state}', '{labels}', '{sort}', '{direction}', $since), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Issues::getList() + * + * Failure + * + * @return void + */ + public function testGetListFailure() + { + $this->expectException(\DomainException::class); + + $this->response->code = 500; + $this->response->body = $this->errorString; + + $this->client->expects($this->once()) + ->method('get') + ->with('/issues') + ->will($this->returnValue($this->response)); + + $this->object->getList(); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Issues::getListByRepository() + * + * @return void + */ + public function testGetListByRepository() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/repos/joomla/joomla-platform/issues') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->getListByRepository('joomla', 'joomla-platform'), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Issues::getListByRepository() + * + * With all parameters + * + * @return void + */ + public function testGetListByRepositoryAll() + { + $date = new \DateTime('January 1, 2012 12:12:12', new \DateTimeZone('UTC')); + + $this->client->expects($this->once()) + ->method('get') + ->with( + '/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)); + + $this->assertThat( + $this->object->getListByRepository( + 'joomla', + 'joomla-platform', + '25', + 'closed', + 'none', + 'joomla-jenkins', + 'bug', + 'created', + 'asc', + $date + ), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Issues::getListByRepository() + * + * Failure + * + * @return void + */ + public function testGetListByRepositoryFailure() + { + $this->expectException(\DomainException::class); + + $this->response->code = 500; + $this->response->body = $this->errorString; + + $this->client->expects($this->once()) + ->method('get') + ->with('/repos/joomla/joomla-platform/issues') + ->will($this->returnValue($this->response)); + + $this->object->getListByRepository('joomla', 'joomla-platform'); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Issues::lock() + * + * @return void + */ + public function testLock() + { + $this->response->code = 204; + + $this->client->expects($this->once()) + ->method('put') + ->with('/repos/joomla/joomla-platform/issues/523/lock') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->lock('joomla', 'joomla-platform', 523), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Issues::lock() + * + * Failure + * + * @return void + */ + public function testLockFailure() + { + $this->expectException(\DomainException::class); + + $this->response->code = 500; + $this->response->body = $this->errorString; + + $this->client->expects($this->once()) + ->method('put') + ->with('/repos/joomla/joomla-platform/issues/523/lock') + ->will($this->returnValue($this->response)); + + $this->object->lock('joomla', 'joomla-platform', 523); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Issues::unlock() + * + * @return void + */ + public function testUnlock() + { + $this->response->code = 204; + + $this->client->expects($this->once()) + ->method('delete') + ->with('/repos/joomla/joomla-platform/issues/523/lock') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->unlock('joomla', 'joomla-platform', 523), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Issues::unlock() + * + * Failure + * + * @return void + */ + public function testUnlockFailure() + { + $this->expectException(\DomainException::class); + + $this->response->code = 500; + $this->response->body = $this->errorString; + + $this->client->expects($this->once()) + ->method('delete') + ->with('/repos/joomla/joomla-platform/issues/523/lock') + ->will($this->returnValue($this->response)); + + $this->object->unlock('joomla', 'joomla-platform', 523); + } } diff --git a/Tests/Package/MarkdownTest.php b/Tests/Package/MarkdownTest.php index 95ca4689..8f31d555 100644 --- a/Tests/Package/MarkdownTest.php +++ b/Tests/Package/MarkdownTest.php @@ -1,4 +1,5 @@ object = new Markdown($this->options, $this->client); - } - - /** - * Tests the render method - * - * @return void - */ - public function testRender() - { - $this->response->code = 200; - $this->response->body = '
Hello world github/linguist#1 cool, ' - . 'and #1!
'; - - $text = 'Hello world github/linguist#1 **cool**, and #1!'; - $mode = 'gfm'; - $context = 'github/gollum'; - - $data = str_replace( - '\\/', '/', json_encode( - array( - 'text' => $text, - 'mode' => $mode, - 'context' => $context - ) - ) - ); - - $this->client->expects($this->once()) - ->method('post') - ->with('/markdown', $data, array(), 0) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->render($text, $mode, $context), - $this->equalTo($this->response->body) - ); - } - - /** - * Tests the renderInvalidMode method - * - * @return void - */ - public function testRenderInvalidMode() - { - $this->expectException(\InvalidArgumentException::class); - - $this->assertThat( - $this->object->render('', 'xxx', 'github/gollum'), - $this->equalTo('') - ); - } - - /** - * Tests the renderFailure method - * - * @return void - */ - public function testRenderFailure() - { - $this->expectException(\DomainException::class); - - $this->response->code = 404; - $this->response->body = ''; - - $text = 'Hello world github/linguist#1 **cool**, and #1!'; - $mode = 'gfm'; - $context = 'github/gollum'; - - $data = str_replace( - '\\/', '/', json_encode( - array( - 'text' => $text, - 'mode' => $mode, - 'context' => $context - ) - ) - ); - - $this->client->expects($this->once()) - ->method('post') - ->with('/markdown', $data, array(), 0) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->render($text, $mode, $context), - $this->equalTo('') - ); - } + /** + * @var Markdown + */ + protected $object; + + /** + * Sets up the fixture, for example, opens a network connection. + * This method is called before a test is executed. + * + * @access protected + * + * @return void + */ + protected function setUp(): void + { + parent::setUp(); + + $this->object = new Markdown($this->options, $this->client); + } + + /** + * Tests the render method + * + * @return void + */ + public function testRender() + { + $this->response->code = 200; + $this->response->body = 'Hello world github/linguist#1 cool, ' + . 'and #1!
'; + + $text = 'Hello world github/linguist#1 **cool**, and #1!'; + $mode = 'gfm'; + $context = 'github/gollum'; + + $data = str_replace( + '\\/', + '/', + json_encode( + [ + 'text' => $text, + 'mode' => $mode, + 'context' => $context, + ] + ) + ); + + $this->client->expects($this->once()) + ->method('post') + ->with('/markdown', $data, [], 0) + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->render($text, $mode, $context), + $this->equalTo($this->response->body) + ); + } + + /** + * Tests the renderInvalidMode method + * + * @return void + */ + public function testRenderInvalidMode() + { + $this->expectException(\InvalidArgumentException::class); + + $this->assertThat( + $this->object->render('', 'xxx', 'github/gollum'), + $this->equalTo('') + ); + } + + /** + * Tests the renderFailure method + * + * @return void + */ + public function testRenderFailure() + { + $this->expectException(\DomainException::class); + + $this->response->code = 404; + $this->response->body = ''; + + $text = 'Hello world github/linguist#1 **cool**, and #1!'; + $mode = 'gfm'; + $context = 'github/gollum'; + + $data = str_replace( + '\\/', + '/', + json_encode( + [ + 'text' => $text, + 'mode' => $mode, + 'context' => $context, + ] + ) + ); + + $this->client->expects($this->once()) + ->method('post') + ->with('/markdown', $data, [], 0) + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->render($text, $mode, $context), + $this->equalTo('') + ); + } } diff --git a/Tests/Package/MetaTest.php b/Tests/Package/MetaTest.php index f0964b4c..dd20ee95 100644 --- a/Tests/Package/MetaTest.php +++ b/Tests/Package/MetaTest.php @@ -1,4 +1,5 @@ object = new Meta($this->options, $this->client); - } + $this->object = new Meta($this->options, $this->client); + } - /** - * Tests the getMeta method - * - * @return void - * - * @since 1.0 - */ - public function testGetMeta() - { - $decodedResponse = new \stdClass; - $decodedResponse->hooks = array('127.0.0.1/32', '192.168.1.1/32', '10.10.1.1/27'); - $decodedResponse->git = array('127.0.0.1/32'); + /** + * Tests the getMeta method + * + * @return void + * + * @since 1.0 + */ + public function testGetMeta() + { + $decodedResponse = new \stdClass(); + $decodedResponse->hooks = ['127.0.0.1/32', '192.168.1.1/32', '10.10.1.1/27']; + $decodedResponse->git = ['127.0.0.1/32']; - $this->client->expects($this->once()) - ->method('get') - ->with('/meta') - ->will($this->returnValue($this->response)); + $this->client->expects($this->once()) + ->method('get') + ->with('/meta') + ->will($this->returnValue($this->response)); - $this->assertThat( - $this->object->getMeta(), - $this->equalTo($decodedResponse) - ); - } + $this->assertThat( + $this->object->getMeta(), + $this->equalTo($decodedResponse) + ); + } - /** - * Tests the getMeta method - failure - * - * @return void - * - * @since 1.0 - */ - public function testGetMetaFailure() - { - $this->expectException(\DomainException::class); + /** + * Tests the getMeta method - failure + * + * @return void + * + * @since 1.0 + */ + public function testGetMetaFailure() + { + $this->expectException(\DomainException::class); - $this->response->code = 500; - $this->response->body = $this->errorString; + $this->response->code = 500; + $this->response->body = $this->errorString; - $this->client->expects($this->once()) - ->method('get') - ->with('/meta') - ->will($this->returnValue($this->response)); + $this->client->expects($this->once()) + ->method('get') + ->with('/meta') + ->will($this->returnValue($this->response)); - $this->object->getMeta(); - } + $this->object->getMeta(); + } } diff --git a/Tests/Package/Orgs/HooksTest.php b/Tests/Package/Orgs/HooksTest.php index 6ad1b4ff..b99201f5 100644 --- a/Tests/Package/Orgs/HooksTest.php +++ b/Tests/Package/Orgs/HooksTest.php @@ -1,4 +1,5 @@ object = new Hooks($this->options, $this->client); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Orgs\Hooks::getList() - * - * @return void - */ - public function testGetList() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/orgs/joomla/hooks') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->getList('joomla'), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Orgs\Hooks::get() - * - * @return void - */ - public function testGet() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/orgs/joomla/hooks/123') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->get('joomla', 123), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Orgs\Hooks::create() - * - * @return void - */ - public function testCreate() - { - $this->response->code = 201; - - $this->client->expects($this->once()) - ->method('post') - ->with('/orgs/joomla/hooks') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->create('joomla', '{url}', 'json', '{secret}'), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Orgs\Hooks::create() - * - * @return void - */ - public function testCreateFailure() - { - $this->expectException(\UnexpectedValueException::class); - $this->expectExceptionMessage('Content type must be either "form" or "json"'); - - $this->object->create('joomla', '{url}', '{invalid}'); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Orgs\Hooks::create() - * - * @return void - */ - public function testCreateInvalidEvent() - { - $this->expectException(\RuntimeException::class); - $this->expectExceptionMessage('Your events array contains an unauthorized event.'); - - $this->object->create('{org}', '{url}', 'form', null, false, ['{invalid}']); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Orgs\Hooks::edit() - * - * @return void - */ - public function testEdit() - { - $this->response->code = 201; - - $this->client->expects($this->once()) - ->method('post') - ->with('/orgs/{org}/hooks') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->edit('{org}', '{url}', 'json', '{secret}', 1, array('create'), true), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Orgs\Hooks::edit() - * - * @return void - */ - public function testEditFailure() - { - $this->expectException(\UnexpectedValueException::class); - - $this->object->edit('{org}', '{url}', '{invalid}'); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Orgs\Hooks::edit() - * - * @return void - */ - public function testEditFailure2() - { - $this->expectException(\RuntimeException::class); - - $this->object->edit('{org}', '{url}', 'json', '{secret}', 1, array('{invalid}')); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Orgs\Hooks::ping() - * - * @return void - */ - public function testPing() - { - $this->response->code = 204; - - $this->client->expects($this->once()) - ->method('post') - ->with('/orgs/{org}/hooks/123/pings') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->ping('{org}', 123), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Orgs\Hooks::delete() - * - * @return void - */ - public function testDelete() - { - $this->response->code = 204; - - $this->client->expects($this->once()) - ->method('delete') - ->with('/orgs/joomla/hooks/123') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->delete('joomla', 123), - $this->equalTo(json_decode($this->sampleString)) - ); - } + /** + * @var Hooks + */ + protected $object; + + /** + * Sets up the fixture, for example, opens a network connection. + * This method is called before a test is executed. + * + * @since 1.0 + * + * @return void + */ + protected function setUp(): void + { + parent::setUp(); + + $this->object = new Hooks($this->options, $this->client); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Orgs\Hooks::getList() + * + * @return void + */ + public function testGetList() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/orgs/joomla/hooks') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->getList('joomla'), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Orgs\Hooks::get() + * + * @return void + */ + public function testGet() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/orgs/joomla/hooks/123') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->get('joomla', 123), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Orgs\Hooks::create() + * + * @return void + */ + public function testCreate() + { + $this->response->code = 201; + + $this->client->expects($this->once()) + ->method('post') + ->with('/orgs/joomla/hooks') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->create('joomla', '{url}', 'json', '{secret}'), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Orgs\Hooks::create() + * + * @return void + */ + public function testCreateFailure() + { + $this->expectException(\UnexpectedValueException::class); + $this->expectExceptionMessage('Content type must be either "form" or "json"'); + + $this->object->create('joomla', '{url}', '{invalid}'); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Orgs\Hooks::create() + * + * @return void + */ + public function testCreateInvalidEvent() + { + $this->expectException(\RuntimeException::class); + $this->expectExceptionMessage('Your events array contains an unauthorized event.'); + + $this->object->create('{org}', '{url}', 'form', null, false, ['{invalid}']); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Orgs\Hooks::edit() + * + * @return void + */ + public function testEdit() + { + $this->response->code = 201; + + $this->client->expects($this->once()) + ->method('post') + ->with('/orgs/{org}/hooks') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->edit('{org}', '{url}', 'json', '{secret}', 1, ['create'], true), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Orgs\Hooks::edit() + * + * @return void + */ + public function testEditFailure() + { + $this->expectException(\UnexpectedValueException::class); + + $this->object->edit('{org}', '{url}', '{invalid}'); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Orgs\Hooks::edit() + * + * @return void + */ + public function testEditFailure2() + { + $this->expectException(\RuntimeException::class); + + $this->object->edit('{org}', '{url}', 'json', '{secret}', 1, ['{invalid}']); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Orgs\Hooks::ping() + * + * @return void + */ + public function testPing() + { + $this->response->code = 204; + + $this->client->expects($this->once()) + ->method('post') + ->with('/orgs/{org}/hooks/123/pings') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->ping('{org}', 123), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Orgs\Hooks::delete() + * + * @return void + */ + public function testDelete() + { + $this->response->code = 204; + + $this->client->expects($this->once()) + ->method('delete') + ->with('/orgs/joomla/hooks/123') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->delete('joomla', 123), + $this->equalTo(json_decode($this->sampleString)) + ); + } } diff --git a/Tests/Package/Orgs/MembersTest.php b/Tests/Package/Orgs/MembersTest.php index bed70da6..604ed50a 100644 --- a/Tests/Package/Orgs/MembersTest.php +++ b/Tests/Package/Orgs/MembersTest.php @@ -1,4 +1,5 @@ object = new Members($this->options, $this->client); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Orgs\Members::getList() - * - * @return void - */ - public function testGetList() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/orgs/joomla/members') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->getList('joomla'), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Orgs\Members::getList() - * - * @return void - */ - public function testGetListNotAMember() - { - $this->response->code = 302; - - $this->client->expects($this->once()) - ->method('get') - ->with('/orgs/joomla/members') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->getList('joomla'), - $this->equalTo(false) - ); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Orgs\Members::getList() - * - * @return void - */ - public function testGetListUnexpected() - { - $this->expectException(\UnexpectedValueException::class); - - $this->response->code = 666; - - $this->client->expects($this->once()) - ->method('get') - ->with('/orgs/joomla/members') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->getList('joomla'), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Orgs\Members::check() - * - * @return void - */ - public function testCheck() - { - $this->response->code = 204; - - $this->client->expects($this->once()) - ->method('get') - ->with('/orgs/joomla/members/elkuku') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->check('joomla', 'elkuku'), - $this->equalTo(true) - ); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Orgs\Members::check() - * - * @return void - */ - public function testCheckNoMember() - { - $this->response->code = 404; - - $this->client->expects($this->once()) - ->method('get') - ->with('/orgs/joomla/members/elkuku') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->check('joomla', 'elkuku'), - $this->equalTo(false) - ); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Orgs\Members::check() - * - * @return void - */ - public function testCheckRequesterNoMember() - { - $this->response->code = 302; - - $this->client->expects($this->once()) - ->method('get') - ->with('/orgs/joomla/members/elkuku') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->check('joomla', 'elkuku'), - $this->equalTo(false) - ); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Orgs\Members::check() - * - * @return void - */ - public function testCheckUnexpectedr() - { - $this->expectException(\UnexpectedValueException::class); - - $this->response->code = 666; - - $this->client->expects($this->once()) - ->method('get') - ->with('/orgs/joomla/members/elkuku') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->check('joomla', 'elkuku'), - $this->equalTo(false) - ); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Orgs\Members::remove() - * - * @return void - */ - public function testRemove() - { - $this->response->code = 204; - - $this->client->expects($this->once()) - ->method('delete') - ->with('/orgs/joomla/members/elkuku') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->remove('joomla', 'elkuku'), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Orgs\Members::getListPublic() - * - * @return void - */ - public function testGetListPublic() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/orgs/joomla/public_members') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->getListPublic('joomla'), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Orgs\Members::checkPublic() - * - * @return void - */ - public function testCheckPublic() - { - $this->response->code = 204; - - $this->client->expects($this->once()) - ->method('get') - ->with('/orgs/joomla/public_members/elkuku') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->checkPublic('joomla', 'elkuku'), - $this->equalTo(true) - ); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Orgs\Members::checkPublic() - * - * @return void - */ - public function testCheckPublicNo() - { - $this->response->code = 404; - - $this->client->expects($this->once()) - ->method('get') - ->with('/orgs/joomla/public_members/elkuku') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->checkPublic('joomla', 'elkuku'), - $this->equalTo(false) - ); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Orgs\Members::checkPublic() - * - * @return void - */ - public function testCheckPublicUnexpected() - { - $this->expectException(\UnexpectedValueException::class); - - $this->response->code = 666; - - $this->client->expects($this->once()) - ->method('get') - ->with('/orgs/joomla/public_members/elkuku') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->checkPublic('joomla', 'elkuku'), - $this->equalTo(false) - ); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Orgs\Members::publicize() - * - * @return void - */ - public function testPublicize() - { - $this->response->code = 204; - - $this->client->expects($this->once()) - ->method('put') - ->with('/orgs/joomla/public_members/elkuku') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->publicize('joomla', 'elkuku'), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Orgs\Members::conceal() - * - * @return void - */ - public function testConceal() - { - $this->response->code = 204; - - $this->client->expects($this->once()) - ->method('delete') - ->with('/orgs/joomla/public_members/elkuku') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->conceal('joomla', 'elkuku'), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Orgs\Members::getMembership() - * - * @return void - */ - public function testGetMembership() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/orgs/{org}/memberships/{user}') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->getMembership('{org}', '{user}'), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Orgs\Members::updateMembership() - * - * @return void - */ - public function testUpdateMembership() - { - $this->client->expects($this->once()) - ->method('put') - ->with('/orgs/{org}/memberships/{user}') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->updateMembership('{org}', '{user}'), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Orgs\Members::updateMembership() - * - * @return void - */ - public function testUpdateMembershipInvalidRole() - { - $this->expectException(\InvalidArgumentException::class); - $this->expectExceptionMessage("The user's role must be: member, admin"); - - $this->object->updateMembership('{org}', '{user}', 'INVALID'); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Orgs\Members::removeMembership() - * - * @return void - */ - public function testRemoveMembership() - { - $this->response->code = 204; - - $this->client->expects($this->once()) - ->method('delete') - ->with('/orgs/{org}/memberships/{user}') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->removeMembership('{org}', '{user}'), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Orgs\Members::listMemberships() - * - * @return void - */ - public function testListMemberships() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/user/memberships/orgs') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->listMemberships(), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Orgs\Members::listOrganizationMembership() - * - * @return void - */ - public function testListOrganizationMemberships() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/user/memberships/orgs/{org}') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->listOrganizationMembership('{org}'), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Orgs\Members::editOrganizationMembership() - * - * @return void - */ - public function testEditOrganizationMemberships() - { - $this->client->expects($this->once()) - ->method('patch') - ->with('/user/memberships/orgs/{org}') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->editOrganizationMembership('{org}', 'active'), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Orgs\Members::editOrganizationMembership() - * - * @return void - */ - public function testEditOrganizationMembershipsInvalidState() - { - $this->expectException(\InvalidArgumentException::class); - $this->expectExceptionMessage('The state must be "active".'); - - $this->object->editOrganizationMembership('{org}', 'INVALID'); - } + /** + * @var Members + */ + protected $object; + + /** + * Sets up the fixture, for example, opens a network connection. + * This method is called before a test is executed. + * + * @since 1.0 + * + * @return void + */ + protected function setUp(): void + { + parent::setUp(); + + $this->object = new Members($this->options, $this->client); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Orgs\Members::getList() + * + * @return void + */ + public function testGetList() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/orgs/joomla/members') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->getList('joomla'), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Orgs\Members::getList() + * + * @return void + */ + public function testGetListNotAMember() + { + $this->response->code = 302; + + $this->client->expects($this->once()) + ->method('get') + ->with('/orgs/joomla/members') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->getList('joomla'), + $this->equalTo(false) + ); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Orgs\Members::getList() + * + * @return void + */ + public function testGetListUnexpected() + { + $this->expectException(\UnexpectedValueException::class); + + $this->response->code = 666; + + $this->client->expects($this->once()) + ->method('get') + ->with('/orgs/joomla/members') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->getList('joomla'), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Orgs\Members::check() + * + * @return void + */ + public function testCheck() + { + $this->response->code = 204; + + $this->client->expects($this->once()) + ->method('get') + ->with('/orgs/joomla/members/elkuku') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->check('joomla', 'elkuku'), + $this->equalTo(true) + ); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Orgs\Members::check() + * + * @return void + */ + public function testCheckNoMember() + { + $this->response->code = 404; + + $this->client->expects($this->once()) + ->method('get') + ->with('/orgs/joomla/members/elkuku') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->check('joomla', 'elkuku'), + $this->equalTo(false) + ); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Orgs\Members::check() + * + * @return void + */ + public function testCheckRequesterNoMember() + { + $this->response->code = 302; + + $this->client->expects($this->once()) + ->method('get') + ->with('/orgs/joomla/members/elkuku') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->check('joomla', 'elkuku'), + $this->equalTo(false) + ); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Orgs\Members::check() + * + * @return void + */ + public function testCheckUnexpectedr() + { + $this->expectException(\UnexpectedValueException::class); + + $this->response->code = 666; + + $this->client->expects($this->once()) + ->method('get') + ->with('/orgs/joomla/members/elkuku') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->check('joomla', 'elkuku'), + $this->equalTo(false) + ); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Orgs\Members::remove() + * + * @return void + */ + public function testRemove() + { + $this->response->code = 204; + + $this->client->expects($this->once()) + ->method('delete') + ->with('/orgs/joomla/members/elkuku') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->remove('joomla', 'elkuku'), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Orgs\Members::getListPublic() + * + * @return void + */ + public function testGetListPublic() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/orgs/joomla/public_members') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->getListPublic('joomla'), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Orgs\Members::checkPublic() + * + * @return void + */ + public function testCheckPublic() + { + $this->response->code = 204; + + $this->client->expects($this->once()) + ->method('get') + ->with('/orgs/joomla/public_members/elkuku') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->checkPublic('joomla', 'elkuku'), + $this->equalTo(true) + ); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Orgs\Members::checkPublic() + * + * @return void + */ + public function testCheckPublicNo() + { + $this->response->code = 404; + + $this->client->expects($this->once()) + ->method('get') + ->with('/orgs/joomla/public_members/elkuku') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->checkPublic('joomla', 'elkuku'), + $this->equalTo(false) + ); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Orgs\Members::checkPublic() + * + * @return void + */ + public function testCheckPublicUnexpected() + { + $this->expectException(\UnexpectedValueException::class); + + $this->response->code = 666; + + $this->client->expects($this->once()) + ->method('get') + ->with('/orgs/joomla/public_members/elkuku') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->checkPublic('joomla', 'elkuku'), + $this->equalTo(false) + ); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Orgs\Members::publicize() + * + * @return void + */ + public function testPublicize() + { + $this->response->code = 204; + + $this->client->expects($this->once()) + ->method('put') + ->with('/orgs/joomla/public_members/elkuku') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->publicize('joomla', 'elkuku'), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Orgs\Members::conceal() + * + * @return void + */ + public function testConceal() + { + $this->response->code = 204; + + $this->client->expects($this->once()) + ->method('delete') + ->with('/orgs/joomla/public_members/elkuku') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->conceal('joomla', 'elkuku'), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Orgs\Members::getMembership() + * + * @return void + */ + public function testGetMembership() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/orgs/{org}/memberships/{user}') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->getMembership('{org}', '{user}'), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Orgs\Members::updateMembership() + * + * @return void + */ + public function testUpdateMembership() + { + $this->client->expects($this->once()) + ->method('put') + ->with('/orgs/{org}/memberships/{user}') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->updateMembership('{org}', '{user}'), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Orgs\Members::updateMembership() + * + * @return void + */ + public function testUpdateMembershipInvalidRole() + { + $this->expectException(\InvalidArgumentException::class); + $this->expectExceptionMessage("The user's role must be: member, admin"); + + $this->object->updateMembership('{org}', '{user}', 'INVALID'); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Orgs\Members::removeMembership() + * + * @return void + */ + public function testRemoveMembership() + { + $this->response->code = 204; + + $this->client->expects($this->once()) + ->method('delete') + ->with('/orgs/{org}/memberships/{user}') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->removeMembership('{org}', '{user}'), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Orgs\Members::listMemberships() + * + * @return void + */ + public function testListMemberships() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/user/memberships/orgs') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->listMemberships(), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Orgs\Members::listOrganizationMembership() + * + * @return void + */ + public function testListOrganizationMemberships() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/user/memberships/orgs/{org}') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->listOrganizationMembership('{org}'), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Orgs\Members::editOrganizationMembership() + * + * @return void + */ + public function testEditOrganizationMemberships() + { + $this->client->expects($this->once()) + ->method('patch') + ->with('/user/memberships/orgs/{org}') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->editOrganizationMembership('{org}', 'active'), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Orgs\Members::editOrganizationMembership() + * + * @return void + */ + public function testEditOrganizationMembershipsInvalidState() + { + $this->expectException(\InvalidArgumentException::class); + $this->expectExceptionMessage('The state must be "active".'); + + $this->object->editOrganizationMembership('{org}', 'INVALID'); + } } diff --git a/Tests/Package/Orgs/TeamsTest.php b/Tests/Package/Orgs/TeamsTest.php index 7ab71b99..2e55c2dd 100644 --- a/Tests/Package/Orgs/TeamsTest.php +++ b/Tests/Package/Orgs/TeamsTest.php @@ -1,4 +1,5 @@ object = new Teams($this->options, $this->client); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Orgs\Teams::getList() - * - * @return void - */ - public function testGetList() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/orgs/joomla/teams') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->getList('joomla'), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Orgs\Teams::get() - * - * @return void - */ - public function testGet() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/teams/123') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->get(123), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Orgs\Teams::create() - * - * @return void - */ - public function testCreate() - { - $this->response->code = 201; - - $this->client->expects($this->once()) - ->method('post') - ->with('/orgs/joomla/teams') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->create('joomla', 'TheTeam', array('joomla-platform'), 'admin'), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Orgs\Teams::create() - * - * @return void - */ - public function testCreateWrongPermission() - { - $this->expectException(\UnexpectedValueException::class); - - $this->response->code = 201; - - $this->object->create('joomla', 'TheTeam', array('joomla-platform'), 'invalid'); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Orgs\Teams::edit() - * - * @return void - */ - public function testEdit() - { - $this->client->expects($this->once()) - ->method('patch') - ->with('/teams/123') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->edit(123, 'TheTeam', 'admin'), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Orgs\Teams::edit() - * - * @return void - */ - public function testEditWrongPermission() - { - $this->expectException(\UnexpectedValueException::class); - - $this->object->edit(123, 'TheTeam', 'invalid'); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Orgs\Teams::delete() - * - * @return void - */ - public function testDelete() - { - $this->response->code = 204; - - $this->client->expects($this->once()) - ->method('delete') - ->with('/teams/123') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->delete(123), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Orgs\Teams::getListMembers() - * - * @return void - */ - public function testGetListMembers() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/teams/123/members') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->getListMembers(123), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Orgs\Teams::isMember() - * - * @deprecated - * - * @return void - */ - public function testIsMember() - { - $this->response->code = 204; - - $this->client->expects($this->once()) - ->method('get') - ->with('/teams/123/members/elkuku') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->isMember(123, 'elkuku'), - $this->equalTo(json_decode(true)) - ); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Orgs\Teams::isMember() - * - * @deprecated - * - * @return void - */ - public function testIsMemberNo() - { - $this->response->code = 404; - - $this->client->expects($this->once()) - ->method('get') - ->with('/teams/123/members/elkuku') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->isMember(123, 'elkuku'), - $this->equalTo(json_decode(false)) - ); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Orgs\Teams::isMember() - * - * @deprecated - * - * @return void - */ - public function testIsMemberUnexpected() - { - $this->expectException(\UnexpectedValueException::class); - - $this->response->code = 666; - - $this->client->expects($this->once()) - ->method('get') - ->with('/teams/123/members/elkuku') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->isMember(123, 'elkuku'), - $this->equalTo(json_decode(true)) - ); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Orgs\Teams::addMember() - * - * @deprecated - * - * @return void - */ - public function testAddMember() - { - $this->response->code = 204; - - $this->client->expects($this->once()) - ->method('put') - ->with('/teams/123/members/elkuku') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->addMember(123, 'elkuku'), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Orgs\Teams::removeMember() - * - * @deprecated - * - * @return void - */ - public function testRemoveMember() - { - $this->response->code = 204; - - $this->client->expects($this->once()) - ->method('delete') - ->with('/teams/123/members/elkuku') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->removeMember(123, 'elkuku'), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Orgs\Teams::getListRepos() - * - * @return void - */ - public function testGetListRepos() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/teams/123/repos') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->getListRepos(123), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Orgs\Teams::checkRepo() - * - * @return void - */ - public function testCheckRepo() - { - $this->response->code = 204; - - $this->client->expects($this->once()) - ->method('get') - ->with('/teams/123/repos/joomla/cms') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->checkRepo(123, 'joomla', 'cms'), - $this->equalTo(true) - ); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Orgs\Teams::checkRepo() - * - * @return void - */ - public function testCheckRepoNo() - { - $this->response->code = 404; - - $this->client->expects($this->once()) - ->method('get') - ->with('/teams/123/repos/joomla/cms') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->checkRepo(123, 'joomla', 'cms'), - $this->equalTo(false) - ); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Orgs\Teams::checkRepo() - * - * @return void - */ - public function testCheckRepoUnexpected() - { - $this->expectException(\UnexpectedValueException::class); - - $this->response->code = 666; - - $this->client->expects($this->once()) - ->method('get') - ->with('/teams/123/repos/joomla/cms') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->checkRepo(123, 'joomla', 'cms'), - $this->equalTo(true) - ); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Orgs\Teams::addRepo() - * - * @return void - */ - public function testAddRepo() - { - $this->response->code = 204; - - $this->client->expects($this->once()) - ->method('put') - ->with('/teams/123/repos/joomla/joomla-platform') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->addRepo(123, 'joomla', 'joomla-platform'), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Orgs\Teams::removeRepo() - * - * @return void - */ - public function testRemoveRepo() - { - $this->response->code = 204; - - $this->client->expects($this->once()) - ->method('delete') - ->with('/teams/123/repos/joomla/joomla-platform') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->removeRepo(123, 'joomla', 'joomla-platform'), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Orgs\Teams::getTeamMembership() - * - * @return void - */ - public function testGetTeamMemberships() - { - $this->response->code = 200; - $this->response->body = '{"state":"TEST"}'; - - $this->client->expects($this->once()) - ->method('get') - ->with('/teams/123/memberships/{user}') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->getTeamMembership(123, '{user}'), - $this->equalTo('TEST') - ); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Orgs\Teams::getTeamMembership() - * - * Response if user is not a member - * - * @return void - */ - public function testGetTeamMembershipsFailure1() - { - $this->response->code = 404; - $this->response->body = '{"state":"TEST"}'; - - $this->client->expects($this->once()) - ->method('get') - ->with('/teams/123/memberships/{user}') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->getTeamMembership(123, '{user}'), - $this->equalTo(false) - ); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Orgs\Teams::getTeamMembership() - * - * Unexpected Response - * - * @return void - */ - public function testGetTeamMembershipsFailure2() - { - $this->expectException(\UnexpectedValueException::class); - $this->expectExceptionMessage('Unexpected response code: 666'); - - $this->response->code = 666; - $this->response->body = '{"state":"TEST"}'; - - $this->client->expects($this->once()) - ->method('get') - ->with('/teams/123/memberships/{user}') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->getTeamMembership(123, '{user}'), - $this->equalTo('TEST') - ); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Orgs\Teams::addTeamMembership() - * - * @return void - */ - public function testAddTeamMemberships() - { - $this->client->expects($this->once()) - ->method('put') - ->with('/teams/123/memberships/{user}') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->addTeamMembership(123, '{user}'), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Orgs\Teams::addTeamMembership() - * - * Invalid role - * - * @return void - */ - public function testAddTeamMembershipsFailure() - { - $this->expectException(\UnexpectedValueException::class); - $this->expectExceptionMessage('Roles must be either "member" or "maintainer".'); - - $this->object->addTeamMembership(123, '{user}', 'INVALID'); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Orgs\Teams::removeTeamMembership() - * - * @return void - */ - public function testRemoveTeamMemberships() - { - $this->response->code = 204; - - $this->client->expects($this->once()) - ->method('delete') - ->with('/teams/123/memberships/{user}') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->removeTeamMembership(123, '{user}'), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Orgs\Teams::getUserTeams() - * - * @return void - */ - public function testGetUserTeams() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/user/teams') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->getUserTeams(), - $this->equalTo(json_decode($this->sampleString)) - ); - } + /** + * @var Teams + */ + protected $object; + + /** + * Sets up the fixture, for example, opens a network connection. + * This method is called before a test is executed. + * + * @since 1.0 + * + * @return void + */ + protected function setUp(): void + { + parent::setUp(); + + $this->object = new Teams($this->options, $this->client); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Orgs\Teams::getList() + * + * @return void + */ + public function testGetList() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/orgs/joomla/teams') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->getList('joomla'), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Orgs\Teams::get() + * + * @return void + */ + public function testGet() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/teams/123') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->get(123), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Orgs\Teams::create() + * + * @return void + */ + public function testCreate() + { + $this->response->code = 201; + + $this->client->expects($this->once()) + ->method('post') + ->with('/orgs/joomla/teams') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->create('joomla', 'TheTeam', ['joomla-platform'], 'admin'), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Orgs\Teams::create() + * + * @return void + */ + public function testCreateWrongPermission() + { + $this->expectException(\UnexpectedValueException::class); + + $this->response->code = 201; + + $this->object->create('joomla', 'TheTeam', ['joomla-platform'], 'invalid'); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Orgs\Teams::edit() + * + * @return void + */ + public function testEdit() + { + $this->client->expects($this->once()) + ->method('patch') + ->with('/teams/123') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->edit(123, 'TheTeam', 'admin'), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Orgs\Teams::edit() + * + * @return void + */ + public function testEditWrongPermission() + { + $this->expectException(\UnexpectedValueException::class); + + $this->object->edit(123, 'TheTeam', 'invalid'); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Orgs\Teams::delete() + * + * @return void + */ + public function testDelete() + { + $this->response->code = 204; + + $this->client->expects($this->once()) + ->method('delete') + ->with('/teams/123') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->delete(123), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Orgs\Teams::getListMembers() + * + * @return void + */ + public function testGetListMembers() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/teams/123/members') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->getListMembers(123), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Orgs\Teams::isMember() + * + * @deprecated + * + * @return void + */ + public function testIsMember() + { + $this->response->code = 204; + + $this->client->expects($this->once()) + ->method('get') + ->with('/teams/123/members/elkuku') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->isMember(123, 'elkuku'), + $this->equalTo(json_decode(true)) + ); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Orgs\Teams::isMember() + * + * @deprecated + * + * @return void + */ + public function testIsMemberNo() + { + $this->response->code = 404; + + $this->client->expects($this->once()) + ->method('get') + ->with('/teams/123/members/elkuku') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->isMember(123, 'elkuku'), + $this->equalTo(json_decode(false)) + ); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Orgs\Teams::isMember() + * + * @deprecated + * + * @return void + */ + public function testIsMemberUnexpected() + { + $this->expectException(\UnexpectedValueException::class); + + $this->response->code = 666; + + $this->client->expects($this->once()) + ->method('get') + ->with('/teams/123/members/elkuku') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->isMember(123, 'elkuku'), + $this->equalTo(json_decode(true)) + ); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Orgs\Teams::addMember() + * + * @deprecated + * + * @return void + */ + public function testAddMember() + { + $this->response->code = 204; + + $this->client->expects($this->once()) + ->method('put') + ->with('/teams/123/members/elkuku') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->addMember(123, 'elkuku'), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Orgs\Teams::removeMember() + * + * @deprecated + * + * @return void + */ + public function testRemoveMember() + { + $this->response->code = 204; + + $this->client->expects($this->once()) + ->method('delete') + ->with('/teams/123/members/elkuku') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->removeMember(123, 'elkuku'), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Orgs\Teams::getListRepos() + * + * @return void + */ + public function testGetListRepos() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/teams/123/repos') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->getListRepos(123), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Orgs\Teams::checkRepo() + * + * @return void + */ + public function testCheckRepo() + { + $this->response->code = 204; + + $this->client->expects($this->once()) + ->method('get') + ->with('/teams/123/repos/joomla/cms') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->checkRepo(123, 'joomla', 'cms'), + $this->equalTo(true) + ); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Orgs\Teams::checkRepo() + * + * @return void + */ + public function testCheckRepoNo() + { + $this->response->code = 404; + + $this->client->expects($this->once()) + ->method('get') + ->with('/teams/123/repos/joomla/cms') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->checkRepo(123, 'joomla', 'cms'), + $this->equalTo(false) + ); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Orgs\Teams::checkRepo() + * + * @return void + */ + public function testCheckRepoUnexpected() + { + $this->expectException(\UnexpectedValueException::class); + + $this->response->code = 666; + + $this->client->expects($this->once()) + ->method('get') + ->with('/teams/123/repos/joomla/cms') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->checkRepo(123, 'joomla', 'cms'), + $this->equalTo(true) + ); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Orgs\Teams::addRepo() + * + * @return void + */ + public function testAddRepo() + { + $this->response->code = 204; + + $this->client->expects($this->once()) + ->method('put') + ->with('/teams/123/repos/joomla/joomla-platform') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->addRepo(123, 'joomla', 'joomla-platform'), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Orgs\Teams::removeRepo() + * + * @return void + */ + public function testRemoveRepo() + { + $this->response->code = 204; + + $this->client->expects($this->once()) + ->method('delete') + ->with('/teams/123/repos/joomla/joomla-platform') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->removeRepo(123, 'joomla', 'joomla-platform'), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Orgs\Teams::getTeamMembership() + * + * @return void + */ + public function testGetTeamMemberships() + { + $this->response->code = 200; + $this->response->body = '{"state":"TEST"}'; + + $this->client->expects($this->once()) + ->method('get') + ->with('/teams/123/memberships/{user}') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->getTeamMembership(123, '{user}'), + $this->equalTo('TEST') + ); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Orgs\Teams::getTeamMembership() + * + * Response if user is not a member + * + * @return void + */ + public function testGetTeamMembershipsFailure1() + { + $this->response->code = 404; + $this->response->body = '{"state":"TEST"}'; + + $this->client->expects($this->once()) + ->method('get') + ->with('/teams/123/memberships/{user}') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->getTeamMembership(123, '{user}'), + $this->equalTo(false) + ); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Orgs\Teams::getTeamMembership() + * + * Unexpected Response + * + * @return void + */ + public function testGetTeamMembershipsFailure2() + { + $this->expectException(\UnexpectedValueException::class); + $this->expectExceptionMessage('Unexpected response code: 666'); + + $this->response->code = 666; + $this->response->body = '{"state":"TEST"}'; + + $this->client->expects($this->once()) + ->method('get') + ->with('/teams/123/memberships/{user}') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->getTeamMembership(123, '{user}'), + $this->equalTo('TEST') + ); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Orgs\Teams::addTeamMembership() + * + * @return void + */ + public function testAddTeamMemberships() + { + $this->client->expects($this->once()) + ->method('put') + ->with('/teams/123/memberships/{user}') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->addTeamMembership(123, '{user}'), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Orgs\Teams::addTeamMembership() + * + * Invalid role + * + * @return void + */ + public function testAddTeamMembershipsFailure() + { + $this->expectException(\UnexpectedValueException::class); + $this->expectExceptionMessage('Roles must be either "member" or "maintainer".'); + + $this->object->addTeamMembership(123, '{user}', 'INVALID'); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Orgs\Teams::removeTeamMembership() + * + * @return void + */ + public function testRemoveTeamMemberships() + { + $this->response->code = 204; + + $this->client->expects($this->once()) + ->method('delete') + ->with('/teams/123/memberships/{user}') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->removeTeamMembership(123, '{user}'), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Orgs\Teams::getUserTeams() + * + * @return void + */ + public function testGetUserTeams() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/user/teams') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->getUserTeams(), + $this->equalTo(json_decode($this->sampleString)) + ); + } } diff --git a/Tests/Package/OrgsTest.php b/Tests/Package/OrgsTest.php index 2c992e51..28acae74 100644 --- a/Tests/Package/OrgsTest.php +++ b/Tests/Package/OrgsTest.php @@ -1,4 +1,5 @@ object = new Orgs($this->options, $this->client); - } + $this->object = new Orgs($this->options, $this->client); + } - /** - * Tests the getList method - * - * @return void - */ - public function testGetList() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/users/joomla/orgs') - ->will($this->returnValue($this->response)); + /** + * Tests the getList method + * + * @return void + */ + public function testGetList() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/users/joomla/orgs') + ->will($this->returnValue($this->response)); - $this->assertThat( - $this->object->getList('joomla'), - $this->equalTo(json_decode($this->sampleString)) - ); - } + $this->assertThat( + $this->object->getList('joomla'), + $this->equalTo(json_decode($this->sampleString)) + ); + } - /** - * Tests the get method - * - * @return void - */ - public function testGet() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/orgs/joomla') - ->will($this->returnValue($this->response)); + /** + * Tests the get method + * + * @return void + */ + public function testGet() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/orgs/joomla') + ->will($this->returnValue($this->response)); - $this->assertThat( - $this->object->get('joomla'), - $this->equalTo(json_decode($this->sampleString)) - ); - } + $this->assertThat( + $this->object->get('joomla'), + $this->equalTo(json_decode($this->sampleString)) + ); + } - /** - * Tests the edit method - * - * @return void - */ - public function testEdit() - { - $this->client->expects($this->once()) - ->method('patch') - ->with('/orgs/joomla') - ->will($this->returnValue($this->response)); + /** + * Tests the edit method + * + * @return void + */ + public function testEdit() + { + $this->client->expects($this->once()) + ->method('patch') + ->with('/orgs/joomla') + ->will($this->returnValue($this->response)); - $this->assertThat( - $this->object->edit('joomla', 'email@example.com'), - $this->equalTo(json_decode($this->sampleString)) - ); - } + $this->assertThat( + $this->object->edit('joomla', 'email@example.com'), + $this->equalTo(json_decode($this->sampleString)) + ); + } } diff --git a/Tests/Package/Pulls/CommentsTest.php b/Tests/Package/Pulls/CommentsTest.php index 0c0e96cf..faaea5a5 100644 --- a/Tests/Package/Pulls/CommentsTest.php +++ b/Tests/Package/Pulls/CommentsTest.php @@ -1,4 +1,5 @@ object = new Comments($this->options, $this->client); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Pulls\Comments::create() - * - * @return void - */ - public function testCreate() - { - $this->response->code = 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, array(), 0) - ->will($this->returnValue($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)) - ); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Pulls\Comments::createReply() - * - * @return void - */ - public function testCreateReply() - { - $this->response->code = 201; - - $this->client->expects($this->once()) - ->method('post') - ->with('/repos/joomla/joomla-platform/pulls/1/comments', '{"body":"The Body","in_reply_to":456}', array(), 0) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->createReply('joomla', 'joomla-platform', 1, 'The Body', 456), - $this->equalTo(json_decode($this->response->body)) - ); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Pulls\Comments::delete() - * - * @return void - */ - public function testDelete() - { - $this->response->code = 204; - $this->response->body = ''; - - $this->client->expects($this->once()) - ->method('delete') - ->with('/repos/joomla/joomla-platform/pulls/comments/456', array(), 0) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->delete('joomla', 'joomla-platform', 456), - $this->equalTo(json_decode($this->response->body)) - ); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Pulls\Comments::edit() - * - * @return void - */ - public function testEdit() - { - $this->response->code = 200; - $this->response->body = ''; - - $this->client->expects($this->once()) - ->method('patch') - ->with('/repos/joomla/joomla-platform/pulls/comments/456', '{"body":"Hello"}', array(), 0) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->edit('joomla', 'joomla-platform', 456, 'Hello'), - $this->equalTo(json_decode($this->response->body)) - ); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Pulls\Comments::get() - * - * @return void - */ - public function testGet() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/repos/joomla/joomla-platform/pulls/comments/456', array(), 0) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->get('joomla', 'joomla-platform', 456), - $this->equalTo(json_decode($this->response->body)) - ); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Pulls\Comments::getList() - * - * @return void - */ - public function testGetList() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/repos/joomla/joomla-platform/pulls/456/comments', array(), 0) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->getList('joomla', 'joomla-platform', 456), - $this->equalTo(json_decode($this->response->body)) - ); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Pulls\Comments::getListForRepo() - * - * @return void - */ - public function testGetListForRepo() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/repos/{user}/{repo}/pulls/comments', [], 0) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->getListForRepo('{user}', '{repo}'), - $this->equalTo(json_decode($this->response->body)) - ); - } + /** + * @var Comments + */ + protected $object; + + /** + * Sets up the fixture, for example, opens a network connection. + * This method is called before a test is executed. + * + * @since 1.0 + * + * @return void + */ + protected function setUp(): void + { + parent::setUp(); + + $this->object = new Comments($this->options, $this->client); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Pulls\Comments::create() + * + * @return void + */ + public function testCreate() + { + $this->response->code = 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)); + + $this->assertThat( + $this->object->create('joomla', 'joomla-platform', 1, 'The Body', '123abc', 'a/b/c', 456), + $this->equalTo(json_decode($this->response->body)) + ); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Pulls\Comments::createReply() + * + * @return void + */ + public function testCreateReply() + { + $this->response->code = 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)); + + $this->assertThat( + $this->object->createReply('joomla', 'joomla-platform', 1, 'The Body', 456), + $this->equalTo(json_decode($this->response->body)) + ); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Pulls\Comments::delete() + * + * @return void + */ + public function testDelete() + { + $this->response->code = 204; + $this->response->body = ''; + + $this->client->expects($this->once()) + ->method('delete') + ->with('/repos/joomla/joomla-platform/pulls/comments/456', [], 0) + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->delete('joomla', 'joomla-platform', 456), + $this->equalTo(json_decode($this->response->body)) + ); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Pulls\Comments::edit() + * + * @return void + */ + public function testEdit() + { + $this->response->code = 200; + $this->response->body = ''; + + $this->client->expects($this->once()) + ->method('patch') + ->with('/repos/joomla/joomla-platform/pulls/comments/456', '{"body":"Hello"}', [], 0) + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->edit('joomla', 'joomla-platform', 456, 'Hello'), + $this->equalTo(json_decode($this->response->body)) + ); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Pulls\Comments::get() + * + * @return void + */ + public function testGet() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/repos/joomla/joomla-platform/pulls/comments/456', [], 0) + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->get('joomla', 'joomla-platform', 456), + $this->equalTo(json_decode($this->response->body)) + ); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Pulls\Comments::getList() + * + * @return void + */ + public function testGetList() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/repos/joomla/joomla-platform/pulls/456/comments', [], 0) + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->getList('joomla', 'joomla-platform', 456), + $this->equalTo(json_decode($this->response->body)) + ); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Pulls\Comments::getListForRepo() + * + * @return void + */ + public function testGetListForRepo() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/repos/{user}/{repo}/pulls/comments', [], 0) + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->getListForRepo('{user}', '{repo}'), + $this->equalTo(json_decode($this->response->body)) + ); + } } diff --git a/Tests/Package/PullsTest.php b/Tests/Package/PullsTest.php index 11d5bfe0..e75bd4d6 100755 --- a/Tests/Package/PullsTest.php +++ b/Tests/Package/PullsTest.php @@ -1,4 +1,5 @@ object = new Pulls($this->options, $this->client); - } - - /** - * Tests the create method - * - * @return void - */ - public function testCreate() - { - $this->response->code = 201; - - $pull = new \stdClass; - $pull->title = 'My Pull Request'; - $pull->base = 'staging'; - $pull->head = 'joomla-jenkins:mychanges'; - $pull->body = 'These are my changes - please review them'; - - $this->client->expects($this->once()) - ->method('post') - ->with('/repos/joomla/joomla-platform/pulls', json_encode($pull)) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->create('joomla', 'joomla-platform', 'My Pull Request', 'staging', 'joomla-jenkins:mychanges', - 'These are my changes - please review them' - ), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Tests the create method - failure - * - * @return void - */ - public function testCreateFailure() - { - $this->expectException(\DomainException::class); - - $this->response->code = 501; - $this->response->body = $this->errorString; - - $pull = new \stdClass; - $pull->title = 'My Pull Request'; - $pull->base = 'staging'; - $pull->head = 'joomla-jenkins:mychanges'; - $pull->body = 'These are my changes - please review them'; - - $this->client->expects($this->once()) - ->method('post') - ->with('/repos/joomla/joomla-platform/pulls', json_encode($pull)) - ->will($this->returnValue($this->response)); - - $this->object->create('joomla', 'joomla-platform', 'My Pull Request', 'staging', 'joomla-jenkins:mychanges', - 'These are my changes - please review them' - ); - } - - /** - * Tests the createFromIssue method - * - * @return void - */ - public function testCreateFromIssue() - { - $this->response->code = 201; - - $pull = new \stdClass; - $pull->issue = 254; - $pull->base = 'staging'; - $pull->head = 'joomla-jenkins:mychanges'; - - $this->client->expects($this->once()) - ->method('post') - ->with('/repos/joomla/joomla-platform/pulls', json_encode($pull)) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->createFromIssue('joomla', 'joomla-platform', 254, 'staging', 'joomla-jenkins:mychanges'), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Tests the createFromIssue method - failure - * - * @return void - */ - public function testCreateFromIssueFailure() - { - $this->expectException(\DomainException::class); - - $this->response->code = 501; - $this->response->body = $this->errorString; - - $pull = new \stdClass; - $pull->issue = 254; - $pull->base = 'staging'; - $pull->head = 'joomla-jenkins:mychanges'; - - $this->client->expects($this->once()) - ->method('post') - ->with('/repos/joomla/joomla-platform/pulls', json_encode($pull)) - ->will($this->returnValue($this->response)); - - $this->object->createFromIssue('joomla', 'joomla-platform', 254, 'staging', 'joomla-jenkins:mychanges'); - } - - /** - * Tests the edit method - * - * @return void - */ - public function testEdit() - { - $pull = new \stdClass; - $pull->title = 'My Pull Request'; - $pull->body = 'These are my changes - please review them'; - $pull->state = 'Closed'; - $pull->base = 'new'; - - $this->client->expects($this->once()) - ->method('patch') - ->with('/repos/joomla/joomla-platform/pulls/523', json_encode($pull)) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->edit('joomla', 'joomla-platform', 523, 'My Pull Request', 'These are my changes - please review them', 'Closed', 'new'), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Tests the edit method - failure - * - * @return void - */ - public function testEditFailure() - { - $this->expectException(\DomainException::class); - - $this->response->code = 500; - $this->response->body = $this->errorString; - - $pull = new \stdClass; - $pull->title = 'My Pull Request'; - $pull->body = 'These are my changes - please review them'; - - $this->client->expects($this->once()) - ->method('patch') - ->with('/repos/joomla/joomla-platform/pulls/523', json_encode($pull)) - ->will($this->returnValue($this->response)); - - $this->object->edit('joomla', 'joomla-platform', 523, 'My Pull Request', 'These are my changes - please review them'); - } - - /** - * Tests the get method - * - * @return void - */ - public function testGet() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/repos/joomla/joomla-platform/pulls/523') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->get('joomla', 'joomla-platform', 523), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Tests the get method - failure - * - * @return void - */ - public function testGetFailure() - { - $this->expectException(\DomainException::class); - - $this->response->code = 500; - $this->response->body = $this->errorString; - - $this->client->expects($this->once()) - ->method('get') - ->with('/repos/joomla/joomla-platform/pulls/523') - ->will($this->returnValue($this->response)); - - $this->object->get('joomla', 'joomla-platform', 523); - } - - /** - * Tests the getCommits method - * - * @return void - */ - public function testGetCommits() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/repos/joomla/joomla-platform/pulls/523/commits') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->getCommits('joomla', 'joomla-platform', 523), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Tests the getCommits method - failure - * - * @return void - */ - public function testGetCommitsFailure() - { - $this->expectException(\DomainException::class); - - $this->response->code = 500; - $this->response->body = $this->errorString; - - $this->client->expects($this->once()) - ->method('get') - ->with('/repos/joomla/joomla-platform/pulls/523/commits') - ->will($this->returnValue($this->response)); - - $this->object->getCommits('joomla', 'joomla-platform', 523); - } - - /** - * Tests the getFiles method - * - * @return void - */ - public function testGetFiles() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/repos/joomla/joomla-platform/pulls/523/files') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->getFiles('joomla', 'joomla-platform', 523), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Tests the getFiles method - failure - * - * @return void - */ - public function testGetFilesFailure() - { - $this->expectException(\DomainException::class); - - $this->response->code = 500; - $this->response->body = $this->errorString; - - $this->client->expects($this->once()) - ->method('get') - ->with('/repos/joomla/joomla-platform/pulls/523/files') - ->will($this->returnValue($this->response)); - - $this->object->getFiles('joomla', 'joomla-platform', 523); - } - - /** - * Tests the getList method - * - * @return void - */ - public function testGetList() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/repos/joomla/joomla-platform/pulls?state=closed') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->getList('joomla', 'joomla-platform', 'closed'), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Tests the getList method - failure - * - * @return void - */ - public function testGetListFailure() - { - $this->expectException(\DomainException::class); - - $this->response->code = 500; - $this->response->body = $this->errorString; - - $this->client->expects($this->once()) - ->method('get') - ->with('/repos/joomla/joomla-platform/pulls') - ->will($this->returnValue($this->response)); - - $this->object->getList('joomla', 'joomla-platform'); - } - - /** - * Tests the isMerged method when the pull request has been merged - * - * @return void - */ - public function testIsMergedTrue() - { - $this->response->code = 204; - - $this->client->expects($this->once()) - ->method('get') - ->with('/repos/joomla/joomla-platform/pulls/523/merge') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->isMerged('joomla', 'joomla-platform', 523), - $this->equalTo(true) - ); - } - - /** - * Tests the isMerged method when the pull request has not been merged - * - * @return void - */ - public function testIsMergedFalse() - { - $this->response->code = 404; - - $this->client->expects($this->once()) - ->method('get') - ->with('/repos/joomla/joomla-platform/pulls/523/merge') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->isMerged('joomla', 'joomla-platform', 523), - $this->equalTo(false) - ); - } - - /** - * Tests the isMerged method when the request fails - * - * @return void - */ - public function testIsMergedFailure() - { - $this->expectException(\DomainException::class); - - $this->response->code = 504; - $this->response->body = $this->errorString; - - $this->client->expects($this->once()) - ->method('get') - ->with('/repos/joomla/joomla-platform/pulls/523/merge') - ->will($this->returnValue($this->response)); - - $this->object->isMerged('joomla', 'joomla-platform', 523); - } - - /** - * Tests the merge method - * - * @return void - */ - public function testMerge() - { - $this->client->expects($this->once()) - ->method('put') - ->with('/repos/joomla/joomla-platform/pulls/523/merge') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->merge('joomla', 'joomla-platform', 523), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Tests the merge method - failure - * - * @return void - */ - public function testMergeFailure() - { - $this->expectException(\DomainException::class); - - $this->response->code = 500; - $this->response->body = $this->errorString; - - $this->client->expects($this->once()) - ->method('put') - ->with('/repos/joomla/joomla-platform/pulls/523/merge') - ->will($this->returnValue($this->response)); - - $this->object->merge('joomla', 'joomla-platform', 523); - } + /** + * @var Pulls + */ + protected $object; + + /** + * Sets up the fixture, for example, opens a network connection. + * This method is called before a test is executed. + * + * @access protected + * + * @return void + */ + protected function setUp(): void + { + parent::setUp(); + + $this->object = new Pulls($this->options, $this->client); + } + + /** + * Tests the create method + * + * @return void + */ + public function testCreate() + { + $this->response->code = 201; + + $pull = new \stdClass(); + $pull->title = 'My Pull Request'; + $pull->base = 'staging'; + $pull->head = 'joomla-jenkins:mychanges'; + $pull->body = 'These are my changes - please review them'; + + $this->client->expects($this->once()) + ->method('post') + ->with('/repos/joomla/joomla-platform/pulls', json_encode($pull)) + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->create( + 'joomla', + 'joomla-platform', + 'My Pull Request', + 'staging', + 'joomla-jenkins:mychanges', + 'These are my changes - please review them' + ), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Tests the create method - failure + * + * @return void + */ + public function testCreateFailure() + { + $this->expectException(\DomainException::class); + + $this->response->code = 501; + $this->response->body = $this->errorString; + + $pull = new \stdClass(); + $pull->title = 'My Pull Request'; + $pull->base = 'staging'; + $pull->head = 'joomla-jenkins:mychanges'; + $pull->body = 'These are my changes - please review them'; + + $this->client->expects($this->once()) + ->method('post') + ->with('/repos/joomla/joomla-platform/pulls', json_encode($pull)) + ->will($this->returnValue($this->response)); + + $this->object->create( + 'joomla', + 'joomla-platform', + 'My Pull Request', + 'staging', + 'joomla-jenkins:mychanges', + 'These are my changes - please review them' + ); + } + + /** + * Tests the createFromIssue method + * + * @return void + */ + public function testCreateFromIssue() + { + $this->response->code = 201; + + $pull = new \stdClass(); + $pull->issue = 254; + $pull->base = 'staging'; + $pull->head = 'joomla-jenkins:mychanges'; + + $this->client->expects($this->once()) + ->method('post') + ->with('/repos/joomla/joomla-platform/pulls', json_encode($pull)) + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->createFromIssue('joomla', 'joomla-platform', 254, 'staging', 'joomla-jenkins:mychanges'), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Tests the createFromIssue method - failure + * + * @return void + */ + public function testCreateFromIssueFailure() + { + $this->expectException(\DomainException::class); + + $this->response->code = 501; + $this->response->body = $this->errorString; + + $pull = new \stdClass(); + $pull->issue = 254; + $pull->base = 'staging'; + $pull->head = 'joomla-jenkins:mychanges'; + + $this->client->expects($this->once()) + ->method('post') + ->with('/repos/joomla/joomla-platform/pulls', json_encode($pull)) + ->will($this->returnValue($this->response)); + + $this->object->createFromIssue('joomla', 'joomla-platform', 254, 'staging', 'joomla-jenkins:mychanges'); + } + + /** + * Tests the edit method + * + * @return void + */ + public function testEdit() + { + $pull = new \stdClass(); + $pull->title = 'My Pull Request'; + $pull->body = 'These are my changes - please review them'; + $pull->state = 'Closed'; + $pull->base = 'new'; + + $this->client->expects($this->once()) + ->method('patch') + ->with('/repos/joomla/joomla-platform/pulls/523', json_encode($pull)) + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->edit('joomla', 'joomla-platform', 523, 'My Pull Request', 'These are my changes - please review them', 'Closed', 'new'), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Tests the edit method - failure + * + * @return void + */ + public function testEditFailure() + { + $this->expectException(\DomainException::class); + + $this->response->code = 500; + $this->response->body = $this->errorString; + + $pull = new \stdClass(); + $pull->title = 'My Pull Request'; + $pull->body = 'These are my changes - please review them'; + + $this->client->expects($this->once()) + ->method('patch') + ->with('/repos/joomla/joomla-platform/pulls/523', json_encode($pull)) + ->will($this->returnValue($this->response)); + + $this->object->edit('joomla', 'joomla-platform', 523, 'My Pull Request', 'These are my changes - please review them'); + } + + /** + * Tests the get method + * + * @return void + */ + public function testGet() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/repos/joomla/joomla-platform/pulls/523') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->get('joomla', 'joomla-platform', 523), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Tests the get method - failure + * + * @return void + */ + public function testGetFailure() + { + $this->expectException(\DomainException::class); + + $this->response->code = 500; + $this->response->body = $this->errorString; + + $this->client->expects($this->once()) + ->method('get') + ->with('/repos/joomla/joomla-platform/pulls/523') + ->will($this->returnValue($this->response)); + + $this->object->get('joomla', 'joomla-platform', 523); + } + + /** + * Tests the getCommits method + * + * @return void + */ + public function testGetCommits() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/repos/joomla/joomla-platform/pulls/523/commits') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->getCommits('joomla', 'joomla-platform', 523), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Tests the getCommits method - failure + * + * @return void + */ + public function testGetCommitsFailure() + { + $this->expectException(\DomainException::class); + + $this->response->code = 500; + $this->response->body = $this->errorString; + + $this->client->expects($this->once()) + ->method('get') + ->with('/repos/joomla/joomla-platform/pulls/523/commits') + ->will($this->returnValue($this->response)); + + $this->object->getCommits('joomla', 'joomla-platform', 523); + } + + /** + * Tests the getFiles method + * + * @return void + */ + public function testGetFiles() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/repos/joomla/joomla-platform/pulls/523/files') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->getFiles('joomla', 'joomla-platform', 523), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Tests the getFiles method - failure + * + * @return void + */ + public function testGetFilesFailure() + { + $this->expectException(\DomainException::class); + + $this->response->code = 500; + $this->response->body = $this->errorString; + + $this->client->expects($this->once()) + ->method('get') + ->with('/repos/joomla/joomla-platform/pulls/523/files') + ->will($this->returnValue($this->response)); + + $this->object->getFiles('joomla', 'joomla-platform', 523); + } + + /** + * Tests the getList method + * + * @return void + */ + public function testGetList() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/repos/joomla/joomla-platform/pulls?state=closed') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->getList('joomla', 'joomla-platform', 'closed'), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Tests the getList method - failure + * + * @return void + */ + public function testGetListFailure() + { + $this->expectException(\DomainException::class); + + $this->response->code = 500; + $this->response->body = $this->errorString; + + $this->client->expects($this->once()) + ->method('get') + ->with('/repos/joomla/joomla-platform/pulls') + ->will($this->returnValue($this->response)); + + $this->object->getList('joomla', 'joomla-platform'); + } + + /** + * Tests the isMerged method when the pull request has been merged + * + * @return void + */ + public function testIsMergedTrue() + { + $this->response->code = 204; + + $this->client->expects($this->once()) + ->method('get') + ->with('/repos/joomla/joomla-platform/pulls/523/merge') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->isMerged('joomla', 'joomla-platform', 523), + $this->equalTo(true) + ); + } + + /** + * Tests the isMerged method when the pull request has not been merged + * + * @return void + */ + public function testIsMergedFalse() + { + $this->response->code = 404; + + $this->client->expects($this->once()) + ->method('get') + ->with('/repos/joomla/joomla-platform/pulls/523/merge') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->isMerged('joomla', 'joomla-platform', 523), + $this->equalTo(false) + ); + } + + /** + * Tests the isMerged method when the request fails + * + * @return void + */ + public function testIsMergedFailure() + { + $this->expectException(\DomainException::class); + + $this->response->code = 504; + $this->response->body = $this->errorString; + + $this->client->expects($this->once()) + ->method('get') + ->with('/repos/joomla/joomla-platform/pulls/523/merge') + ->will($this->returnValue($this->response)); + + $this->object->isMerged('joomla', 'joomla-platform', 523); + } + + /** + * Tests the merge method + * + * @return void + */ + public function testMerge() + { + $this->client->expects($this->once()) + ->method('put') + ->with('/repos/joomla/joomla-platform/pulls/523/merge') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->merge('joomla', 'joomla-platform', 523), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Tests the merge method - failure + * + * @return void + */ + public function testMergeFailure() + { + $this->expectException(\DomainException::class); + + $this->response->code = 500; + $this->response->body = $this->errorString; + + $this->client->expects($this->once()) + ->method('put') + ->with('/repos/joomla/joomla-platform/pulls/523/merge') + ->will($this->returnValue($this->response)); + + $this->object->merge('joomla', 'joomla-platform', 523); + } } diff --git a/Tests/Package/Repositories/BranchesTest.php b/Tests/Package/Repositories/BranchesTest.php index 51ca67e5..c9899301 100644 --- a/Tests/Package/Repositories/BranchesTest.php +++ b/Tests/Package/Repositories/BranchesTest.php @@ -1,4 +1,5 @@ object = new Branches($this->options, $this->client); - } + $this->object = new Branches($this->options, $this->client); + } - /** - * Tests the GetList method. - * - * @covers \Joomla\Github\Package\Repositories\Branches::getList() - * - * @return void - */ - public function testGetList() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/repos/{owner}/{repo}/branches') - ->will($this->returnValue($this->response)); + /** + * Tests the GetList method. + * + * @covers \Joomla\Github\Package\Repositories\Branches::getList() + * + * @return void + */ + public function testGetList() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/repos/{owner}/{repo}/branches') + ->will($this->returnValue($this->response)); - $this->assertThat( - $this->object->getList('{owner}', '{repo}'), - $this->equalTo(json_decode($this->sampleString)) - ); - } + $this->assertThat( + $this->object->getList('{owner}', '{repo}'), + $this->equalTo(json_decode($this->sampleString)) + ); + } - /** - * Tests the Get method. - * - * @covers \Joomla\Github\Package\Repositories\Branches::get() - * - * @return void - */ - public function testGet() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/repos/{owner}/{repo}/branches/{branch}') - ->will($this->returnValue($this->response)); + /** + * Tests the Get method. + * + * @covers \Joomla\Github\Package\Repositories\Branches::get() + * + * @return void + */ + public function testGet() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/repos/{owner}/{repo}/branches/{branch}') + ->will($this->returnValue($this->response)); - $this->assertThat( - $this->object->get('{owner}', '{repo}', '{branch}'), - $this->equalTo(json_decode($this->sampleString)) - ); - } + $this->assertThat( + $this->object->get('{owner}', '{repo}', '{branch}'), + $this->equalTo(json_decode($this->sampleString)) + ); + } } diff --git a/Tests/Package/Repositories/CollaboratorsTest.php b/Tests/Package/Repositories/CollaboratorsTest.php index 045572fb..d365db94 100644 --- a/Tests/Package/Repositories/CollaboratorsTest.php +++ b/Tests/Package/Repositories/CollaboratorsTest.php @@ -1,4 +1,5 @@ object = new Collaborators($this->options, $this->client); - } - - /** - * Tests the GetList method. - * - * @return void - */ - public function testGetList() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/repos/joomla/joomla-framework/collaborators') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->getList('joomla', 'joomla-framework'), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Tests the Get method. - * - * @return void - */ - public function testGet() - { - $this->response->code = 204; - $this->response->body = true; - - $this->client->expects($this->once()) - ->method('get') - ->with('/repos/joomla/joomla-framework/collaborators/elkuku') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->get('joomla', 'joomla-framework', 'elkuku'), - $this->equalTo($this->response->body) - ); - } - - /** - * Tests the GetNegative method. - * - * @return void - */ - public function testGetNegative() - { - $this->response->code = 404; - $this->response->body = false; - - $this->client->expects($this->once()) - ->method('get') - ->with('/repos/joomla/joomla-framework/collaborators/elkuku') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->get('joomla', 'joomla-framework', 'elkuku'), - $this->equalTo($this->response->body) - ); - } - - /** - * Tests the GetUnexpected method. - * - * @return void - */ - public function testGetUnexpected() - { - $this->expectException(\UnexpectedValueException::class); - - $this->response->code = 666; - $this->response->body = null; - - $this->client->expects($this->once()) - ->method('get') - ->with('/repos/joomla/joomla-framework/collaborators/elkuku') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->get('joomla', 'joomla-framework', 'elkuku'), - $this->equalTo($this->response->body) - ); - } - - /** - * Tests the Add method. - * - * @return void - */ - public function testAdd() - { - $this->response->code = 204; - - $this->client->expects($this->once()) - ->method('put') - ->with('/repos/joomla/joomla-framework/collaborators/elkuku') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->add('joomla', 'joomla-framework', 'elkuku'), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Tests the Remove method. - * - * @return void - */ - public function testRemove() - { - $this->response->code = 204; - - $this->client->expects($this->once()) - ->method('delete') - ->with('/repos/joomla/joomla-framework/collaborators/elkuku') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->remove('joomla', 'joomla-framework', 'elkuku'), - $this->equalTo(json_decode($this->sampleString)) - ); - } + /** + * @var Collaborators + */ + protected $object; + + /** + * Sets up the fixture, for example, opens a network connection. + * This method is called before a test is executed. + * + * @since 1.0 + * + * @return void + */ + protected function setUp(): void + { + parent::setUp(); + + $this->object = new Collaborators($this->options, $this->client); + } + + /** + * Tests the GetList method. + * + * @return void + */ + public function testGetList() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/repos/joomla/joomla-framework/collaborators') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->getList('joomla', 'joomla-framework'), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Tests the Get method. + * + * @return void + */ + public function testGet() + { + $this->response->code = 204; + $this->response->body = true; + + $this->client->expects($this->once()) + ->method('get') + ->with('/repos/joomla/joomla-framework/collaborators/elkuku') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->get('joomla', 'joomla-framework', 'elkuku'), + $this->equalTo($this->response->body) + ); + } + + /** + * Tests the GetNegative method. + * + * @return void + */ + public function testGetNegative() + { + $this->response->code = 404; + $this->response->body = false; + + $this->client->expects($this->once()) + ->method('get') + ->with('/repos/joomla/joomla-framework/collaborators/elkuku') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->get('joomla', 'joomla-framework', 'elkuku'), + $this->equalTo($this->response->body) + ); + } + + /** + * Tests the GetUnexpected method. + * + * @return void + */ + public function testGetUnexpected() + { + $this->expectException(\UnexpectedValueException::class); + + $this->response->code = 666; + $this->response->body = null; + + $this->client->expects($this->once()) + ->method('get') + ->with('/repos/joomla/joomla-framework/collaborators/elkuku') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->get('joomla', 'joomla-framework', 'elkuku'), + $this->equalTo($this->response->body) + ); + } + + /** + * Tests the Add method. + * + * @return void + */ + public function testAdd() + { + $this->response->code = 204; + + $this->client->expects($this->once()) + ->method('put') + ->with('/repos/joomla/joomla-framework/collaborators/elkuku') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->add('joomla', 'joomla-framework', 'elkuku'), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Tests the Remove method. + * + * @return void + */ + public function testRemove() + { + $this->response->code = 204; + + $this->client->expects($this->once()) + ->method('delete') + ->with('/repos/joomla/joomla-framework/collaborators/elkuku') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->remove('joomla', 'joomla-framework', 'elkuku'), + $this->equalTo(json_decode($this->sampleString)) + ); + } } diff --git a/Tests/Package/Repositories/CommentsTest.php b/Tests/Package/Repositories/CommentsTest.php index ecfada10..0b6e441d 100644 --- a/Tests/Package/Repositories/CommentsTest.php +++ b/Tests/Package/Repositories/CommentsTest.php @@ -1,4 +1,5 @@ object = new Comments($this->options, $this->client); - } - - /** - * Tests the GetListRepository method. - * - * @return void - */ - public function testGetListRepository() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/repos/joomla/joomla-framework/comments') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->getListRepository('joomla', 'joomla-framework'), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Tests the GetList method. - * - * @return void - */ - public function testGetList() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/repos/joomla/joomla-framework/commits/123/comments') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->getList('joomla', 'joomla-framework', '123'), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Tests the Get method. - * - * @return void - */ - public function testGet() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/repos/joomla/joomla-framework/comments/123') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->get('joomla', 'joomla-framework', 123), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Tests the Edit method. - * - * @return void - */ - public function testEdit() - { - $this->client->expects($this->once()) - ->method('patch') - ->with('/repos/joomla/joomla-framework/comments/123') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->edit('joomla', 'joomla-framework', 123, 'My Comment'), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Tests the Delete method. - * - * @return void - */ - public function testDelete() - { - $this->response->code = 204; - - $this->client->expects($this->once()) - ->method('delete') - ->with('/repos/joomla/joomla-framework/comments/123') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->delete('joomla', 'joomla-framework', 123), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Tests the Create method. - * - * @return void - */ - public function testCreate() - { - $this->response->code = 201; - - $this->client->expects($this->once()) - ->method('post') - ->with('/repos/joomla/joomla-framework/commits/123abc/comments') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->create('joomla', 'joomla-framework', '123abc', 'My Comment', 456, 'path/file.php', 789), - $this->equalTo(json_decode($this->sampleString)) - ); - } + /** + * @var Comments + */ + protected $object; + + /** + * Sets up the fixture, for example, opens a network connection. + * This method is called before a test is executed. + * + * @since 1.0 + * + * @return void + */ + protected function setUp(): void + { + parent::setUp(); + + $this->object = new Comments($this->options, $this->client); + } + + /** + * Tests the GetListRepository method. + * + * @return void + */ + public function testGetListRepository() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/repos/joomla/joomla-framework/comments') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->getListRepository('joomla', 'joomla-framework'), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Tests the GetList method. + * + * @return void + */ + public function testGetList() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/repos/joomla/joomla-framework/commits/123/comments') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->getList('joomla', 'joomla-framework', '123'), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Tests the Get method. + * + * @return void + */ + public function testGet() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/repos/joomla/joomla-framework/comments/123') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->get('joomla', 'joomla-framework', 123), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Tests the Edit method. + * + * @return void + */ + public function testEdit() + { + $this->client->expects($this->once()) + ->method('patch') + ->with('/repos/joomla/joomla-framework/comments/123') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->edit('joomla', 'joomla-framework', 123, 'My Comment'), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Tests the Delete method. + * + * @return void + */ + public function testDelete() + { + $this->response->code = 204; + + $this->client->expects($this->once()) + ->method('delete') + ->with('/repos/joomla/joomla-framework/comments/123') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->delete('joomla', 'joomla-framework', 123), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Tests the Create method. + * + * @return void + */ + public function testCreate() + { + $this->response->code = 201; + + $this->client->expects($this->once()) + ->method('post') + ->with('/repos/joomla/joomla-framework/commits/123abc/comments') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->create('joomla', 'joomla-framework', '123abc', 'My Comment', 456, 'path/file.php', 789), + $this->equalTo(json_decode($this->sampleString)) + ); + } } diff --git a/Tests/Package/Repositories/CommitsTest.php b/Tests/Package/Repositories/CommitsTest.php index 50999a97..1d7e9065 100644 --- a/Tests/Package/Repositories/CommitsTest.php +++ b/Tests/Package/Repositories/CommitsTest.php @@ -1,4 +1,5 @@ object = new Commits($this->options, $this->client); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Repositories\Commits::get() - * - * @return void - * - * @since 1.0 - */ - public function testGet() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/repos/joomla/joomla-platform/commits/abc1234') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->get('joomla', 'joomla-platform', 'abc1234'), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Repositories\Commits::get() - * - * @return void - * - * @since 1.0 - */ - public function testGetFailure() - { - $this->expectException(\DomainException::class); - $this->expectExceptionMessage('Generic Error'); - - $this->response->code = 500; - $this->response->body = $this->errorString; - - $this->client->expects($this->once()) - ->method('get') - ->with('/repos/joomla/joomla-platform/commits/abc1234') - ->will($this->returnValue($this->response)); - - $this->object->get('joomla', 'joomla-platform', 'abc1234'); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Repositories\Commits::getList() - * - * @return void - * - * @since 1.0 - */ - public function testGetList() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/repos/joomla/joomla-platform/commits') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->getList('joomla', 'joomla-platform'), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Repositories\Commits::getList() - * - * @return void - * - * @since 1.0 - */ - public function testGetListFailure() - { - $this->expectException(\DomainException::class); - $this->expectExceptionMessage('Generic Error'); - - $this->response->code = 500; - $this->response->body = $this->errorString; - - $this->client->expects($this->once()) - ->method('get') - ->with('/repos/joomla/joomla-platform/commits') - ->will($this->returnValue($this->response)); - - $this->object->getList('joomla', 'joomla-platform'); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Repositories\Commits::compare() - * - * @return void - * - * @since 1.0 - */ - public function testCompare() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/repos/joomla/joomla-platform/compare/123abc...456def') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->compare('joomla', 'joomla-platform', '123abc', '456def'), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Repositories\Commits::getSha() - * - * @return void - * - * @since 1.0 - */ - public function testgetSha() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/repos/{user}/{repo}/commits/{ref}') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->getSha('{user}', '{repo}', '{ref}'), - $this->equalTo($this->sampleString) - ); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Repositories\Commits::getSha() - * - * @return void - * - * @since 1.0 - */ - public function testgetShaFailure() - { - $this->expectException(UnexpectedResponseException::class); - $this->expectExceptionMessage('Invalid response received from GitHub.'); - - $this->response->code = 666; - - $this->client->expects($this->once()) - ->method('get') - ->with('/repos/{user}/{repo}/commits/{ref}') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->getSha('{user}', '{repo}', '{ref}'), - $this->equalTo($this->sampleString) - ); - } + /** + * @var Commits Object under test. + * @since 12.1 + */ + protected $object; + + /** + * Sets up the fixture, for example, opens a network connection. + * This method is called before a test is executed. + * + * @return void + * + * @since 1.0 + */ + protected function setUp(): void + { + parent::setUp(); + + $this->object = new Commits($this->options, $this->client); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Repositories\Commits::get() + * + * @return void + * + * @since 1.0 + */ + public function testGet() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/repos/joomla/joomla-platform/commits/abc1234') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->get('joomla', 'joomla-platform', 'abc1234'), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Repositories\Commits::get() + * + * @return void + * + * @since 1.0 + */ + public function testGetFailure() + { + $this->expectException(\DomainException::class); + $this->expectExceptionMessage('Generic Error'); + + $this->response->code = 500; + $this->response->body = $this->errorString; + + $this->client->expects($this->once()) + ->method('get') + ->with('/repos/joomla/joomla-platform/commits/abc1234') + ->will($this->returnValue($this->response)); + + $this->object->get('joomla', 'joomla-platform', 'abc1234'); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Repositories\Commits::getList() + * + * @return void + * + * @since 1.0 + */ + public function testGetList() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/repos/joomla/joomla-platform/commits') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->getList('joomla', 'joomla-platform'), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Repositories\Commits::getList() + * + * @return void + * + * @since 1.0 + */ + public function testGetListFailure() + { + $this->expectException(\DomainException::class); + $this->expectExceptionMessage('Generic Error'); + + $this->response->code = 500; + $this->response->body = $this->errorString; + + $this->client->expects($this->once()) + ->method('get') + ->with('/repos/joomla/joomla-platform/commits') + ->will($this->returnValue($this->response)); + + $this->object->getList('joomla', 'joomla-platform'); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Repositories\Commits::compare() + * + * @return void + * + * @since 1.0 + */ + public function testCompare() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/repos/joomla/joomla-platform/compare/123abc...456def') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->compare('joomla', 'joomla-platform', '123abc', '456def'), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Repositories\Commits::getSha() + * + * @return void + * + * @since 1.0 + */ + public function testgetSha() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/repos/{user}/{repo}/commits/{ref}') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->getSha('{user}', '{repo}', '{ref}'), + $this->equalTo($this->sampleString) + ); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Repositories\Commits::getSha() + * + * @return void + * + * @since 1.0 + */ + public function testgetShaFailure() + { + $this->expectException(UnexpectedResponseException::class); + $this->expectExceptionMessage('Invalid response received from GitHub.'); + + $this->response->code = 666; + + $this->client->expects($this->once()) + ->method('get') + ->with('/repos/{user}/{repo}/commits/{ref}') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->getSha('{user}', '{repo}', '{ref}'), + $this->equalTo($this->sampleString) + ); + } } diff --git a/Tests/Package/Repositories/ContentsTest.php b/Tests/Package/Repositories/ContentsTest.php index b95917b2..a3467a42 100644 --- a/Tests/Package/Repositories/ContentsTest.php +++ b/Tests/Package/Repositories/ContentsTest.php @@ -1,4 +1,5 @@ object = new Contents($this->options, $this->client); - } - - /** - * Tests the GetReadme method. - * - * @return void - */ - public function testGetReadme() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/repos/joomla/joomla-platform/readme') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->getReadme('joomla', 'joomla-platform'), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Tests the GetReadmeRef method. - * - * @return void - */ - public function testGetReadmeRef() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/repos/joomla/joomla-platform/readme?ref=123abc') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->getReadme('joomla', 'joomla-platform', '123abc'), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Tests the Get method. - * - * @return void - */ - 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)); - - $this->assertThat( - $this->object->get('joomla', 'joomla-platform', 'path/to/file.php'), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Tests the GetRef method. - * - * @return void - */ - 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)); - - $this->assertThat( - $this->object->get('joomla', 'joomla-platform', 'path/to/file.php', '123abc'), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Tests the GetArchiveLink method. - * - * @return void - */ - public function testGetArchiveLink() - { - $this->response->code = 302; - - $this->client->expects($this->once()) - ->method('get') - ->with('/repos/joomla/joomla-platform/zipball') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->getArchiveLink('joomla', 'joomla-platform'), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Tests the GetArchiveLinkRef method. - * - * @return void - */ - public function testGetArchiveLinkRef() - { - $this->response->code = 302; - - $this->client->expects($this->once()) - ->method('get') - ->with('/repos/joomla/joomla-platform/zipball?ref=123abc') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->getArchiveLink('joomla', 'joomla-platform', 'zipball', '123abc'), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Tests the GetArchiveLinkInvalidFormat method. - * - * @return void - */ - public function testGetArchiveLinkInvalidFormat() - { - $this->expectException(\UnexpectedValueException::class); - - $this->response->code = 302; - - $this->object->getArchiveLink('joomla', 'joomla-platform', 'invalid'); - } - - /** - * Tests the create method. - * - * @return void - */ - public function testCreate() - { - $this->response->code = 201; - - $this->client->expects($this->once()) - ->method('put') - ->with('/repos/joomla/joomla-platform/contents/src/foo') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->create( - 'joomla', 'joomla-platform', 'src/foo', 'my Message', 'ABC123def', 'xxbranch', - 'eddieajau', 'eddieajau@example.com', 'elkuku', 'elkuku@example.com' - ), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Tests the create method with missing author e-mail. - * - * @return void - */ - public function testCreateFail1() - { - $this->expectException(\UnexpectedValueException::class); - - $this->object->create( - 'joomla', 'joomla-platform', 'src/foo', 'my Message', 'ABC123def', 'xxbranch', - 'eddieajau', '', 'elkuku', 'elkuku@example.com' - ); - } - - /** - * Tests the create method with missing committer e-mail. - * - * @return void - */ - public function testCreateFail2() - { - $this->expectException(\UnexpectedValueException::class); - - $this->object->create( - 'joomla', 'joomla-platform', 'src/foo', 'my Message', 'ABC123def', 'xxbranch', - 'eddieajau', 'eddieajau@example.com', 'elkuku', '' - ); - } - - /** - * Tests the update method. - * - * @return void - */ - public function testUpdate() - { - $this->client->expects($this->once()) - ->method('put') - ->with('/repos/joomla/joomla-platform/contents/src/foo') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->update( - 'joomla', 'joomla-platform', 'src/foo', 'my Message', 'ABC123def', 'abcd1234', 'xxbranch', - 'eddieajau', 'eddieajau@example.com', 'elkuku', 'elkuku@example.com' - ), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Tests the update method with missing author e-mail. - * - * @return void - */ - public function testUpdateFail1() - { - $this->expectException(\UnexpectedValueException::class); - - $this->object->update( - 'joomla', 'joomla-platform', 'src/foo', 'my Message', 'ABC123def', 'abcd1234', 'xxbranch', - 'eddieajau', '', 'elkuku', 'elkuku@example.com' - ); - } - - /** - * Tests the update method with missing committer e-mail. - * - * @return void - */ - public function testUpdateFail2() - { - $this->expectException(\UnexpectedValueException::class); - - $this->object->update( - 'joomla', 'joomla-platform', 'src/foo', 'my Message', 'ABC123def', 'abcd1234', 'xxbranch', - 'eddieajau', 'eddieajau@example.com', 'elkuku', '' - ); - } - - /** - * Tests the delete method. - * - * @return void - */ - public function testDelete() - { - $this->client->expects($this->once()) - ->method('delete') - ->with('/repos/joomla/joomla-platform/contents/src/foo') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->delete( - 'joomla', 'joomla-platform', 'src/foo', 'my Message', 'ABC123def', 'xxbranch', - 'eddieajau', 'eddieajau@example.com', 'elkuku', 'elkuku@example.com' - ), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Tests the delete method with missing author e-mail. - * - * @return void - */ - public function testDeleteFail1() - { - $this->expectException(\UnexpectedValueException::class); - - $this->object->delete( - 'joomla', 'joomla-platform', 'src/foo', 'my Message', 'ABC123def', 'xxbranch', - 'eddieajau', '', 'elkuku', 'elkuku@example.com' - ); - } - - /** - * Tests the update method with missing committer e-mail. - * - * @return void - */ - public function testDeleteFail2() - { - $this->expectException(\UnexpectedValueException::class); - - $this->object->delete( - 'joomla', 'joomla-platform', 'src/foo', 'my Message', 'ABC123def', 'xxbranch', - 'eddieajau', 'eddieajau@example.com', 'elkuku', '' - ); - } + /** + * @var Contents + */ + protected $object; + + /** + * Sets up the fixture, for example, opens a network connection. + * This method is called before a test is executed. + * + * @since 1.0 + * + * @return void + */ + protected function setUp(): void + { + parent::setUp(); + + $this->object = new Contents($this->options, $this->client); + } + + /** + * Tests the GetReadme method. + * + * @return void + */ + public function testGetReadme() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/repos/joomla/joomla-platform/readme') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->getReadme('joomla', 'joomla-platform'), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Tests the GetReadmeRef method. + * + * @return void + */ + public function testGetReadmeRef() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/repos/joomla/joomla-platform/readme?ref=123abc') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->getReadme('joomla', 'joomla-platform', '123abc'), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Tests the Get method. + * + * @return void + */ + 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)); + + $this->assertThat( + $this->object->get('joomla', 'joomla-platform', 'path/to/file.php'), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Tests the GetRef method. + * + * @return void + */ + 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)); + + $this->assertThat( + $this->object->get('joomla', 'joomla-platform', 'path/to/file.php', '123abc'), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Tests the GetArchiveLink method. + * + * @return void + */ + public function testGetArchiveLink() + { + $this->response->code = 302; + + $this->client->expects($this->once()) + ->method('get') + ->with('/repos/joomla/joomla-platform/zipball') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->getArchiveLink('joomla', 'joomla-platform'), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Tests the GetArchiveLinkRef method. + * + * @return void + */ + public function testGetArchiveLinkRef() + { + $this->response->code = 302; + + $this->client->expects($this->once()) + ->method('get') + ->with('/repos/joomla/joomla-platform/zipball?ref=123abc') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->getArchiveLink('joomla', 'joomla-platform', 'zipball', '123abc'), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Tests the GetArchiveLinkInvalidFormat method. + * + * @return void + */ + public function testGetArchiveLinkInvalidFormat() + { + $this->expectException(\UnexpectedValueException::class); + + $this->response->code = 302; + + $this->object->getArchiveLink('joomla', 'joomla-platform', 'invalid'); + } + + /** + * Tests the create method. + * + * @return void + */ + public function testCreate() + { + $this->response->code = 201; + + $this->client->expects($this->once()) + ->method('put') + ->with('/repos/joomla/joomla-platform/contents/src/foo') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->create( + 'joomla', + 'joomla-platform', + 'src/foo', + 'my Message', + 'ABC123def', + 'xxbranch', + 'eddieajau', + 'eddieajau@example.com', + 'elkuku', + 'elkuku@example.com' + ), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Tests the create method with missing author e-mail. + * + * @return void + */ + public function testCreateFail1() + { + $this->expectException(\UnexpectedValueException::class); + + $this->object->create( + 'joomla', + 'joomla-platform', + 'src/foo', + 'my Message', + 'ABC123def', + 'xxbranch', + 'eddieajau', + '', + 'elkuku', + 'elkuku@example.com' + ); + } + + /** + * Tests the create method with missing committer e-mail. + * + * @return void + */ + public function testCreateFail2() + { + $this->expectException(\UnexpectedValueException::class); + + $this->object->create( + 'joomla', + 'joomla-platform', + 'src/foo', + 'my Message', + 'ABC123def', + 'xxbranch', + 'eddieajau', + 'eddieajau@example.com', + 'elkuku', + '' + ); + } + + /** + * Tests the update method. + * + * @return void + */ + public function testUpdate() + { + $this->client->expects($this->once()) + ->method('put') + ->with('/repos/joomla/joomla-platform/contents/src/foo') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->update( + 'joomla', + 'joomla-platform', + 'src/foo', + 'my Message', + 'ABC123def', + 'abcd1234', + 'xxbranch', + 'eddieajau', + 'eddieajau@example.com', + 'elkuku', + 'elkuku@example.com' + ), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Tests the update method with missing author e-mail. + * + * @return void + */ + public function testUpdateFail1() + { + $this->expectException(\UnexpectedValueException::class); + + $this->object->update( + 'joomla', + 'joomla-platform', + 'src/foo', + 'my Message', + 'ABC123def', + 'abcd1234', + 'xxbranch', + 'eddieajau', + '', + 'elkuku', + 'elkuku@example.com' + ); + } + + /** + * Tests the update method with missing committer e-mail. + * + * @return void + */ + public function testUpdateFail2() + { + $this->expectException(\UnexpectedValueException::class); + + $this->object->update( + 'joomla', + 'joomla-platform', + 'src/foo', + 'my Message', + 'ABC123def', + 'abcd1234', + 'xxbranch', + 'eddieajau', + 'eddieajau@example.com', + 'elkuku', + '' + ); + } + + /** + * Tests the delete method. + * + * @return void + */ + public function testDelete() + { + $this->client->expects($this->once()) + ->method('delete') + ->with('/repos/joomla/joomla-platform/contents/src/foo') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->delete( + 'joomla', + 'joomla-platform', + 'src/foo', + 'my Message', + 'ABC123def', + 'xxbranch', + 'eddieajau', + 'eddieajau@example.com', + 'elkuku', + 'elkuku@example.com' + ), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Tests the delete method with missing author e-mail. + * + * @return void + */ + public function testDeleteFail1() + { + $this->expectException(\UnexpectedValueException::class); + + $this->object->delete( + 'joomla', + 'joomla-platform', + 'src/foo', + 'my Message', + 'ABC123def', + 'xxbranch', + 'eddieajau', + '', + 'elkuku', + 'elkuku@example.com' + ); + } + + /** + * Tests the update method with missing committer e-mail. + * + * @return void + */ + public function testDeleteFail2() + { + $this->expectException(\UnexpectedValueException::class); + + $this->object->delete( + 'joomla', + 'joomla-platform', + 'src/foo', + 'my Message', + 'ABC123def', + 'xxbranch', + 'eddieajau', + 'eddieajau@example.com', + 'elkuku', + '' + ); + } } diff --git a/Tests/Package/Repositories/DeploymentsTest.php b/Tests/Package/Repositories/DeploymentsTest.php index eccf027f..a135b672 100644 --- a/Tests/Package/Repositories/DeploymentsTest.php +++ b/Tests/Package/Repositories/DeploymentsTest.php @@ -1,4 +1,5 @@ object = new Deployments($this->options, $this->client); - } - - /** - * Tests the GetList method. - * - * @return void - */ - 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)); - - $this->assertThat( - $this->object->getList('{owner}', '{repo}', '{sha}', '{ref}', '{task}', '{environment}'), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Tests the Create method. - * - * @return void - */ - public function testCreate() - { - $this->response->code = 201; - - $this->client->expects($this->once()) - ->method('post') - ->with('/repos/{owner}/{repo}/deployments') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->create( - '{owner}', '{repo}', '{ref}', '{task}', '{automerge}', array('{requiredContexts}'), - '{payload}', '{environment}', '{description}' - ), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Tests the Create method. - * - * @return void - */ - public function testCreateMergeConflict() - { - $this->expectException(\RuntimeException::class); - - $this->response->code = 409; - - $this->client->expects($this->once()) - ->method('post') - ->with('/repos/{owner}/{repo}/deployments') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->create('{owner}', '{repo}', '{ref}'), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Tests the Create method. - * - * @return void - */ - public function testCreateFailure() - { - $this->expectException(\UnexpectedValueException::class); - - $this->response->code = 666; - - $this->client->expects($this->once()) - ->method('post') - ->with('/repos/{owner}/{repo}/deployments') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->create('{owner}', '{repo}', '{ref}'), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Tests the GetDeploymentStatuses method. - * - * @return void - */ - public function testGetDeploymentStatuses() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/repos/{owner}/{repo}/deployments/123/statuses') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->getDeploymentStatuses('{owner}', '{repo}', 123), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Tests the CreateStatus method. - * - * @return void - */ - public function testCreateStatus() - { - $this->response->code = 201; - - $this->client->expects($this->once()) - ->method('post') - ->with('/repos/{owner}/{repo}/deployments/123/statuses') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->createStatus('{owner}', '{repo}', 123, 'success', '{targetUrl}', '{description}'), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Tests the CreateStatus method. - * - * @return void - */ - public function testCreateStatusFailure() - { - $this->expectException(\InvalidArgumentException::class); - - $this->object->createStatus('{owner}', '{repo}', 123, '{invalid}'); - } + /** + * @var Deployments + */ + protected $object; + + /** + * Sets up the fixture, for example, opens a network connection. + * This method is called before a test is executed. + * + * @since 1.0 + * + * @return void + */ + protected function setUp(): void + { + parent::setUp(); + + $this->object = new Deployments($this->options, $this->client); + } + + /** + * Tests the GetList method. + * + * @return void + */ + 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)); + + $this->assertThat( + $this->object->getList('{owner}', '{repo}', '{sha}', '{ref}', '{task}', '{environment}'), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Tests the Create method. + * + * @return void + */ + public function testCreate() + { + $this->response->code = 201; + + $this->client->expects($this->once()) + ->method('post') + ->with('/repos/{owner}/{repo}/deployments') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->create( + '{owner}', + '{repo}', + '{ref}', + '{task}', + '{automerge}', + ['{requiredContexts}'], + '{payload}', + '{environment}', + '{description}' + ), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Tests the Create method. + * + * @return void + */ + public function testCreateMergeConflict() + { + $this->expectException(\RuntimeException::class); + + $this->response->code = 409; + + $this->client->expects($this->once()) + ->method('post') + ->with('/repos/{owner}/{repo}/deployments') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->create('{owner}', '{repo}', '{ref}'), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Tests the Create method. + * + * @return void + */ + public function testCreateFailure() + { + $this->expectException(\UnexpectedValueException::class); + + $this->response->code = 666; + + $this->client->expects($this->once()) + ->method('post') + ->with('/repos/{owner}/{repo}/deployments') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->create('{owner}', '{repo}', '{ref}'), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Tests the GetDeploymentStatuses method. + * + * @return void + */ + public function testGetDeploymentStatuses() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/repos/{owner}/{repo}/deployments/123/statuses') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->getDeploymentStatuses('{owner}', '{repo}', 123), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Tests the CreateStatus method. + * + * @return void + */ + public function testCreateStatus() + { + $this->response->code = 201; + + $this->client->expects($this->once()) + ->method('post') + ->with('/repos/{owner}/{repo}/deployments/123/statuses') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->createStatus('{owner}', '{repo}', 123, 'success', '{targetUrl}', '{description}'), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Tests the CreateStatus method. + * + * @return void + */ + public function testCreateStatusFailure() + { + $this->expectException(\InvalidArgumentException::class); + + $this->object->createStatus('{owner}', '{repo}', 123, '{invalid}'); + } } diff --git a/Tests/Package/Repositories/DownloadsTest.php b/Tests/Package/Repositories/DownloadsTest.php index 953f8511..9e11539e 100644 --- a/Tests/Package/Repositories/DownloadsTest.php +++ b/Tests/Package/Repositories/DownloadsTest.php @@ -1,4 +1,5 @@ object = new Downloads($this->options, $this->client); - } - - /** - * Tests the GetList method. - * - * @return void - */ - public function testGetList() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/repos/joomla/joomla-platform/downloads') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->getList('joomla', 'joomla-platform'), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Tests the Get method. - * - * @return void - */ - public function testGet() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/repos/joomla/joomla-platform/downloads/123abc') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->get('joomla', 'joomla-platform', '123abc'), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Tests the Create method. - * - * @return void - */ - public function testCreate() - { - $this->expectException(\RuntimeException::class); - $this->expectExceptionMessage('The GitHub API no longer supports creating downloads. The Releases API should be used instead.'); - - $this->object->create('joomla', 'joomla-platform', 'aaa.zip', 1234, 'Description', 'content_type'); - } - - /** - * Tests the Upload method. - * - * @return void - */ - public function testUpload() - { - $this->expectException(\RuntimeException::class); - $this->expectExceptionMessage('The GitHub API no longer supports creating downloads. The Releases API should be used instead.'); - - $this->object->upload( - 'joomla', 'joomla-platform', 123, 'a/b/aaa.zip', 'acl', 201, 'aaa.zip', '123abc', '123abc', '123abc', 'content_type', '@aaa.zip' - ); - } - - /** - * Tests the Delete method. - * - * @return void - */ - public function testDelete() - { - $this->response->code = 204; - - $this->client->expects($this->once()) - ->method('delete') - ->with('/repos/joomla/joomla-platform/downloads/123') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->delete('joomla', 'joomla-platform', 123), - $this->equalTo(json_decode($this->sampleString)) - ); - } + /** + * @var Downloads + */ + protected $object; + + /** + * Sets up the fixture, for example, opens a network connection. + * This method is called before a test is executed. + * + * @since 1.0 + * + * @return void + */ + protected function setUp(): void + { + parent::setUp(); + + $this->object = new Downloads($this->options, $this->client); + } + + /** + * Tests the GetList method. + * + * @return void + */ + public function testGetList() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/repos/joomla/joomla-platform/downloads') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->getList('joomla', 'joomla-platform'), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Tests the Get method. + * + * @return void + */ + public function testGet() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/repos/joomla/joomla-platform/downloads/123abc') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->get('joomla', 'joomla-platform', '123abc'), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Tests the Create method. + * + * @return void + */ + public function testCreate() + { + $this->expectException(\RuntimeException::class); + $this->expectExceptionMessage('The GitHub API no longer supports creating downloads. The Releases API should be used instead.'); + + $this->object->create('joomla', 'joomla-platform', 'aaa.zip', 1234, 'Description', 'content_type'); + } + + /** + * Tests the Upload method. + * + * @return void + */ + public function testUpload() + { + $this->expectException(\RuntimeException::class); + $this->expectExceptionMessage('The GitHub API no longer supports creating downloads. The Releases API should be used instead.'); + + $this->object->upload( + 'joomla', + 'joomla-platform', + 123, + 'a/b/aaa.zip', + 'acl', + 201, + 'aaa.zip', + '123abc', + '123abc', + '123abc', + 'content_type', + '@aaa.zip' + ); + } + + /** + * Tests the Delete method. + * + * @return void + */ + public function testDelete() + { + $this->response->code = 204; + + $this->client->expects($this->once()) + ->method('delete') + ->with('/repos/joomla/joomla-platform/downloads/123') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->delete('joomla', 'joomla-platform', 123), + $this->equalTo(json_decode($this->sampleString)) + ); + } } diff --git a/Tests/Package/Repositories/ForksTest.php b/Tests/Package/Repositories/ForksTest.php index 255c5ef1..a6b6cc20 100755 --- a/Tests/Package/Repositories/ForksTest.php +++ b/Tests/Package/Repositories/ForksTest.php @@ -1,4 +1,5 @@ object = new Forks($this->options, $this->client); - } - - /** - * Tests the create method - * - * @return void - */ - public function testCreate() - { - $this->response->code = 202; - - // Build the request data. - $data = json_encode( - array( - 'org' => 'jenkins-jools' - ) - ); - - $this->client->expects($this->once()) - ->method('post') - ->with('/repos/joomla/joomla-platform/forks', $data) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->create('joomla', 'joomla-platform', 'jenkins-jools'), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Tests the create method - failure - * - * @return void - */ - public function testCreateFailure() - { - $this->expectException(\DomainException::class); - - $this->response->code = 500; - $this->response->body = $this->errorString; - - // Build the request data. - $data = json_encode( - array() - ); - - $this->client->expects($this->once()) - ->method('post') - ->with('/repos/joomla/joomla-platform/forks', $data) - ->will($this->returnValue($this->response)); - - $this->object->create('joomla', 'joomla-platform', ''); - } - - /** - * Tests the getList method - * - * @return void - */ - public function testGetList() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/repos/joomla/joomla-platform/forks') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->getList('joomla', 'joomla-platform'), - $this->equalTo(json_decode($this->response->body)) - ); - } - - /** - * Tests the getList method - failure - * - * @return void - */ - public function testGetListFailure() - { - $this->expectException(\DomainException::class); - - $this->response->code = 500; - $this->response->body = $this->errorString; - - $this->client->expects($this->once()) - ->method('get') - ->with('/repos/joomla/joomla-platform/forks') - ->will($this->returnValue($this->response)); - - $this->object->getList('joomla', 'joomla-platform'); - } + /** + * @var Forks Object under test. + * @since 11.4 + */ + protected $object; + + /** + * Sets up the fixture, for example, opens a network connection. + * This method is called before a test is executed. + * + * @access protected + * + * @return void + */ + protected function setUp(): void + { + parent::setUp(); + + $this->object = new Forks($this->options, $this->client); + } + + /** + * Tests the create method + * + * @return void + */ + public function testCreate() + { + $this->response->code = 202; + + // Build the request data. + $data = json_encode( + [ + 'org' => 'jenkins-jools', + ] + ); + + $this->client->expects($this->once()) + ->method('post') + ->with('/repos/joomla/joomla-platform/forks', $data) + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->create('joomla', 'joomla-platform', 'jenkins-jools'), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Tests the create method - failure + * + * @return void + */ + public function testCreateFailure() + { + $this->expectException(\DomainException::class); + + $this->response->code = 500; + $this->response->body = $this->errorString; + + // Build the request data. + $data = json_encode( + [] + ); + + $this->client->expects($this->once()) + ->method('post') + ->with('/repos/joomla/joomla-platform/forks', $data) + ->will($this->returnValue($this->response)); + + $this->object->create('joomla', 'joomla-platform', ''); + } + + /** + * Tests the getList method + * + * @return void + */ + public function testGetList() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/repos/joomla/joomla-platform/forks') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->getList('joomla', 'joomla-platform'), + $this->equalTo(json_decode($this->response->body)) + ); + } + + /** + * Tests the getList method - failure + * + * @return void + */ + public function testGetListFailure() + { + $this->expectException(\DomainException::class); + + $this->response->code = 500; + $this->response->body = $this->errorString; + + $this->client->expects($this->once()) + ->method('get') + ->with('/repos/joomla/joomla-platform/forks') + ->will($this->returnValue($this->response)); + + $this->object->getList('joomla', 'joomla-platform'); + } } diff --git a/Tests/Package/Repositories/HooksTest.php b/Tests/Package/Repositories/HooksTest.php index 83f8b6af..4bf84c16 100644 --- a/Tests/Package/Repositories/HooksTest.php +++ b/Tests/Package/Repositories/HooksTest.php @@ -1,4 +1,5 @@ object = new Hooks($this->options, $this->client); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Repositories\Hooks::create() - * - * @return void - * - * @since 1.0 - */ - public function testCreate() - { - $this->response->code = 201; - - $hook = new \stdClass; - $hook->name = 'acunote'; - $hook->config = array('token' => '123456789'); - $hook->events = array('push', 'public'); - $hook->active = true; - - $this->client->expects($this->once()) - ->method('post') - ->with('/repos/joomla/joomla-platform/hooks', json_encode($hook)) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->create('joomla', 'joomla-platform', 'acunote', array('token' => '123456789'), array('push', 'public')), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Repositories\Hooks::create() - * - * @return void - * - * @since 1.0 - */ - public function testCreateFailure() - { - $exception = false; - - $this->response->code = 500; - $this->response->body = $this->errorString; - - $hook = new \stdClass; - $hook->name = 'acunote'; - $hook->config = array('token' => '123456789'); - $hook->events = array('push', 'public'); - $hook->active = true; - - $this->client->expects($this->once()) - ->method('post') - ->with('/repos/joomla/joomla-platform/hooks', json_encode($hook)) - ->will($this->returnValue($this->response)); - - try - { - $this->object->create('joomla', 'joomla-platform', 'acunote', array('token' => '123456789'), array('push', 'public')); - } - catch (\DomainException $e) - { - $exception = true; - - $this->assertThat( - $e->getMessage(), - $this->equalTo(json_decode($this->errorString)->message) - ); - } - - $this->assertTrue($exception); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Repositories\Hooks::create() - * - * Unauthorised event - * - * @return void - * - * @since 1.0 - */ - public function testCreateUnauthorisedEvent() - { - $this->expectException(\RuntimeException::class); - - $this->object->create('joomla', 'joomla-platform', 'acunote', array('token' => '123456789'), array('push', 'faker')); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Repositories\Hooks::delete() - * - * @return void - * - * @since 1.0 - */ - public function testDelete() - { - $this->response->code = 204; - - $this->client->expects($this->once()) - ->method('delete') - ->with('/repos/joomla/joomla-platform/hooks/42') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->delete('joomla', 'joomla-platform', 42), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Repositories\Hooks::delete() - * - * Simulated failure - * - * @return void - * - * @since 1.0 - */ - public function testDeleteFailure() - { - $exception = false; - - $this->response->code = 500; - $this->response->body = $this->errorString; - - $this->client->expects($this->once()) - ->method('delete') - ->with('/repos/joomla/joomla-platform/hooks/42') - ->will($this->returnValue($this->response)); - - try - { - $this->object->delete('joomla', 'joomla-platform', 42); - } - catch (\DomainException $e) - { - $exception = true; - - $this->assertThat( - $e->getMessage(), - $this->equalTo(json_decode($this->errorString)->message) - ); - } - - $this->assertTrue($exception); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Repositories\Hooks::edit() - * - * @return void - * - * @since 1.0 - */ - public function testEdit() - { - $hook = '{' - . '"name":"acunote","config":{"token":"123456789"},"events":["push","public"],' - . '"add_events":["watch"],"remove_events":["watch"],"active":true' - . '}'; - - $this->client->expects($this->once()) - ->method('patch') - ->with('/repos/joomla/joomla-platform/hooks/42', $hook) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->edit('joomla', 'joomla-platform', 42, 'acunote', array('token' => '123456789'), - array('push', 'public'), array('watch'), array('watch') - ), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Repositories\Hooks::edit() - * - * Simulated failure - * - * @return void - * - * @since 1.0 - */ - public function testEditFailure() - { - $exception = false; - - $this->response->code = 500; - $this->response->body = $this->errorString; - - $hook = '{' - . '"name":"acunote","config":{"token":"123456789"},"events":["push","public"],' - . '"add_events":["watch"],"remove_events":["watch"],"active":true' - . '}'; - - $this->client->expects($this->once()) - ->method('patch') - ->with('/repos/joomla/joomla-platform/hooks/42', $hook) - ->will($this->returnValue($this->response)); - - try - { - $this->object->edit('joomla', 'joomla-platform', 42, 'acunote', array('token' => '123456789'), - array('push', 'public'), array('watch'), array('watch') - ); - } - catch (\DomainException $e) - { - $exception = true; - - $this->assertThat( - $e->getMessage(), - $this->equalTo(json_decode($this->errorString)->message) - ); - } - - $this->assertTrue($exception); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Repositories\Hooks::edit() - * - * Unauthorised event - * - * @return void - * - * @since 1.0 - */ - public function testEditUnauthorisedEvent() - { - $this->expectException(\RuntimeException::class); - - $this->object->edit('joomla', 'joomla-platform', 42, 'acunote', array('token' => '123456789'), array('invalid')); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Repositories\Hooks::edit() - * - * Unauthorised event - * - * @return void - * - * @since 1.0 - */ - public function testEditUnauthorisedAddEvent() - { - $this->expectException(\RuntimeException::class); - - $this->object->edit('joomla', 'joomla-platform', 42, 'acunote', array('token' => '123456789'), array('push'), array('invalid')); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Repositories\Hooks::edit() - * - * Unauthorised event - * - * @return void - * - * @since 1.0 - */ - public function testEditUnauthorisedRemoveEvent() - { - $this->expectException(\RuntimeException::class); - - $this->object->edit( - 'joomla', 'joomla-platform', 42, 'acunote', array('token' => '123456789'), array('push'), array('push'), array('invalid') - ); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Repositories\Hooks::get() - * - * @return void - * - * @since 1.0 - */ - public function testGet() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/repos/joomla/joomla-platform/hooks/42') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->get('joomla', 'joomla-platform', 42), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Repositories\Hooks::get() - * - * Failure - * - * @return void - * - * @since 1.0 - */ - public function testGetFailure() - { - $this->expectException(\DomainException::class); - - $this->response->code = 500; - $this->response->body = $this->errorString; - - $this->client->expects($this->once()) - ->method('get') - ->with('/repos/joomla/joomla-platform/hooks/42') - ->will($this->returnValue($this->response)); - - $this->object->get('joomla', 'joomla-platform', 42); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Repositories\Hooks::getList() - * - * @return void - * - * @since 1.0 - */ - public function testGetList() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/repos/joomla/joomla-platform/hooks') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->getList('joomla', 'joomla-platform'), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Repositories\Hooks::getList() - * - * Failure - * - * @return void - * - * @since 1.0 - */ - public function testGetListFailure() - { - $this->expectException(\DomainException::class); - - $this->response->code = 500; - $this->response->body = $this->errorString; - - $this->client->expects($this->once()) - ->method('get') - ->with('/repos/joomla/joomla-platform/hooks') - ->will($this->returnValue($this->response)); - - $this->object->getList('joomla', 'joomla-platform'); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Repositories\Hooks::test() - * - * @return void - * - * @since 1.0 - */ - public function testTest() - { - $this->response->code = 204; - - $this->client->expects($this->once()) - ->method('post') - ->with('/repos/joomla/joomla-platform/hooks/42/test') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->test('joomla', 'joomla-platform', 42), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Repositories\Hooks::test() - * - * Failure - * - * @return void - * - * @since 1.0 - */ - public function testTestFailure() - { - $this->expectException(\DomainException::class); - - $this->response->code = 500; - $this->response->body = $this->errorString; - - $this->client->expects($this->once()) - ->method('post') - ->with('/repos/joomla/joomla-platform/hooks/42/test') - ->will($this->returnValue($this->response)); - - $this->object->test('joomla', 'joomla-platform', 42); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Repositories\Hooks::ping() - * - * @return void - * - * @since 1.0 - */ - public function testPing() - { - $this->response->code = 204; - - $this->client->expects($this->once()) - ->method('post') - ->with('/repos/{user}/{repo}/hooks/42/pings') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->ping('{user}', '{repo}', 42), - $this->equalTo(json_decode($this->sampleString)) - ); - } + /** + * @var Hooks Object under test. + * @since 12.3 + */ + protected $object; + + /** + * Sets up the fixture, for example, opens a network connection. + * This method is called before a test is executed. + * + * @return void + * + * @since 1.0 + */ + protected function setUp(): void + { + parent::setUp(); + + $this->object = new Hooks($this->options, $this->client); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Repositories\Hooks::create() + * + * @return void + * + * @since 1.0 + */ + public function testCreate() + { + $this->response->code = 201; + + $hook = new \stdClass(); + $hook->name = 'acunote'; + $hook->config = ['token' => '123456789']; + $hook->events = ['push', 'public']; + $hook->active = true; + + $this->client->expects($this->once()) + ->method('post') + ->with('/repos/joomla/joomla-platform/hooks', json_encode($hook)) + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->create('joomla', 'joomla-platform', 'acunote', ['token' => '123456789'], ['push', 'public']), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Repositories\Hooks::create() + * + * @return void + * + * @since 1.0 + */ + public function testCreateFailure() + { + $exception = false; + + $this->response->code = 500; + $this->response->body = $this->errorString; + + $hook = new \stdClass(); + $hook->name = 'acunote'; + $hook->config = ['token' => '123456789']; + $hook->events = ['push', 'public']; + $hook->active = true; + + $this->client->expects($this->once()) + ->method('post') + ->with('/repos/joomla/joomla-platform/hooks', json_encode($hook)) + ->will($this->returnValue($this->response)); + + try { + $this->object->create('joomla', 'joomla-platform', 'acunote', ['token' => '123456789'], ['push', 'public']); + } catch (\DomainException $e) { + $exception = true; + + $this->assertThat( + $e->getMessage(), + $this->equalTo(json_decode($this->errorString)->message) + ); + } + + $this->assertTrue($exception); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Repositories\Hooks::create() + * + * Unauthorised event + * + * @return void + * + * @since 1.0 + */ + public function testCreateUnauthorisedEvent() + { + $this->expectException(\RuntimeException::class); + + $this->object->create('joomla', 'joomla-platform', 'acunote', ['token' => '123456789'], ['push', 'faker']); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Repositories\Hooks::delete() + * + * @return void + * + * @since 1.0 + */ + public function testDelete() + { + $this->response->code = 204; + + $this->client->expects($this->once()) + ->method('delete') + ->with('/repos/joomla/joomla-platform/hooks/42') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->delete('joomla', 'joomla-platform', 42), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Repositories\Hooks::delete() + * + * Simulated failure + * + * @return void + * + * @since 1.0 + */ + public function testDeleteFailure() + { + $exception = false; + + $this->response->code = 500; + $this->response->body = $this->errorString; + + $this->client->expects($this->once()) + ->method('delete') + ->with('/repos/joomla/joomla-platform/hooks/42') + ->will($this->returnValue($this->response)); + + try { + $this->object->delete('joomla', 'joomla-platform', 42); + } catch (\DomainException $e) { + $exception = true; + + $this->assertThat( + $e->getMessage(), + $this->equalTo(json_decode($this->errorString)->message) + ); + } + + $this->assertTrue($exception); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Repositories\Hooks::edit() + * + * @return void + * + * @since 1.0 + */ + public function testEdit() + { + $hook = '{' + . '"name":"acunote","config":{"token":"123456789"},"events":["push","public"],' + . '"add_events":["watch"],"remove_events":["watch"],"active":true' + . '}'; + + $this->client->expects($this->once()) + ->method('patch') + ->with('/repos/joomla/joomla-platform/hooks/42', $hook) + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->edit( + 'joomla', + 'joomla-platform', + 42, + 'acunote', + ['token' => '123456789'], + ['push', 'public'], + ['watch'], + ['watch'] + ), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Repositories\Hooks::edit() + * + * Simulated failure + * + * @return void + * + * @since 1.0 + */ + public function testEditFailure() + { + $exception = false; + + $this->response->code = 500; + $this->response->body = $this->errorString; + + $hook = '{' + . '"name":"acunote","config":{"token":"123456789"},"events":["push","public"],' + . '"add_events":["watch"],"remove_events":["watch"],"active":true' + . '}'; + + $this->client->expects($this->once()) + ->method('patch') + ->with('/repos/joomla/joomla-platform/hooks/42', $hook) + ->will($this->returnValue($this->response)); + + try { + $this->object->edit( + 'joomla', + 'joomla-platform', + 42, + 'acunote', + ['token' => '123456789'], + ['push', 'public'], + ['watch'], + ['watch'] + ); + } catch (\DomainException $e) { + $exception = true; + + $this->assertThat( + $e->getMessage(), + $this->equalTo(json_decode($this->errorString)->message) + ); + } + + $this->assertTrue($exception); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Repositories\Hooks::edit() + * + * Unauthorised event + * + * @return void + * + * @since 1.0 + */ + public function testEditUnauthorisedEvent() + { + $this->expectException(\RuntimeException::class); + + $this->object->edit('joomla', 'joomla-platform', 42, 'acunote', ['token' => '123456789'], ['invalid']); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Repositories\Hooks::edit() + * + * Unauthorised event + * + * @return void + * + * @since 1.0 + */ + public function testEditUnauthorisedAddEvent() + { + $this->expectException(\RuntimeException::class); + + $this->object->edit('joomla', 'joomla-platform', 42, 'acunote', ['token' => '123456789'], ['push'], ['invalid']); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Repositories\Hooks::edit() + * + * Unauthorised event + * + * @return void + * + * @since 1.0 + */ + public function testEditUnauthorisedRemoveEvent() + { + $this->expectException(\RuntimeException::class); + + $this->object->edit( + 'joomla', + 'joomla-platform', + 42, + 'acunote', + ['token' => '123456789'], + ['push'], + ['push'], + ['invalid'] + ); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Repositories\Hooks::get() + * + * @return void + * + * @since 1.0 + */ + public function testGet() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/repos/joomla/joomla-platform/hooks/42') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->get('joomla', 'joomla-platform', 42), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Repositories\Hooks::get() + * + * Failure + * + * @return void + * + * @since 1.0 + */ + public function testGetFailure() + { + $this->expectException(\DomainException::class); + + $this->response->code = 500; + $this->response->body = $this->errorString; + + $this->client->expects($this->once()) + ->method('get') + ->with('/repos/joomla/joomla-platform/hooks/42') + ->will($this->returnValue($this->response)); + + $this->object->get('joomla', 'joomla-platform', 42); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Repositories\Hooks::getList() + * + * @return void + * + * @since 1.0 + */ + public function testGetList() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/repos/joomla/joomla-platform/hooks') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->getList('joomla', 'joomla-platform'), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Repositories\Hooks::getList() + * + * Failure + * + * @return void + * + * @since 1.0 + */ + public function testGetListFailure() + { + $this->expectException(\DomainException::class); + + $this->response->code = 500; + $this->response->body = $this->errorString; + + $this->client->expects($this->once()) + ->method('get') + ->with('/repos/joomla/joomla-platform/hooks') + ->will($this->returnValue($this->response)); + + $this->object->getList('joomla', 'joomla-platform'); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Repositories\Hooks::test() + * + * @return void + * + * @since 1.0 + */ + public function testTest() + { + $this->response->code = 204; + + $this->client->expects($this->once()) + ->method('post') + ->with('/repos/joomla/joomla-platform/hooks/42/test') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->test('joomla', 'joomla-platform', 42), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Repositories\Hooks::test() + * + * Failure + * + * @return void + * + * @since 1.0 + */ + public function testTestFailure() + { + $this->expectException(\DomainException::class); + + $this->response->code = 500; + $this->response->body = $this->errorString; + + $this->client->expects($this->once()) + ->method('post') + ->with('/repos/joomla/joomla-platform/hooks/42/test') + ->will($this->returnValue($this->response)); + + $this->object->test('joomla', 'joomla-platform', 42); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Repositories\Hooks::ping() + * + * @return void + * + * @since 1.0 + */ + public function testPing() + { + $this->response->code = 204; + + $this->client->expects($this->once()) + ->method('post') + ->with('/repos/{user}/{repo}/hooks/42/pings') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->ping('{user}', '{repo}', 42), + $this->equalTo(json_decode($this->sampleString)) + ); + } } diff --git a/Tests/Package/Repositories/KeysTest.php b/Tests/Package/Repositories/KeysTest.php index eb3e5cba..0243ff46 100644 --- a/Tests/Package/Repositories/KeysTest.php +++ b/Tests/Package/Repositories/KeysTest.php @@ -1,4 +1,5 @@ object = new Keys($this->options, $this->client); - } - - /** - * Tests the GetList method. - * - * @return void - */ - public function testGetList() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/repos/joomla/joomla-platform/keys') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->getList('joomla', 'joomla-platform'), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Tests the Get method. - * - * @return void - */ - public function testGet() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/repos/joomla/joomla-platform/keys/1') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->get('joomla', 'joomla-platform', 1), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Tests the Create method. - * - * @return void - */ - public function testCreate() - { - $this->response->code = 201; - - $this->client->expects($this->once()) - ->method('post') - ->with('/repos/joomla/joomla-platform/keys') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->create('joomla', 'joomla-platform', 'email@example.com', '123abc'), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Tests the Edit method. - * - * @return void - */ - public function testEdit() - { - $this->client->expects($this->once()) - ->method('patch') - ->with('/repos/joomla/joomla-platform/keys/1') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->edit('joomla', 'joomla-platform', 1, 'email@example.com', '123abc'), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Tests the Delete method. - * - * @return void - */ - public function testDelete() - { - $this->response->code = 204; - $this->response->body = true; - - $this->client->expects($this->once()) - ->method('delete') - ->with('/repos/joomla/joomla-platform/keys/1') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->delete('joomla', 'joomla-platform', 1), - $this->equalTo($this->response->body) - ); - } + /** + * @var Keys + */ + protected $object; + + /** + * Sets up the fixture, for example, opens a network connection. + * This method is called before a test is executed. + * + * @since 1.0 + * + * @return void + */ + protected function setUp(): void + { + parent::setUp(); + + $this->object = new Keys($this->options, $this->client); + } + + /** + * Tests the GetList method. + * + * @return void + */ + public function testGetList() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/repos/joomla/joomla-platform/keys') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->getList('joomla', 'joomla-platform'), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Tests the Get method. + * + * @return void + */ + public function testGet() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/repos/joomla/joomla-platform/keys/1') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->get('joomla', 'joomla-platform', 1), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Tests the Create method. + * + * @return void + */ + public function testCreate() + { + $this->response->code = 201; + + $this->client->expects($this->once()) + ->method('post') + ->with('/repos/joomla/joomla-platform/keys') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->create('joomla', 'joomla-platform', 'email@example.com', '123abc'), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Tests the Edit method. + * + * @return void + */ + public function testEdit() + { + $this->client->expects($this->once()) + ->method('patch') + ->with('/repos/joomla/joomla-platform/keys/1') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->edit('joomla', 'joomla-platform', 1, 'email@example.com', '123abc'), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Tests the Delete method. + * + * @return void + */ + public function testDelete() + { + $this->response->code = 204; + $this->response->body = true; + + $this->client->expects($this->once()) + ->method('delete') + ->with('/repos/joomla/joomla-platform/keys/1') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->delete('joomla', 'joomla-platform', 1), + $this->equalTo($this->response->body) + ); + } } diff --git a/Tests/Package/Repositories/MergingTest.php b/Tests/Package/Repositories/MergingTest.php index 128535da..c7e0c3f1 100644 --- a/Tests/Package/Repositories/MergingTest.php +++ b/Tests/Package/Repositories/MergingTest.php @@ -1,4 +1,5 @@ object = new Merging($this->options, $this->client); - } - - /** - * Tests the Perform method. - * - * @return void - */ - public function testPerform() - { - $this->response->code = 201; - - $this->client->expects($this->once()) - ->method('post') - ->with('/repos/joomla/joomla-platform/merges') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->perform('joomla', 'joomla-platform', '123', '456', 'My Message'), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Tests the Perform method. - * - * @return void - */ - public function testPerformNoOp() - { - $this->expectException(\UnexpectedValueException::class); - - $this->response->code = 204; - - $this->client->expects($this->once()) - ->method('post') - ->with('/repos/joomla/joomla-platform/merges') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->perform('joomla', 'joomla-platform', '123', '456', 'My Message'), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Tests the Perform method. - * - * @return void - */ - public function testPerformMissing() - { - $this->expectException(\UnexpectedValueException::class); - - $this->response->code = 404; - - $this->client->expects($this->once()) - ->method('post') - ->with('/repos/joomla/joomla-platform/merges') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->perform('joomla', 'joomla-platform', '123', '456', 'My Message'), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Tests the Perform method. - * - * @return void - */ - public function testPerformConflict() - { - $this->expectException(\UnexpectedValueException::class); - - $this->response->code = 409; - - $this->client->expects($this->once()) - ->method('post') - ->with('/repos/joomla/joomla-platform/merges') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->perform('joomla', 'joomla-platform', '123', '456', 'My Message'), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Tests the Perform method. - * - * @return void - */ - public function testPerformUnexpected() - { - $this->expectException(\UnexpectedValueException::class); - - $this->response->code = 666; - - $this->client->expects($this->once()) - ->method('post') - ->with('/repos/joomla/joomla-platform/merges') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->perform('joomla', 'joomla-platform', '123', '456', 'My Message'), - $this->equalTo(json_decode($this->sampleString)) - ); - } + /** + * @var Merging + * @since 1.0 + */ + protected $object; + + /** + * Sets up the fixture, for example, opens a network connection. + * This method is called before a test is executed. + * + * @since 1.0 + * + * @return void + */ + protected function setUp(): void + { + parent::setUp(); + + $this->object = new Merging($this->options, $this->client); + } + + /** + * Tests the Perform method. + * + * @return void + */ + public function testPerform() + { + $this->response->code = 201; + + $this->client->expects($this->once()) + ->method('post') + ->with('/repos/joomla/joomla-platform/merges') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->perform('joomla', 'joomla-platform', '123', '456', 'My Message'), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Tests the Perform method. + * + * @return void + */ + public function testPerformNoOp() + { + $this->expectException(\UnexpectedValueException::class); + + $this->response->code = 204; + + $this->client->expects($this->once()) + ->method('post') + ->with('/repos/joomla/joomla-platform/merges') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->perform('joomla', 'joomla-platform', '123', '456', 'My Message'), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Tests the Perform method. + * + * @return void + */ + public function testPerformMissing() + { + $this->expectException(\UnexpectedValueException::class); + + $this->response->code = 404; + + $this->client->expects($this->once()) + ->method('post') + ->with('/repos/joomla/joomla-platform/merges') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->perform('joomla', 'joomla-platform', '123', '456', 'My Message'), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Tests the Perform method. + * + * @return void + */ + public function testPerformConflict() + { + $this->expectException(\UnexpectedValueException::class); + + $this->response->code = 409; + + $this->client->expects($this->once()) + ->method('post') + ->with('/repos/joomla/joomla-platform/merges') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->perform('joomla', 'joomla-platform', '123', '456', 'My Message'), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Tests the Perform method. + * + * @return void + */ + public function testPerformUnexpected() + { + $this->expectException(\UnexpectedValueException::class); + + $this->response->code = 666; + + $this->client->expects($this->once()) + ->method('post') + ->with('/repos/joomla/joomla-platform/merges') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->perform('joomla', 'joomla-platform', '123', '456', 'My Message'), + $this->equalTo(json_decode($this->sampleString)) + ); + } } diff --git a/Tests/Package/Repositories/PagesTest.php b/Tests/Package/Repositories/PagesTest.php index 242de302..e723d41d 100644 --- a/Tests/Package/Repositories/PagesTest.php +++ b/Tests/Package/Repositories/PagesTest.php @@ -16,77 +16,77 @@ */ class PagesTest extends GitHubTestCase { - /** - * @var Pages - */ - protected $object; + /** + * @var Pages + */ + protected $object; - /** - * Sets up the fixture, for example, opens a network connection. - * This method is called before a test is executed. - * - * @since 1.0 - * - * @return void - */ - protected function setUp(): void - { - parent::setUp(); + /** + * Sets up the fixture, for example, opens a network connection. + * This method is called before a test is executed. + * + * @since 1.0 + * + * @return void + */ + protected function setUp(): void + { + parent::setUp(); - $this->object = new Pages($this->options, $this->client); - } + $this->object = new Pages($this->options, $this->client); + } - /** - * Tests the GetInfo method. - * - * @return void - */ - public function testGetInfo() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/repos/{owner}/{repo}/pages') - ->will($this->returnValue($this->response)); + /** + * Tests the GetInfo method. + * + * @return void + */ + public function testGetInfo() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/repos/{owner}/{repo}/pages') + ->will($this->returnValue($this->response)); - $this->assertThat( - $this->object->getInfo('{owner}', '{repo}'), - $this->equalTo(json_decode($this->sampleString)) - ); - } + $this->assertThat( + $this->object->getInfo('{owner}', '{repo}'), + $this->equalTo(json_decode($this->sampleString)) + ); + } - /** - * Tests the GetList method. - * - * @return void - */ - public function testGetList() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/repos/{owner}/{repo}/pages/builds') - ->will($this->returnValue($this->response)); + /** + * Tests the GetList method. + * + * @return void + */ + public function testGetList() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/repos/{owner}/{repo}/pages/builds') + ->will($this->returnValue($this->response)); - $this->assertThat( - $this->object->getList('{owner}', '{repo}'), - $this->equalTo(json_decode($this->sampleString)) - ); - } + $this->assertThat( + $this->object->getList('{owner}', '{repo}'), + $this->equalTo(json_decode($this->sampleString)) + ); + } - /** - * Tests the GetLatest method. - * - * @return void - */ - public function testGetLatest() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/repos/{owner}/{repo}/pages/builds/latest') - ->will($this->returnValue($this->response)); + /** + * Tests the GetLatest method. + * + * @return void + */ + public function testGetLatest() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/repos/{owner}/{repo}/pages/builds/latest') + ->will($this->returnValue($this->response)); - $this->assertThat( - $this->object->getLatest('{owner}', '{repo}'), - $this->equalTo(json_decode($this->sampleString)) - ); - } + $this->assertThat( + $this->object->getLatest('{owner}', '{repo}'), + $this->equalTo(json_decode($this->sampleString)) + ); + } } diff --git a/Tests/Package/Repositories/ReleasesTest.php b/Tests/Package/Repositories/ReleasesTest.php index 9d4c27e7..ddd596c8 100644 --- a/Tests/Package/Repositories/ReleasesTest.php +++ b/Tests/Package/Repositories/ReleasesTest.php @@ -16,272 +16,271 @@ */ class ReleasesTest extends GitHubTestCase { - /** - * @var Releases Object under test. - * @since 1.0 - */ - protected $object; - - /** - * Sets up the fixture, for example, opens a network connection. - * This method is called before a test is executed. - * - * @since 1.0 - * - * @return void - */ - protected function setUp(): void - { - parent::setUp(); - - $this->object = new Releases($this->options, $this->client); - } - - /** - * Tests the get method - * - * @return void - */ - public function testGet() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/repos/joomla/joomla-platform/releases/12345', array(), 0) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->get('joomla', 'joomla-platform', '12345'), - $this->equalTo(json_decode($this->response->body)) - ); - } - - /** - * Tests the create method - * - * @return void - */ - public function testCreate() - { - $this->response->code = 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, array(), 0) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->create('joomla', 'joomla-platform', '0.1', 'targetCommitish', 'master', 'New release', false, false), - $this->equalTo(json_decode($this->response->body)) - ); - } - - /** - * Tests the create method with failure. - * - * @return void - */ - public function testCreateFailure() - { - $this->response->code = 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, array(), 0) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->create('joomla', 'joomla-platform', '0.1', 'targetCommitish', 'master', 'New release', false, false), - $this->equalTo(json_decode($this->response->body)) - ); - } - - /** - * Tests the edit method. - * - * @return void - */ - public function testEdit() - { - $releaseId = 123; - - $data = '{"tag_name":"tagName","target_commitish":"targetCommitish","name":"name","body":"body","draft":"draft","prerelease":"preRelease"}'; - $this->client->expects($this->once()) - ->method('patch') - ->with('/repos/joomla/joomla-platform/releases/' . $releaseId, $data, array(), 0) - - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->edit('joomla', 'joomla-platform', $releaseId, 'tagName', 'targetCommitish', 'name', 'body', 'draft', 'preRelease'), - $this->equalTo(json_decode($this->response->body)) - ); - } - - /** - * Tests the getList method. - * - * @return void - */ - public function testGetList() - { - $this->response->code = 200; - $this->response->body = '[{"tag_name":"1"},{"tag_name":"2"}]'; - - $releases = array(); - - foreach (json_decode($this->response->body) as $i => $release) - { - $releases[$i + 1] = $release; - } - - $this->client->expects($this->once()) - ->method('get') - ->with('/repos/joomla/joomla-platform/releases', array(), 0) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->getList('joomla', 'joomla-platform'), - $this->equalTo($releases) - ); - } - - /** - * Tests the delete method - * - * @return void - */ - public function testDelete() - { - $this->response->code = 204; - - $this->client->expects($this->once()) - ->method('delete') - ->with('/repos/joomla/joomla-platform/releases/123') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->delete('joomla', 'joomla-platform', '123'), - $this->equalTo(json_decode($this->response->body)) - ); - } - - /** - * Tests the getLatest method. - * - * @return void - */ - public function testGetLatest() - { - $this->response->code = 200; - $this->response->body = '[]'; - - $releases = array(); - - $this->client->expects($this->once()) - ->method('get') - ->with('/repos/joomla/joomla-platform/releases/latest', array(), 0) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->getLatest('joomla', 'joomla-platform'), - $this->equalTo($releases) - ); - } - - /** - * Tests the getByTag method - * - * @return void - */ - public function testGetByTag() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/repos/joomla/joomla-platform/releases/tags/{tag}', array(), 0) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->getByTag('joomla', 'joomla-platform', '{tag}'), - $this->equalTo(json_decode($this->response->body)) - ); - } - - /** - * Tests the getListAssets method - * - * @return void - */ - public function testGetListAssets() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/repos/joomla/joomla-platform/releases/123/assets', array(), 0) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->getListAssets('joomla', 'joomla-platform', 123), - $this->equalTo(json_decode($this->response->body)) - ); - } - - /** - * Tests the getAsset method - * - * @return void - */ - public function testGetAsset() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/repos/joomla/joomla-platform/releases/assets/123', array(), 0) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->getAsset('joomla', 'joomla-platform', 123), - $this->equalTo(json_decode($this->response->body)) - ); - } - - /** - * Tests the editAsset method - * - * @return void - */ - public function testEditAsset() - { - $data = '{"name":"{name}","label":"{label}"}'; - - $this->client->expects($this->once()) - ->method('patch') - ->with('/repos/joomla/joomla-platform/releases/assets/123', $data, array(), 0) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->editAsset('joomla', 'joomla-platform', 123, '{name}', '{label}'), - $this->equalTo(json_decode($this->response->body)) - ); - } - - /** - * Tests the deleteAsset method - * - * @return void - */ - public function testDeleteAsset() - { - $this->response->code = 204; - $this->response->body = true; - - $this->client->expects($this->once()) - ->method('delete') - ->with('/repos/joomla/joomla-platform/releases/assets/123', array(), 0) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->deleteAsset('joomla', 'joomla-platform', 123), - $this->equalTo($this->response->body) - ); - } + /** + * @var Releases Object under test. + * @since 1.0 + */ + protected $object; + + /** + * Sets up the fixture, for example, opens a network connection. + * This method is called before a test is executed. + * + * @since 1.0 + * + * @return void + */ + protected function setUp(): void + { + parent::setUp(); + + $this->object = new Releases($this->options, $this->client); + } + + /** + * Tests the get method + * + * @return void + */ + public function testGet() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/repos/joomla/joomla-platform/releases/12345', [], 0) + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->get('joomla', 'joomla-platform', '12345'), + $this->equalTo(json_decode($this->response->body)) + ); + } + + /** + * Tests the create method + * + * @return void + */ + public function testCreate() + { + $this->response->code = 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)); + + $this->assertThat( + $this->object->create('joomla', 'joomla-platform', '0.1', 'targetCommitish', 'master', 'New release', false, false), + $this->equalTo(json_decode($this->response->body)) + ); + } + + /** + * Tests the create method with failure. + * + * @return void + */ + public function testCreateFailure() + { + $this->response->code = 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)); + + $this->assertThat( + $this->object->create('joomla', 'joomla-platform', '0.1', 'targetCommitish', 'master', 'New release', false, false), + $this->equalTo(json_decode($this->response->body)) + ); + } + + /** + * Tests the edit method. + * + * @return void + */ + public function testEdit() + { + $releaseId = 123; + + $data = '{"tag_name":"tagName","target_commitish":"targetCommitish","name":"name","body":"body","draft":"draft","prerelease":"preRelease"}'; + $this->client->expects($this->once()) + ->method('patch') + ->with('/repos/joomla/joomla-platform/releases/' . $releaseId, $data, [], 0) + + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->edit('joomla', 'joomla-platform', $releaseId, 'tagName', 'targetCommitish', 'name', 'body', 'draft', 'preRelease'), + $this->equalTo(json_decode($this->response->body)) + ); + } + + /** + * Tests the getList method. + * + * @return void + */ + public function testGetList() + { + $this->response->code = 200; + $this->response->body = '[{"tag_name":"1"},{"tag_name":"2"}]'; + + $releases = []; + + foreach (json_decode($this->response->body) 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)); + + $this->assertThat( + $this->object->getList('joomla', 'joomla-platform'), + $this->equalTo($releases) + ); + } + + /** + * Tests the delete method + * + * @return void + */ + public function testDelete() + { + $this->response->code = 204; + + $this->client->expects($this->once()) + ->method('delete') + ->with('/repos/joomla/joomla-platform/releases/123') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->delete('joomla', 'joomla-platform', '123'), + $this->equalTo(json_decode($this->response->body)) + ); + } + + /** + * Tests the getLatest method. + * + * @return void + */ + public function testGetLatest() + { + $this->response->code = 200; + $this->response->body = '[]'; + + $releases = []; + + $this->client->expects($this->once()) + ->method('get') + ->with('/repos/joomla/joomla-platform/releases/latest', [], 0) + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->getLatest('joomla', 'joomla-platform'), + $this->equalTo($releases) + ); + } + + /** + * Tests the getByTag method + * + * @return void + */ + public function testGetByTag() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/repos/joomla/joomla-platform/releases/tags/{tag}', [], 0) + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->getByTag('joomla', 'joomla-platform', '{tag}'), + $this->equalTo(json_decode($this->response->body)) + ); + } + + /** + * Tests the getListAssets method + * + * @return void + */ + public function testGetListAssets() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/repos/joomla/joomla-platform/releases/123/assets', [], 0) + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->getListAssets('joomla', 'joomla-platform', 123), + $this->equalTo(json_decode($this->response->body)) + ); + } + + /** + * Tests the getAsset method + * + * @return void + */ + public function testGetAsset() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/repos/joomla/joomla-platform/releases/assets/123', [], 0) + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->getAsset('joomla', 'joomla-platform', 123), + $this->equalTo(json_decode($this->response->body)) + ); + } + + /** + * Tests the editAsset method + * + * @return void + */ + public function testEditAsset() + { + $data = '{"name":"{name}","label":"{label}"}'; + + $this->client->expects($this->once()) + ->method('patch') + ->with('/repos/joomla/joomla-platform/releases/assets/123', $data, [], 0) + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->editAsset('joomla', 'joomla-platform', 123, '{name}', '{label}'), + $this->equalTo(json_decode($this->response->body)) + ); + } + + /** + * Tests the deleteAsset method + * + * @return void + */ + public function testDeleteAsset() + { + $this->response->code = 204; + $this->response->body = true; + + $this->client->expects($this->once()) + ->method('delete') + ->with('/repos/joomla/joomla-platform/releases/assets/123', [], 0) + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->deleteAsset('joomla', 'joomla-platform', 123), + $this->equalTo($this->response->body) + ); + } } diff --git a/Tests/Package/Repositories/StatisticsTest.php b/Tests/Package/Repositories/StatisticsTest.php index c4baa718..4aefac24 100644 --- a/Tests/Package/Repositories/StatisticsTest.php +++ b/Tests/Package/Repositories/StatisticsTest.php @@ -16,136 +16,136 @@ */ class StatisticsTest extends GitHubTestCase { - /** - * @var Statistics Object under test. - * @since 11.4 - */ - protected $object; - - /** - * Sets up the fixture, for example, opens a network connection. - * This method is called before a test is executed. - * - * @access protected - * - * @return void - */ - protected function setUp(): void - { - parent::setUp(); - - $this->object = new Statistics($this->options, $this->client); - } - - /** - * Tests the getListContributors method. - * - * @return void - */ - public function testContributors() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/repos/joomla/joomla-framework/stats/contributors') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->getListContributors('joomla', 'joomla-framework'), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Tests the getActivityData method. - * - * @return void - */ - public function testActivity() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/repos/joomla/joomla-framework/stats/commit_activity') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->getActivityData('joomla', 'joomla-framework'), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Tests the getCodeFrequency method. - * - * @return void - */ - public function testFrequency() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/repos/joomla/joomla-framework/stats/code_frequency') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->getCodeFrequency('joomla', 'joomla-framework'), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Tests the getParticipation method. - * - * @return void - */ - public function testParticipation() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/repos/joomla/joomla-framework/stats/participation') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->getParticipation('joomla', 'joomla-framework'), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Tests the getPunchCard method. - * - * @return void - */ - public function testPunchCard() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/repos/joomla/joomla-framework/stats/punch_card') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->getPunchCard('joomla', 'joomla-framework'), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Tests the ProcessResponse method with failure. - * - * @return void - */ - public function testProcessResponse202() - { - $this->expectException(\DomainException::class); - - $this->response->code = 202; - - $this->client->expects($this->once()) - ->method('get') - ->with('/repos/joomla/joomla-framework/stats/punch_card') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->getPunchCard('joomla', 'joomla-framework'), - $this->equalTo(json_decode($this->sampleString)) - ); - } + /** + * @var Statistics Object under test. + * @since 11.4 + */ + protected $object; + + /** + * Sets up the fixture, for example, opens a network connection. + * This method is called before a test is executed. + * + * @access protected + * + * @return void + */ + protected function setUp(): void + { + parent::setUp(); + + $this->object = new Statistics($this->options, $this->client); + } + + /** + * Tests the getListContributors method. + * + * @return void + */ + public function testContributors() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/repos/joomla/joomla-framework/stats/contributors') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->getListContributors('joomla', 'joomla-framework'), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Tests the getActivityData method. + * + * @return void + */ + public function testActivity() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/repos/joomla/joomla-framework/stats/commit_activity') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->getActivityData('joomla', 'joomla-framework'), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Tests the getCodeFrequency method. + * + * @return void + */ + public function testFrequency() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/repos/joomla/joomla-framework/stats/code_frequency') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->getCodeFrequency('joomla', 'joomla-framework'), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Tests the getParticipation method. + * + * @return void + */ + public function testParticipation() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/repos/joomla/joomla-framework/stats/participation') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->getParticipation('joomla', 'joomla-framework'), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Tests the getPunchCard method. + * + * @return void + */ + public function testPunchCard() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/repos/joomla/joomla-framework/stats/punch_card') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->getPunchCard('joomla', 'joomla-framework'), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Tests the ProcessResponse method with failure. + * + * @return void + */ + public function testProcessResponse202() + { + $this->expectException(\DomainException::class); + + $this->response->code = 202; + + $this->client->expects($this->once()) + ->method('get') + ->with('/repos/joomla/joomla-framework/stats/punch_card') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->getPunchCard('joomla', 'joomla-framework'), + $this->equalTo(json_decode($this->sampleString)) + ); + } } diff --git a/Tests/Package/Repositories/StatusesTest.php b/Tests/Package/Repositories/StatusesTest.php index 02e6d16d..d51a6b73 100755 --- a/Tests/Package/Repositories/StatusesTest.php +++ b/Tests/Package/Repositories/StatusesTest.php @@ -18,180 +18,180 @@ */ class StatusesTest extends GitHubTestCase { - /** - * @var Statuses Object under test. - * @since 11.4 - */ - protected $object; - - /** - * Sets up the fixture, for example, opens a network connection. - * This method is called before a test is executed. - * - * @access protected - * - * @return void - */ - protected function setUp(): void - { - parent::setUp(); - - $this->object = new Statuses($this->options, $this->client); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Repositories\Statuses::create() - * - * @return void - */ - public function testCreate() - { - $this->response->code = 201; - - // Build the request data. - $data = json_encode( - array( - 'state' => 'success', - 'target_url' => 'http://example.com/my_url', - 'description' => 'Success is the only option - failure is not.', - 'context' => 'Joomla/Test' - ) - ); - - $this->client->expects($this->once()) - ->method('post') - ->with('/repos/joomla/joomla-platform/statuses/6dcb09b5b57875f334f61aebed695e2e4193db5e', $data) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->create( - 'joomla', - 'joomla-platform', - '6dcb09b5b57875f334f61aebed695e2e4193db5e', - 'success', - 'http://example.com/my_url', - 'Success is the only option - failure is not.', - 'Joomla/Test' - ), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Repositories\Statuses::create() - * - * Failure - * - * @return void - */ - public function testCreateFailure() - { - $this->expectException(\DomainException::class); - - $this->response->code = 501; - $this->response->body = $this->errorString; - - // Build the request data. - $data = json_encode( - array( - 'state' => 'pending' - ) - ); - - $this->client->expects($this->once()) - ->method('post') - ->with('/repos/joomla/joomla-platform/statuses/6dcb09b5b57875f334f61aebed695e2e4193db5e', $data) - ->will($this->returnValue($this->response)); - - $this->object->create('joomla', 'joomla-platform', '6dcb09b5b57875f334f61aebed695e2e4193db5e', 'pending'); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Repositories\Statuses::create() - * - * Failure - * - * @return void - */ - public function testCreateInvalidState() - { - $this->expectException(\InvalidArgumentException::class); - - $this->response->code = 501; - $this->response->body = $this->errorString; - - $this->object->create('joomla', 'joomla-platform', '6dcb09b5b57875f334f61aebed695e2e4193db5e', 'INVALID'); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Repositories\Statuses::getList() - * - * @return void - */ - public function testGetList() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/repos/joomla/joomla-platform/statuses/6dcb09b5b57875f334f61aebed695e2e4193db5e') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->getList('joomla', 'joomla-platform', '6dcb09b5b57875f334f61aebed695e2e4193db5e'), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Repositories\Statuses::getList() - * - * Failure - * - * @return void - */ - public function testGetListFailure() - { - $this->expectException(\DomainException::class); - - $this->response->code = 500; - $this->response->body = $this->errorString; - - $this->client->expects($this->once()) - ->method('get') - ->with('/repos/joomla/joomla-platform/statuses/6dcb09b5b57875f334f61aebed695e2e4193db5e') - ->will($this->returnValue($this->response)); - - $this->object->getList('joomla', 'joomla-platform', '6dcb09b5b57875f334f61aebed695e2e4193db5e'); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Repositories\Statuses::getCombinedStatus() - * - * @return void - * - * @since 1.0 - */ - public function testGetCombinedStatus() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/repos/{user}/{repo}/commits/{sha}/status') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->getCombinedStatus('{user}', '{repo}', '{sha}'), - $this->equalTo(json_decode($this->sampleString)) - ); - } + /** + * @var Statuses Object under test. + * @since 11.4 + */ + protected $object; + + /** + * Sets up the fixture, for example, opens a network connection. + * This method is called before a test is executed. + * + * @access protected + * + * @return void + */ + protected function setUp(): void + { + parent::setUp(); + + $this->object = new Statuses($this->options, $this->client); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Repositories\Statuses::create() + * + * @return void + */ + public function testCreate() + { + $this->response->code = 201; + + // Build the request data. + $data = json_encode( + [ + 'state' => 'success', + 'target_url' => 'http://example.com/my_url', + 'description' => 'Success is the only option - failure is not.', + 'context' => 'Joomla/Test', + ] + ); + + $this->client->expects($this->once()) + ->method('post') + ->with('/repos/joomla/joomla-platform/statuses/6dcb09b5b57875f334f61aebed695e2e4193db5e', $data) + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->create( + 'joomla', + 'joomla-platform', + '6dcb09b5b57875f334f61aebed695e2e4193db5e', + 'success', + 'http://example.com/my_url', + 'Success is the only option - failure is not.', + 'Joomla/Test' + ), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Repositories\Statuses::create() + * + * Failure + * + * @return void + */ + public function testCreateFailure() + { + $this->expectException(\DomainException::class); + + $this->response->code = 501; + $this->response->body = $this->errorString; + + // Build the request data. + $data = json_encode( + [ + 'state' => 'pending', + ] + ); + + $this->client->expects($this->once()) + ->method('post') + ->with('/repos/joomla/joomla-platform/statuses/6dcb09b5b57875f334f61aebed695e2e4193db5e', $data) + ->will($this->returnValue($this->response)); + + $this->object->create('joomla', 'joomla-platform', '6dcb09b5b57875f334f61aebed695e2e4193db5e', 'pending'); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Repositories\Statuses::create() + * + * Failure + * + * @return void + */ + public function testCreateInvalidState() + { + $this->expectException(\InvalidArgumentException::class); + + $this->response->code = 501; + $this->response->body = $this->errorString; + + $this->object->create('joomla', 'joomla-platform', '6dcb09b5b57875f334f61aebed695e2e4193db5e', 'INVALID'); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Repositories\Statuses::getList() + * + * @return void + */ + public function testGetList() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/repos/joomla/joomla-platform/statuses/6dcb09b5b57875f334f61aebed695e2e4193db5e') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->getList('joomla', 'joomla-platform', '6dcb09b5b57875f334f61aebed695e2e4193db5e'), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Repositories\Statuses::getList() + * + * Failure + * + * @return void + */ + public function testGetListFailure() + { + $this->expectException(\DomainException::class); + + $this->response->code = 500; + $this->response->body = $this->errorString; + + $this->client->expects($this->once()) + ->method('get') + ->with('/repos/joomla/joomla-platform/statuses/6dcb09b5b57875f334f61aebed695e2e4193db5e') + ->will($this->returnValue($this->response)); + + $this->object->getList('joomla', 'joomla-platform', '6dcb09b5b57875f334f61aebed695e2e4193db5e'); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Repositories\Statuses::getCombinedStatus() + * + * @return void + * + * @since 1.0 + */ + public function testGetCombinedStatus() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/repos/{user}/{repo}/commits/{sha}/status') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->getCombinedStatus('{user}', '{repo}', '{sha}'), + $this->equalTo(json_decode($this->sampleString)) + ); + } } diff --git a/Tests/Package/RepositoriesTest.php b/Tests/Package/RepositoriesTest.php index a392afa4..667d5f0c 100644 --- a/Tests/Package/RepositoriesTest.php +++ b/Tests/Package/RepositoriesTest.php @@ -16,358 +16,362 @@ */ class RepositoriesTest extends GitHubTestCase { - /** - * @var Repositories - */ - protected $object; - - /** - * Sets up the fixture, for example, opens a network connection. - * This method is called before a test is executed. - * - * @since 1.0 - * - * @return void - */ - protected function setUp(): void - { - parent::setUp(); - - $this->object = new Repositories($this->options, $this->client); - } - - /** - * Tests the GetListOwn method. - * - * @return void - */ - public function testGetListOwn() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/user/repos?type=all&sort=full_name&direction=asc', array(), 0) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->getListOwn(), - $this->equalTo(json_decode($this->response->body)) - ); - } - - /** - * Tests the GetListOwn method. - * - * @return void - */ - public function testGetListOwnInvalidType() - { - $this->expectException(\RuntimeException::class); - - $this->object->getListOwn('INVALID'); - } - - /** - * Tests the GetListOwn method. - * - * @return void - */ - public function testGetListOwnInvalidSortField() - { - $this->expectException(\RuntimeException::class); - - $this->object->getListOwn('all', 'INVALID'); - } - - /** - * Tests the GetListOwn method. - * - * @return void - */ - public function testGetListOwnInvalidSortOrder() - { - $this->expectException(\RuntimeException::class); - - $this->object->getListOwn('all', 'full_name', 'INVALID'); - } - - /** - * Tests the GetListUser method. - * - * @return void - */ - public function testGetListUser() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/users/joomla/repos?type=all&sort=full_name&direction=asc', array(), 0) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->getListUser('joomla'), - $this->equalTo(json_decode($this->response->body)) - ); - } - - /** - * Tests the GetListUser method. - * - * @return void - */ - public function testGetListUserInvalidType() - { - $this->expectException(\RuntimeException::class); - - $this->object->getListUser('joomla', 'INVALID'); - } - - /** - * Tests the GetListUser method. - * - * @return void - */ - public function testGetListUserInvalidSortField() - { - $this->expectException(\RuntimeException::class); - - $this->object->getListUser('joomla', 'all', 'INVALID'); - } - - /** - * Tests the GetListUser method. - * - * @return void - */ - public function testGetListUserInvalidSortOrder() - { - $this->expectException(\RuntimeException::class); - - $this->object->getListUser('joomla', 'all', 'full_name', 'INVALID'); - } - - /** - * Tests the GetListOrg method. - * - * @return void - */ - public function testGetListOrg() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/orgs/joomla/repos?type=all', array(), 0) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->getListOrg('joomla'), - $this->equalTo(json_decode($this->response->body)) - ); - } - - /** - * Tests the GetList method. - * - * @return void - */ - public function testGetList() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/repositories', array(), 0) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->getList(), - $this->equalTo(json_decode($this->response->body)) - ); - } - - /** - * Tests the Create method. - * - * @return void - */ - public function testCreate() - { - $this->response->code = 201; - - $this->client->expects($this->once()) - ->method('post') - ->with('/user/repos', - '{"name":"joomla-test","description":"","homepage":"","private":false,"has_issues":false,' - . '"has_wiki":false,"has_downloads":false,"team_id":0,"auto_init":false,"gitignore_template":""}', - array(), 0 - ) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->create('joomla-test'), - $this->equalTo(json_decode($this->response->body)) - ); - } - - /** - * Tests the Create method. - * - * @return void - */ - public function testCreateWithOrg() - { - $this->response->code = 201; - - $this->client->expects($this->once()) - ->method('post') - ->with('/orgs/joomla.org/repos', - '{"name":"joomla-test","description":"","homepage":"","private":false,"has_issues":false,' - . '"has_wiki":false,"has_downloads":false,"team_id":0,"auto_init":false,"gitignore_template":""}', - array(), 0 - ) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->create('joomla-test', 'joomla.org'), - $this->equalTo(json_decode($this->response->body)) - ); - } - - /** - * Tests the Get method. - * - * @return void - */ - public function testGet() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/repos/joomla/joomla-cms', array(), 0) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->get('joomla', 'joomla-cms'), - $this->equalTo(json_decode($this->response->body)) - ); - } - - /** - * Tests the GetListOrg method. - * - * @return void - */ - public function testGetListOrgInvalidType() - { - $this->expectException(\RuntimeException::class); - - $this->object->getListOrg('joomla', 'INVALID'); - } - - /** - * Tests the Edit method. - * - * @return void - */ - public function testEdit() - { - $this->client->expects($this->once()) - ->method('patch') - ->with( - '/repos/joomla/joomla-test', - '{"name":"joomla-test-1","description":"","homepage":"","private":' - . 'false,"has_issues":false,"has_wiki":false,"has_downloads":false,"default_branch":""}', - array() - ) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->edit('joomla', 'joomla-test', 'joomla-test-1'), - $this->equalTo(json_decode($this->response->body)) - ); - } - - /** - * Tests the GetListContributors method. - * - * @return void - */ - public function testGetListContributors() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/repos/joomla/joomla-cms/contributors', array(), 0) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->getListContributors('joomla', 'joomla-cms'), - $this->equalTo(json_decode($this->response->body)) - ); - } - - /** - * Tests the GetListLanguages method. - * - * @return void - */ - public function testGetListLanguages() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/repos/joomla/joomla-cms/languages', array(), 0) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->getListLanguages('joomla', 'joomla-cms'), - $this->equalTo(json_decode($this->response->body)) - ); - } - - /** - * Tests the GetListTeams method. - * - * @return void - */ - public function testGetListTeams() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/repos/joomla/joomla-cms/teams', array(), 0) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->getListTeams('joomla', 'joomla-cms'), - $this->equalTo(json_decode($this->response->body)) - ); - } - - /** - * Tests the GetListTags method. - * - * @return void - */ - public function testGetListTags() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/repos/joomla/joomla-cms/tags', array(), 0) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->getListTags('joomla', 'joomla-cms'), - $this->equalTo(json_decode($this->response->body)) - ); - } - - /** - * Tests the Delete method. - * - * @return void - */ - public function testDelete() - { - $this->client->expects($this->once()) - ->method('delete') - ->with('/repos/joomla/joomla-cms', array(), 0) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->delete('joomla', 'joomla-cms'), - $this->equalTo(json_decode($this->response->body)) - ); - } + /** + * @var Repositories + */ + protected $object; + + /** + * Sets up the fixture, for example, opens a network connection. + * This method is called before a test is executed. + * + * @since 1.0 + * + * @return void + */ + protected function setUp(): void + { + parent::setUp(); + + $this->object = new Repositories($this->options, $this->client); + } + + /** + * Tests the GetListOwn method. + * + * @return void + */ + 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)); + + $this->assertThat( + $this->object->getListOwn(), + $this->equalTo(json_decode($this->response->body)) + ); + } + + /** + * Tests the GetListOwn method. + * + * @return void + */ + public function testGetListOwnInvalidType() + { + $this->expectException(\RuntimeException::class); + + $this->object->getListOwn('INVALID'); + } + + /** + * Tests the GetListOwn method. + * + * @return void + */ + public function testGetListOwnInvalidSortField() + { + $this->expectException(\RuntimeException::class); + + $this->object->getListOwn('all', 'INVALID'); + } + + /** + * Tests the GetListOwn method. + * + * @return void + */ + public function testGetListOwnInvalidSortOrder() + { + $this->expectException(\RuntimeException::class); + + $this->object->getListOwn('all', 'full_name', 'INVALID'); + } + + /** + * Tests the GetListUser method. + * + * @return void + */ + 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)); + + $this->assertThat( + $this->object->getListUser('joomla'), + $this->equalTo(json_decode($this->response->body)) + ); + } + + /** + * Tests the GetListUser method. + * + * @return void + */ + public function testGetListUserInvalidType() + { + $this->expectException(\RuntimeException::class); + + $this->object->getListUser('joomla', 'INVALID'); + } + + /** + * Tests the GetListUser method. + * + * @return void + */ + public function testGetListUserInvalidSortField() + { + $this->expectException(\RuntimeException::class); + + $this->object->getListUser('joomla', 'all', 'INVALID'); + } + + /** + * Tests the GetListUser method. + * + * @return void + */ + public function testGetListUserInvalidSortOrder() + { + $this->expectException(\RuntimeException::class); + + $this->object->getListUser('joomla', 'all', 'full_name', 'INVALID'); + } + + /** + * Tests the GetListOrg method. + * + * @return void + */ + public function testGetListOrg() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/orgs/joomla/repos?type=all', [], 0) + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->getListOrg('joomla'), + $this->equalTo(json_decode($this->response->body)) + ); + } + + /** + * Tests the GetList method. + * + * @return void + */ + public function testGetList() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/repositories', [], 0) + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->getList(), + $this->equalTo(json_decode($this->response->body)) + ); + } + + /** + * Tests the Create method. + * + * @return void + */ + public function testCreate() + { + $this->response->code = 201; + + $this->client->expects($this->once()) + ->method('post') + ->with( + '/user/repos', + '{"name":"joomla-test","description":"","homepage":"","private":false,"has_issues":false,' + . '"has_wiki":false,"has_downloads":false,"team_id":0,"auto_init":false,"gitignore_template":""}', + [], + 0 + ) + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->create('joomla-test'), + $this->equalTo(json_decode($this->response->body)) + ); + } + + /** + * Tests the Create method. + * + * @return void + */ + public function testCreateWithOrg() + { + $this->response->code = 201; + + $this->client->expects($this->once()) + ->method('post') + ->with( + '/orgs/joomla.org/repos', + '{"name":"joomla-test","description":"","homepage":"","private":false,"has_issues":false,' + . '"has_wiki":false,"has_downloads":false,"team_id":0,"auto_init":false,"gitignore_template":""}', + [], + 0 + ) + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->create('joomla-test', 'joomla.org'), + $this->equalTo(json_decode($this->response->body)) + ); + } + + /** + * Tests the Get method. + * + * @return void + */ + public function testGet() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/repos/joomla/joomla-cms', [], 0) + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->get('joomla', 'joomla-cms'), + $this->equalTo(json_decode($this->response->body)) + ); + } + + /** + * Tests the GetListOrg method. + * + * @return void + */ + public function testGetListOrgInvalidType() + { + $this->expectException(\RuntimeException::class); + + $this->object->getListOrg('joomla', 'INVALID'); + } + + /** + * Tests the Edit method. + * + * @return void + */ + public function testEdit() + { + $this->client->expects($this->once()) + ->method('patch') + ->with( + '/repos/joomla/joomla-test', + '{"name":"joomla-test-1","description":"","homepage":"","private":' + . 'false,"has_issues":false,"has_wiki":false,"has_downloads":false,"default_branch":""}', + [] + ) + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->edit('joomla', 'joomla-test', 'joomla-test-1'), + $this->equalTo(json_decode($this->response->body)) + ); + } + + /** + * Tests the GetListContributors method. + * + * @return void + */ + public function testGetListContributors() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/repos/joomla/joomla-cms/contributors', [], 0) + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->getListContributors('joomla', 'joomla-cms'), + $this->equalTo(json_decode($this->response->body)) + ); + } + + /** + * Tests the GetListLanguages method. + * + * @return void + */ + public function testGetListLanguages() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/repos/joomla/joomla-cms/languages', [], 0) + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->getListLanguages('joomla', 'joomla-cms'), + $this->equalTo(json_decode($this->response->body)) + ); + } + + /** + * Tests the GetListTeams method. + * + * @return void + */ + public function testGetListTeams() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/repos/joomla/joomla-cms/teams', [], 0) + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->getListTeams('joomla', 'joomla-cms'), + $this->equalTo(json_decode($this->response->body)) + ); + } + + /** + * Tests the GetListTags method. + * + * @return void + */ + public function testGetListTags() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/repos/joomla/joomla-cms/tags', [], 0) + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->getListTags('joomla', 'joomla-cms'), + $this->equalTo(json_decode($this->response->body)) + ); + } + + /** + * Tests the Delete method. + * + * @return void + */ + public function testDelete() + { + $this->client->expects($this->once()) + ->method('delete') + ->with('/repos/joomla/joomla-cms', [], 0) + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->delete('joomla', 'joomla-cms'), + $this->equalTo(json_decode($this->response->body)) + ); + } } diff --git a/Tests/Package/SearchTest.php b/Tests/Package/SearchTest.php index 1a2d5954..ea8c758f 100644 --- a/Tests/Package/SearchTest.php +++ b/Tests/Package/SearchTest.php @@ -16,107 +16,107 @@ */ class SearchTest extends GitHubTestCase { - /** - * @var Search - */ - protected $object; + /** + * @var Search + */ + protected $object; - /** - * Sets up the fixture, for example, opens a network connection. - * This method is called before a test is executed. - * - * @since 1.0 - * - * @return void - */ - protected function setUp(): void - { - parent::setUp(); + /** + * Sets up the fixture, for example, opens a network connection. + * This method is called before a test is executed. + * + * @since 1.0 + * + * @return void + */ + protected function setUp(): void + { + parent::setUp(); - $this->object = new Search($this->options, $this->client); - } + $this->object = new Search($this->options, $this->client); + } - /** - * Tests the issues method - * - * @return void - */ - public function testIssues() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/legacy/issues/search/joomla/joomla-platform/open/github') - ->will($this->returnValue($this->response)); + /** + * Tests the issues method + * + * @return void + */ + public function testIssues() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/legacy/issues/search/joomla/joomla-platform/open/github') + ->will($this->returnValue($this->response)); - $this->assertThat( - $this->object->issues('joomla', 'joomla-platform', 'open', 'github'), - $this->equalTo(json_decode($this->sampleString)) - ); - } + $this->assertThat( + $this->object->issues('joomla', 'joomla-platform', 'open', 'github'), + $this->equalTo(json_decode($this->sampleString)) + ); + } - /** - * Tests the issuesInvalidState method - * - * @return void - */ - public function testIssuesInvalidState() - { - $this->expectException(\UnexpectedValueException::class); + /** + * Tests the issuesInvalidState method + * + * @return void + */ + public function testIssuesInvalidState() + { + $this->expectException(\UnexpectedValueException::class); - $this->object->issues('joomla', 'joomla-platform', 'invalid', 'github'); - } + $this->object->issues('joomla', 'joomla-platform', 'invalid', 'github'); + } - /** - * Tests the repositories method - * - * @return void - */ - public function testRepositories() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/legacy/repos/search/joomla') - ->will($this->returnValue($this->response)); + /** + * Tests the repositories method + * + * @return void + */ + public function testRepositories() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/legacy/repos/search/joomla') + ->will($this->returnValue($this->response)); - $this->assertThat( - $this->object->repositories('joomla'), - $this->equalTo(json_decode($this->sampleString)) - ); - } + $this->assertThat( + $this->object->repositories('joomla'), + $this->equalTo(json_decode($this->sampleString)) + ); + } - /** - * Tests the users method - * - * @return void - */ - public function testUsers() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/legacy/user/search/joomla') - ->will($this->returnValue($this->response)); + /** + * Tests the users method + * + * @return void + */ + public function testUsers() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/legacy/user/search/joomla') + ->will($this->returnValue($this->response)); - $this->assertThat( - $this->object->users('joomla'), - $this->equalTo(json_decode($this->sampleString)) - ); - } + $this->assertThat( + $this->object->users('joomla'), + $this->equalTo(json_decode($this->sampleString)) + ); + } - /** - * Tests the email method - * - * @return void - */ - public function testEmail() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/legacy/user/email/email@joomla') - ->will($this->returnValue($this->response)); + /** + * Tests the email method + * + * @return void + */ + public function testEmail() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/legacy/user/email/email@joomla') + ->will($this->returnValue($this->response)); - $this->assertThat( - $this->object->email('email@joomla'), - $this->equalTo(json_decode($this->sampleString)) - ); - } + $this->assertThat( + $this->object->email('email@joomla'), + $this->equalTo(json_decode($this->sampleString)) + ); + } } diff --git a/Tests/Package/Users/EmailsTest.php b/Tests/Package/Users/EmailsTest.php index c1d466e6..a08eda6b 100644 --- a/Tests/Package/Users/EmailsTest.php +++ b/Tests/Package/Users/EmailsTest.php @@ -16,81 +16,81 @@ */ class EmailsTest extends GitHubTestCase { - /** - * @var Emails - */ - protected $object; + /** + * @var Emails + */ + protected $object; - /** - * Sets up the fixture, for example, opens a network connection. - * This method is called before a test is executed. - * - * @since 1.0 - * - * @return void - */ - protected function setUp(): void - { - parent::setUp(); + /** + * Sets up the fixture, for example, opens a network connection. + * This method is called before a test is executed. + * + * @since 1.0 + * + * @return void + */ + protected function setUp(): void + { + parent::setUp(); - $this->object = new Emails($this->options, $this->client); - } + $this->object = new Emails($this->options, $this->client); + } - /** - * Tests the getList method - * - * @return void - */ - public function testGetList() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/user/emails') - ->will($this->returnValue($this->response)); + /** + * Tests the getList method + * + * @return void + */ + public function testGetList() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/user/emails') + ->will($this->returnValue($this->response)); - $this->assertThat( - $this->object->getList(), - $this->equalTo(json_decode($this->sampleString)) - ); - } + $this->assertThat( + $this->object->getList(), + $this->equalTo(json_decode($this->sampleString)) + ); + } - /** - * Tests the add method - * - * @return void - */ - public function testAdd() - { - $this->response->code = 201; + /** + * Tests the add method + * + * @return void + */ + public function testAdd() + { + $this->response->code = 201; - $this->client->expects($this->once()) - ->method('post') - ->with('/user/emails') - ->will($this->returnValue($this->response)); + $this->client->expects($this->once()) + ->method('post') + ->with('/user/emails') + ->will($this->returnValue($this->response)); - $this->assertThat( - $this->object->add('email@example.com'), - $this->equalTo(json_decode($this->sampleString)) - ); - } + $this->assertThat( + $this->object->add('email@example.com'), + $this->equalTo(json_decode($this->sampleString)) + ); + } - /** - * Tests the delete method - * - * @return void - */ - public function testDelete() - { - $this->response->code = 204; + /** + * Tests the delete method + * + * @return void + */ + public function testDelete() + { + $this->response->code = 204; - $this->client->expects($this->once()) - ->method('delete') - ->with('/user/emails') - ->will($this->returnValue($this->response)); + $this->client->expects($this->once()) + ->method('delete') + ->with('/user/emails') + ->will($this->returnValue($this->response)); - $this->assertThat( - $this->object->delete('email@example.com'), - $this->equalTo(json_decode($this->sampleString)) - ); - } + $this->assertThat( + $this->object->delete('email@example.com'), + $this->equalTo(json_decode($this->sampleString)) + ); + } } diff --git a/Tests/Package/Users/FollowersTest.php b/Tests/Package/Users/FollowersTest.php index 6bad291b..00a1c247 100644 --- a/Tests/Package/Users/FollowersTest.php +++ b/Tests/Package/Users/FollowersTest.php @@ -18,305 +18,305 @@ */ class FollowersTest extends GitHubTestCase { - /** - * @var Followers - */ - protected $object; - - /** - * Sets up the fixture, for example, opens a network connection. - * This method is called before a test is executed. - * - * @since 1.0 - * - * @return void - */ - protected function setUp(): void - { - parent::setUp(); - - $this->object = new Followers($this->options, $this->client); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Users\Followers::getList() - * - * @return void - */ - public function testGetList() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/user/followers') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->getList(), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Users\Followers::getList() - * - * @return void - */ - public function testGetListWithUser() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/users/joomla/followers') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->getList('joomla'), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Users\Followers::getListFollowedBy() - * - * @return void - */ - public function testGetListFollowedBy() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/user/following') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->getListFollowedBy(), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Users\Followers::getListFollowedBy() - * - * @return void - */ - public function testGetListFollowedByWithUser() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/users/joomla/following') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->getListFollowedBy('joomla'), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Users\Followers::check() - * - * You are following this user - * - * @return void - */ - public function testCheck() - { - $this->response->code = 204; - $this->response->body = true; - - $this->client->expects($this->once()) - ->method('get') - ->with('/user/following/joomla') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->check('joomla'), - $this->equalTo($this->response->body) - ); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Users\Followers::check() - * - * You are not following this user - * - * @return void - */ - public function testCheckNo() - { - $this->response->code = 404; - $this->response->body = false; - - $this->client->expects($this->once()) - ->method('get') - ->with('/user/following/joomla') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->check('joomla'), - $this->equalTo($this->response->body) - ); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Users\Followers::check() - * - * @return void - */ - public function testCheckUnexpected() - { - $this->expectException(\UnexpectedValueException::class); - - $this->response->code = 666; - $this->response->body = false; - - $this->client->expects($this->once()) - ->method('get') - ->with('/user/following/joomla') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->check('joomla'), - $this->equalTo($this->response->body) - ); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Users\Followers::follow() - * - * @return void - */ - public function testFollow() - { - $this->response->code = 204; - $this->response->body = ''; - - $this->client->expects($this->once()) - ->method('put') - ->with('/user/following/joomla') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->follow('joomla'), - $this->equalTo($this->response->body) - ); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Users\Followers::unfollow() - * - * @return void - */ - public function testUnfollow() - { - $this->response->code = 204; - $this->response->body = ''; - - $this->client->expects($this->once()) - ->method('delete') - ->with('/user/following/joomla') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->unfollow('joomla'), - $this->equalTo($this->response->body) - ); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Users\Followers::checkUserFollowing() - * - * User is following the target - * - * @return void - * - * @since 1.0 - */ - public function testCheckUserFollowing() - { - $this->response->code = 204; - - $this->client->expects($this->once()) - ->method('get') - ->with('/user/{user}/following/{target}') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->checkUserFollowing('{user}', '{target}'), - $this->equalTo(true) - ); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Users\Followers::checkUserFollowing() - * - * User is not following the target - * - * @return void - * - * @since 1.0 - */ - public function testCheckUserFollowingNot() - { - $this->response->code = 404; - - $this->client->expects($this->once()) - ->method('get') - ->with('/user/{user}/following/{target}') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->checkUserFollowing('{user}', '{target}'), - $this->equalTo(false) - ); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Users\Followers::checkUserFollowing() - * - * // Unexpected response - * - * @return void - * - * @since 1.0 - */ - public function testCheckUserFollowingUnexpected() - { - $this->expectException(\UnexpectedValueException::class); - $this->expectExceptionMessage('Unexpected response code: 666'); - - $this->response->code = 666; - - $this->client->expects($this->once()) - ->method('get') - ->with('/user/{user}/following/{target}') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->checkUserFollowing('{user}', '{target}'), - $this->equalTo(true) - ); - } + /** + * @var Followers + */ + protected $object; + + /** + * Sets up the fixture, for example, opens a network connection. + * This method is called before a test is executed. + * + * @since 1.0 + * + * @return void + */ + protected function setUp(): void + { + parent::setUp(); + + $this->object = new Followers($this->options, $this->client); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Users\Followers::getList() + * + * @return void + */ + public function testGetList() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/user/followers') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->getList(), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Users\Followers::getList() + * + * @return void + */ + public function testGetListWithUser() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/users/joomla/followers') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->getList('joomla'), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Users\Followers::getListFollowedBy() + * + * @return void + */ + public function testGetListFollowedBy() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/user/following') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->getListFollowedBy(), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Users\Followers::getListFollowedBy() + * + * @return void + */ + public function testGetListFollowedByWithUser() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/users/joomla/following') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->getListFollowedBy('joomla'), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Users\Followers::check() + * + * You are following this user + * + * @return void + */ + public function testCheck() + { + $this->response->code = 204; + $this->response->body = true; + + $this->client->expects($this->once()) + ->method('get') + ->with('/user/following/joomla') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->check('joomla'), + $this->equalTo($this->response->body) + ); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Users\Followers::check() + * + * You are not following this user + * + * @return void + */ + public function testCheckNo() + { + $this->response->code = 404; + $this->response->body = false; + + $this->client->expects($this->once()) + ->method('get') + ->with('/user/following/joomla') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->check('joomla'), + $this->equalTo($this->response->body) + ); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Users\Followers::check() + * + * @return void + */ + public function testCheckUnexpected() + { + $this->expectException(\UnexpectedValueException::class); + + $this->response->code = 666; + $this->response->body = false; + + $this->client->expects($this->once()) + ->method('get') + ->with('/user/following/joomla') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->check('joomla'), + $this->equalTo($this->response->body) + ); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Users\Followers::follow() + * + * @return void + */ + public function testFollow() + { + $this->response->code = 204; + $this->response->body = ''; + + $this->client->expects($this->once()) + ->method('put') + ->with('/user/following/joomla') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->follow('joomla'), + $this->equalTo($this->response->body) + ); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Users\Followers::unfollow() + * + * @return void + */ + public function testUnfollow() + { + $this->response->code = 204; + $this->response->body = ''; + + $this->client->expects($this->once()) + ->method('delete') + ->with('/user/following/joomla') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->unfollow('joomla'), + $this->equalTo($this->response->body) + ); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Users\Followers::checkUserFollowing() + * + * User is following the target + * + * @return void + * + * @since 1.0 + */ + public function testCheckUserFollowing() + { + $this->response->code = 204; + + $this->client->expects($this->once()) + ->method('get') + ->with('/user/{user}/following/{target}') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->checkUserFollowing('{user}', '{target}'), + $this->equalTo(true) + ); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Users\Followers::checkUserFollowing() + * + * User is not following the target + * + * @return void + * + * @since 1.0 + */ + public function testCheckUserFollowingNot() + { + $this->response->code = 404; + + $this->client->expects($this->once()) + ->method('get') + ->with('/user/{user}/following/{target}') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->checkUserFollowing('{user}', '{target}'), + $this->equalTo(false) + ); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Users\Followers::checkUserFollowing() + * + * // Unexpected response + * + * @return void + * + * @since 1.0 + */ + public function testCheckUserFollowingUnexpected() + { + $this->expectException(\UnexpectedValueException::class); + $this->expectExceptionMessage('Unexpected response code: 666'); + + $this->response->code = 666; + + $this->client->expects($this->once()) + ->method('get') + ->with('/user/{user}/following/{target}') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->checkUserFollowing('{user}', '{target}'), + $this->equalTo(true) + ); + } } diff --git a/Tests/Package/Users/KeysTest.php b/Tests/Package/Users/KeysTest.php index a7548890..a5be5862 100644 --- a/Tests/Package/Users/KeysTest.php +++ b/Tests/Package/Users/KeysTest.php @@ -16,135 +16,135 @@ */ class KeysTest extends GitHubTestCase { - /** - * @var Keys - */ - protected $object; - - /** - * Sets up the fixture, for example, opens a network connection. - * This method is called before a test is executed. - * - * @since 1.0 - * - * @return void - */ - protected function setUp(): void - { - parent::setUp(); - - $this->object = new Keys($this->options, $this->client); - } - - /** - * Tests the getListUser method - * - * @return void - */ - public function testGetListUser() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/users/joomla/keys') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->getListUser('joomla'), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Tests the getList method - * - * @return void - */ - public function testGetList() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/users/keys') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->getList(), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Tests the get method - * - * @return void - */ - public function testGet() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/users/keys/1') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->get(1), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Tests the create method - * - * @return void - */ - public function testCreate() - { - $this->response->code = 201; - - $this->client->expects($this->once()) - ->method('post') - ->with('/users/keys') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->create('email@example.com', '12345'), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Tests the edit method - * - * @return void - */ - public function testEdit() - { - $this->client->expects($this->once()) - ->method('patch') - ->with('/users/keys/1') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->edit(1, 'email@example.com', '12345'), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Tests the delete method - * - * @return void - */ - public function testDelete() - { - $this->response->code = 204; - - $this->client->expects($this->once()) - ->method('delete') - ->with('/users/keys/1') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->delete(1), - $this->equalTo(json_decode($this->sampleString)) - ); - } + /** + * @var Keys + */ + protected $object; + + /** + * Sets up the fixture, for example, opens a network connection. + * This method is called before a test is executed. + * + * @since 1.0 + * + * @return void + */ + protected function setUp(): void + { + parent::setUp(); + + $this->object = new Keys($this->options, $this->client); + } + + /** + * Tests the getListUser method + * + * @return void + */ + public function testGetListUser() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/users/joomla/keys') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->getListUser('joomla'), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Tests the getList method + * + * @return void + */ + public function testGetList() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/users/keys') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->getList(), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Tests the get method + * + * @return void + */ + public function testGet() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/users/keys/1') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->get(1), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Tests the create method + * + * @return void + */ + public function testCreate() + { + $this->response->code = 201; + + $this->client->expects($this->once()) + ->method('post') + ->with('/users/keys') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->create('email@example.com', '12345'), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Tests the edit method + * + * @return void + */ + public function testEdit() + { + $this->client->expects($this->once()) + ->method('patch') + ->with('/users/keys/1') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->edit(1, 'email@example.com', '12345'), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Tests the delete method + * + * @return void + */ + public function testDelete() + { + $this->response->code = 204; + + $this->client->expects($this->once()) + ->method('delete') + ->with('/users/keys/1') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->delete(1), + $this->equalTo(json_decode($this->sampleString)) + ); + } } diff --git a/Tests/Package/UsersTest.php b/Tests/Package/UsersTest.php index 5b7f52c1..83845b1c 100755 --- a/Tests/Package/UsersTest.php +++ b/Tests/Package/UsersTest.php @@ -16,35 +16,35 @@ */ class UsersTest extends GitHubTestCase { - /** - * @var Users - */ - protected $object; - - /** - * Sets up the fixture, for example, opens a network connection. - * This method is called before a test is executed. - * - * @access protected - * - * @return void - */ - protected function setUp(): void - { - parent::setUp(); - - $this->object = new Users($this->options, $this->client); - } - - /** - * Tests the getUser method - * - * @return void - */ - public function testGet() - { - $this->response->code = 200; - $this->response->body = '{ + /** + * @var Users + */ + protected $object; + + /** + * Sets up the fixture, for example, opens a network connection. + * This method is called before a test is executed. + * + * @access protected + * + * @return void + */ + protected function setUp(): void + { + parent::setUp(); + + $this->object = new Users($this->options, $this->client); + } + + /** + * Tests the getUser method + * + * @return void + */ + public function testGet() + { + $this->response->code = 200; + $this->response->body = '{ "login": "octocat", "id": 1, "avatar_url": "https://github.com/images/error/octocat_happy.gif", @@ -66,49 +66,49 @@ public function testGet() "type": "User" }'; - $this->client->expects($this->once()) - ->method('get') - ->with('/users/joomla', array(), 0) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->get('joomla'), - $this->equalTo(json_decode($this->response->body)) - ); - } - - /** - * Tests the getUser method with failure - * - * @return void - */ - public function testGetFailure() - { - $this->expectException(\DomainException::class); - - $this->response->code = 404; - $this->response->body = '{"message":"Not Found"}'; - - $this->client->expects($this->once()) - ->method('get') - ->with('/users/nonexistentuser', array(), 0) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->get('nonexistentuser'), - $this->equalTo(json_decode($this->response->body)) - ); - } - - /** - * Tests the getAuthenticatedUser method - * - * @return void - */ - public function testGetAuthenticatedUser() - { - $this->response->code = 200; - $this->response->body = '{ + $this->client->expects($this->once()) + ->method('get') + ->with('/users/joomla', [], 0) + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->get('joomla'), + $this->equalTo(json_decode($this->response->body)) + ); + } + + /** + * Tests the getUser method with failure + * + * @return void + */ + public function testGetFailure() + { + $this->expectException(\DomainException::class); + + $this->response->code = 404; + $this->response->body = '{"message":"Not Found"}'; + + $this->client->expects($this->once()) + ->method('get') + ->with('/users/nonexistentuser', [], 0) + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->get('nonexistentuser'), + $this->equalTo(json_decode($this->response->body)) + ); + } + + /** + * Tests the getAuthenticatedUser method + * + * @return void + */ + public function testGetAuthenticatedUser() + { + $this->response->code = 200; + $this->response->body = '{ "login": "octocat", "id": 1, "avatar_url": "https://github.com/images/error/octocat_happy.gif", @@ -141,49 +141,49 @@ public function testGetAuthenticatedUser() } }'; - $this->client->expects($this->once()) - ->method('get') - ->with('/user', array(), 0) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->getAuthenticatedUser(), - $this->equalTo(json_decode($this->response->body)) - ); - } - - /** - * Tests the GetAuthenticatedUser method with failure - * - * @return void - */ - public function testGetAuthenticatedUserFailure() - { - $this->expectException(\DomainException::class); - - $this->response->code = 401; - $this->response->body = '{"message":"Requires authentication"}'; - - $this->client->expects($this->once()) - ->method('get') - ->with('/user', array(), 0) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->getAuthenticatedUser(), - $this->equalTo(json_decode($this->response->body)) - ); - } - - /** - * Tests the getUsers method - * - * @return void - */ - public function testGetList() - { - $this->response->code = 200; - $this->response->body = '[ + $this->client->expects($this->once()) + ->method('get') + ->with('/user', [], 0) + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->getAuthenticatedUser(), + $this->equalTo(json_decode($this->response->body)) + ); + } + + /** + * Tests the GetAuthenticatedUser method with failure + * + * @return void + */ + public function testGetAuthenticatedUserFailure() + { + $this->expectException(\DomainException::class); + + $this->response->code = 401; + $this->response->body = '{"message":"Requires authentication"}'; + + $this->client->expects($this->once()) + ->method('get') + ->with('/user', [], 0) + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->getAuthenticatedUser(), + $this->equalTo(json_decode($this->response->body)) + ); + } + + /** + * Tests the getUsers method + * + * @return void + */ + public function testGetList() + { + $this->response->code = 200; + $this->response->body = '[ { "login": "octocat", "id": 1, @@ -201,34 +201,34 @@ public function testGetList() } ]'; - $this->client->expects($this->once()) - ->method('get') - ->with('/users', array(), 0) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->getList(), - $this->equalTo(json_decode($this->response->body)) - ); - } - - /** - * Tests the getUsers method - * - * @return void - */ - public function testEdit() - { - $name = 'monalisa octocat'; - $email = 'octocat@github.com'; - $blog = 'https =>//github.com/blog'; - $company = 'GitHub'; - $location = 'San Francisco'; - $hireable = true; - $bio = 'There once...'; - - $this->response->code = 200; - $this->response->body = '{ + $this->client->expects($this->once()) + ->method('get') + ->with('/users', [], 0) + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->getList(), + $this->equalTo(json_decode($this->response->body)) + ); + } + + /** + * Tests the getUsers method + * + * @return void + */ + public function testEdit() + { + $name = 'monalisa octocat'; + $email = 'octocat@github.com'; + $blog = 'https =>//github.com/blog'; + $company = 'GitHub'; + $location = 'San Francisco'; + $hireable = true; + $bio = 'There once...'; + + $this->response->code = 200; + $this->response->body = '{ "login": "octocat", "id": 1, "avatar_url": "https://github.com/images/error/octocat_happy.gif", @@ -261,71 +261,71 @@ public function testEdit() } }'; - $input = json_encode( - array( - 'name' => $name, - 'email' => $email, - 'blog' => $blog, - 'company' => $company, - 'location' => $location, - 'hireable' => $hireable, - 'bio' => $bio - ) - ); - - $this->client->expects($this->once()) - ->method('patch') - ->with('/user', $input, array(), 0) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->edit($name, $email, $blog, $company, $location, $hireable, $bio), - $this->equalTo(json_decode($this->response->body)) - ); - } - - /** - * Tests the getUsers method - * - * @return void - */ - public function testEditFailure() - { - $this->expectException(\DomainException::class); - - $name = 'monalisa octocat'; - $email = 'octocat@github.com'; - $blog = 'https =>//github.com/blog'; - $company = 'GitHub'; - $location = 'San Francisco'; - $hireable = true; - $bio = 'There once...'; - - $this->response->code = 404; - $this->response->body = $this->errorString; - - $input = json_encode( - array( - 'name' => $name, - 'email' => $email, - 'blog' => $blog, - 'company' => $company, - 'location' => $location, - 'hireable' => $hireable, - 'bio' => $bio - ) - ); - - $this->client->expects($this->once()) - ->method('patch') - ->with('/user', $input, array(), 0) - ->will($this->returnValue($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)) - ); - } + $input = json_encode( + [ + 'name' => $name, + 'email' => $email, + 'blog' => $blog, + 'company' => $company, + 'location' => $location, + 'hireable' => $hireable, + 'bio' => $bio, + ] + ); + + $this->client->expects($this->once()) + ->method('patch') + ->with('/user', $input, [], 0) + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->edit($name, $email, $blog, $company, $location, $hireable, $bio), + $this->equalTo(json_decode($this->response->body)) + ); + } + + /** + * Tests the getUsers method + * + * @return void + */ + public function testEditFailure() + { + $this->expectException(\DomainException::class); + + $name = 'monalisa octocat'; + $email = 'octocat@github.com'; + $blog = 'https =>//github.com/blog'; + $company = 'GitHub'; + $location = 'San Francisco'; + $hireable = true; + $bio = 'There once...'; + + $this->response->code = 404; + $this->response->body = $this->errorString; + + $input = json_encode( + [ + 'name' => $name, + 'email' => $email, + 'blog' => $blog, + 'company' => $company, + 'location' => $location, + 'hireable' => $hireable, + 'bio' => $bio, + ] + ); + + $this->client->expects($this->once()) + ->method('patch') + ->with('/user', $input, [], 0) + ->will($this->returnValue($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)) + ); + } } diff --git a/Tests/Package/ZenTest.php b/Tests/Package/ZenTest.php index a68cfeba..f7ab1943 100644 --- a/Tests/Package/ZenTest.php +++ b/Tests/Package/ZenTest.php @@ -16,67 +16,67 @@ */ class ZenTest extends GitHubTestCase { - /** - * @var Zen - */ - protected $object; + /** + * @var Zen + */ + protected $object; - /** - * Sets up the fixture, for example, opens a network connection. - * This method is called before a test is executed. - * - * @since 1.0 - * - * @return void - */ - protected function setUp(): void - { - parent::setUp(); + /** + * Sets up the fixture, for example, opens a network connection. + * This method is called before a test is executed. + * + * @since 1.0 + * + * @return void + */ + protected function setUp(): void + { + parent::setUp(); - $this->object = new Zen($this->options, $this->client); - } + $this->object = new Zen($this->options, $this->client); + } - /** - * Tests the Get method. - * - * @return void - */ - public function testGet() - { - $this->response->code = 200; - $this->response->body = 'My Zen'; + /** + * Tests the Get method. + * + * @return void + */ + public function testGet() + { + $this->response->code = 200; + $this->response->body = 'My Zen'; - $this->client->expects($this->once()) - ->method('get') - ->with('/zen', array(), 0) - ->will($this->returnValue($this->response)); + $this->client->expects($this->once()) + ->method('get') + ->with('/zen', [], 0) + ->will($this->returnValue($this->response)); - $this->assertThat( - $this->object->get(), - $this->equalTo($this->response->body) - ); - } + $this->assertThat( + $this->object->get(), + $this->equalTo($this->response->body) + ); + } - /** - * Tests the Get method. - * - * @return void - */ - public function testGetFailure() - { - $this->expectException(\RuntimeException::class); + /** + * Tests the Get method. + * + * @return void + */ + public function testGetFailure() + { + $this->expectException(\RuntimeException::class); - $this->response->code = 400; - $this->response->body = 'My Zen'; + $this->response->code = 400; + $this->response->body = 'My Zen'; - $this->client->expects($this->once()) - ->method('get') - ->with('/zen', array(), 0) - ->will($this->returnValue($this->response)); + $this->client->expects($this->once()) + ->method('get') + ->with('/zen', [], 0) + ->will($this->returnValue($this->response)); - $this->assertThat( - $this->object->get(), - $this->equalTo($this->response->body) - ); - } + $this->assertThat( + $this->object->get(), + $this->equalTo($this->response->body) + ); + } } diff --git a/Tests/PackageTest.php b/Tests/PackageTest.php index 717375d1..c86e3c42 100755 --- a/Tests/PackageTest.php +++ b/Tests/PackageTest.php @@ -16,53 +16,53 @@ */ class PackageTest extends GitHubTestCase { - /** - * @var Github Object under test. - * @since 1.0 - */ - protected $object; + /** + * @var Github Object under test. + * @since 1.0 + */ + protected $object; - /** - * Sets up the fixture, for example, opens a network connection. - * This method is called before a test is executed. - * - * @return void - * - * @since 1.0 - */ - protected function setUp(): void - { - parent::setUp(); + /** + * Sets up the fixture, for example, opens a network connection. + * This method is called before a test is executed. + * + * @return void + * + * @since 1.0 + */ + protected function setUp(): void + { + parent::setUp(); - $this->object = new Github($this->options, $this->client); - } + $this->object = new Github($this->options, $this->client); + } - /** - * Tests the magic __get method - * - * @return void - * - * @since 1.0 - */ - public function testGet() - { - $this->assertThat( - $this->object->repositories->forks, - $this->isInstanceOf('Joomla\Github\Package\Repositories\Forks') - ); - } + /** + * Tests the magic __get method + * + * @return void + * + * @since 1.0 + */ + public function testGet() + { + $this->assertThat( + $this->object->repositories->forks, + $this->isInstanceOf('Joomla\Github\Package\Repositories\Forks') + ); + } - /** - * Tests the magic __get method with an invalid parameter. - * - * @return void - * - * @since 1.0 - */ - public function testGetInvalid() - { - $this->expectException(\InvalidArgumentException::class); + /** + * Tests the magic __get method with an invalid parameter. + * + * @return void + * + * @since 1.0 + */ + public function testGetInvalid() + { + $this->expectException(\InvalidArgumentException::class); - $this->object->repositories->INVALID; - } + $this->object->repositories->INVALID; + } } diff --git a/Tests/Stub/GitHubTestCase.php b/Tests/Stub/GitHubTestCase.php index f6c4b1ae..c4c91664 100644 --- a/Tests/Stub/GitHubTestCase.php +++ b/Tests/Stub/GitHubTestCase.php @@ -16,59 +16,59 @@ */ abstract class GitHubTestCase extends TestCase { - /** - * @var Registry Options for the GitHub object. - * @since 1.0 - */ - protected $options; + /** + * @var Registry Options for the GitHub object. + * @since 1.0 + */ + protected $options; - /** - * @var \PHPUnit_Framework_MockObject_MockObject Mock client object. - * @since 1.0 - */ - protected $client; + /** + * @var \PHPUnit_Framework_MockObject_MockObject Mock client object. + * @since 1.0 + */ + protected $client; - /** - * @var \Joomla\Http\Response Mock response object. - * @since 1.0 - */ - protected $response; + /** + * @var \Joomla\Http\Response Mock response object. + * @since 1.0 + */ + protected $response; - /** - * @var string Sample JSON string. - * @since 12.3 - */ - protected $sampleString = '{"a":1,"b":2,"c":3,"d":4,"e":5}'; + /** + * @var string Sample JSON string. + * @since 12.3 + */ + protected $sampleString = '{"a":1,"b":2,"c":3,"d":4,"e":5}'; - /** - * @var string Sample JSON error message. - * @since 12.3 - */ - protected $errorString = '{"message": "Generic Error"}'; + /** + * @var string Sample JSON error message. + * @since 12.3 + */ + protected $errorString = '{"message": "Generic Error"}'; - /** - * Sets up the fixture, for example, opens a network connection. - * This method is called before a test is executed. - * - * @since 1.0 - * - * @return void - */ - protected function setUp(): void - { - parent::setUp(); + /** + * Sets up the fixture, for example, opens a network connection. + * This method is called before a test is executed. + * + * @since 1.0 + * + * @return void + */ + protected function setUp(): void + { + parent::setUp(); - $this->options = new Registry; + $this->options = new Registry(); - $this->client = $this->getMockBuilder('\\Joomla\\Http\\Http') - ->setMethods(array('get', 'post', 'delete', 'patch', 'put')) - ->getMock(); + $this->client = $this->getMockBuilder('\\Joomla\\Http\\Http') + ->setMethods(['get', 'post', 'delete', 'patch', 'put']) + ->getMock(); - $this->response = $this->getMockBuilder('\\Joomla\\Http\\Response') - ->getMock(); + $this->response = $this->getMockBuilder('\\Joomla\\Http\\Response') + ->getMock(); - // Set a default response - $this->response->code = 200; - $this->response->body = $this->sampleString; - } + // Set a default response + $this->response->code = 200; + $this->response->body = $this->sampleString; + } } diff --git a/Tests/Stub/ObjectMock.php b/Tests/Stub/ObjectMock.php index 8ddcb1cd..fe40373e 100644 --- a/Tests/Stub/ObjectMock.php +++ b/Tests/Stub/ObjectMock.php @@ -15,23 +15,23 @@ */ class ObjectMock extends AbstractGithubObject { - // @codingStandardsIgnoreStart - /** - * Method to build and return a full request URL for the request. This method will - * add appropriate pagination details if necessary and also prepend the API url - * to have a complete URL for the request. - * - * @param string $path URL to inflect - * @param integer $page Page to request - * @param integer $limit Number of results to return per page - * - * @return string The request URL. - * - * @since 1.0 - */ - public function fetchUrl($path, $page = 0, $limit = 0) - { - return parent::fetchUrl($path, $page, $limit); - } - // @codingStandardsIgnoreEnd + // @codingStandardsIgnoreStart + /** + * Method to build and return a full request URL for the request. This method will + * add appropriate pagination details if necessary and also prepend the API url + * to have a complete URL for the request. + * + * @param string $path URL to inflect + * @param integer $page Page to request + * @param integer $limit Number of results to return per page + * + * @return string The request URL. + * + * @since 1.0 + */ + public function fetchUrl($path, $page = 0, $limit = 0) + { + return parent::fetchUrl($path, $page, $limit); + } + // @codingStandardsIgnoreEnd } diff --git a/Tests/bootstrap.php b/Tests/bootstrap.php index ddfe6fa4..f87308fe 100644 --- a/Tests/bootstrap.php +++ b/Tests/bootstrap.php @@ -1,6 +1,7 @@ given\\.$#" + count: 2 + path: src/AbstractGithubObject.php + + - + message: "#^Class Joomla\\\\Github\\\\Github referenced with incorrect case\\: Joomla\\\\Github\\\\GitHub\\.$#" + count: 1 + path: src/Github.php + + - + message: "#^Parameter \\#2 \\$value of method Joomla\\\\Uri\\\\Uri\\:\\:setVar\\(\\) expects string, int given\\.$#" + count: 4 + path: src/Package/Activity/Notifications.php + + - + message: "#^Variable \\$labels in isset\\(\\) always exists and is not nullable\\.$#" + count: 1 + path: src/Package/Issues.php + + - + message: "#^Parameter \\#2 \\$value of method Joomla\\\\Uri\\\\Uri\\:\\:setVar\\(\\) expects string, int\\