diff --git a/.drone.jsonnet b/.drone.jsonnet index 872ba3fb..e13974c7 100644 --- a/.drone.jsonnet +++ b/.drone.jsonnet @@ -25,7 +25,7 @@ local composer(phpversion, params) = { local phpunit(phpversion) = { name: "PHPUnit", image: "joomlaprojects/docker-images:php" + phpversion, - [if phpversion == "8.0" then "failure"]: "ignore", + [if phpversion == "8.3" then "failure"]: "ignore", commands: ["vendor/bin/phpunit"] }; @@ -47,39 +47,33 @@ local pipeline(name, phpversion, params) = { steps: [ { name: "composer", - image: "joomlaprojects/docker-images:php7.4", + image: "joomlaprojects/docker-images:php8.1", volumes: volumes, commands: [ "php -v", - "composer update", - "composer require phpmd/phpmd phpstan/phpstan" + "composer update" ] }, { name: "phpcs", - image: "joomlaprojects/docker-images:php7.4", + image: "joomlaprojects/docker-images:php8.1", depends: [ "composer" ], commands: [ - "vendor/bin/phpcs --config-set installed_paths vendor/joomla/coding-standards", - "vendor/bin/phpcs -p --report=full --extensions=php --standard=ruleset.xml src/" + "vendor/bin/phpcs --standard=ruleset.xml src/" ] }, { - name: "phpmd", - image: "joomlaprojects/docker-images:php7.4", + name: "phan", + image: "joomlaprojects/docker-images:php8.1-ast", 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", + "vendor/bin/phan" ] }, { name: "phpstan", - image: "joomlaprojects/docker-images:php7.4", + image: "joomlaprojects/docker-images:php8.1", depends: [ "composer" ], failure: "ignore", commands: [ @@ -88,7 +82,7 @@ local pipeline(name, phpversion, params) = { }, { name: "phploc", - image: "joomlaprojects/docker-images:php7.4", + image: "joomlaprojects/docker-images:php8.1", depends: [ "composer" ], failure: "ignore", commands: [ @@ -97,7 +91,7 @@ local pipeline(name, phpversion, params) = { }, { name: "phpcpd", - image: "joomlaprojects/docker-images:php7.4", + image: "joomlaprojects/docker-images:php8.1", depends: [ "composer" ], failure: "ignore", commands: [ @@ -106,32 +100,7 @@ local pipeline(name, phpversion, params) = { } ] }, - { - kind: "pipeline", - name: "PHP 5.3 lowest", - volumes: hostvolumes, - steps: [ - { - name: "composer", - image: "joomlaprojects/docker-images:php5.3", - volumes: volumes, - commands: [ - "php -v", - "composer update --prefer-stable --prefer-lowest", - "composer update phpunit/phpunit-mock-objects" - ] - }, - phpunit("5.3") - ] - }, - pipeline("5.3", "5.3", "--prefer-stable"), - pipeline("5.4", "5.4", "--prefer-stable"), - pipeline("5.5", "5.5", "--prefer-stable"), - pipeline("5.6", "5.6", "--prefer-stable"), - pipeline("7.0", "7.0", "--prefer-stable"), - pipeline("7.1", "7.1", "--prefer-stable"), - 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", "--ignore-platform-reqs --prefer-stable") + pipeline("8.1 lowest", "8.1", "--prefer-stable --prefer-lowest"), + pipeline("8.1", "8.1", "--prefer-stable"), + pipeline("8.2", "8.2", "--prefer-stable"), ] diff --git a/.drone.yml b/.drone.yml index 7766be1f..0b8d4d90 100644 --- a/.drone.yml +++ b/.drone.yml @@ -1,373 +1,115 @@ --- kind: pipeline name: Codequality - -platform: - os: linux - arch: amd64 - steps: -- name: composer - image: joomlaprojects/docker-images:php7.4 - commands: +- commands: - php -v - composer update - - composer require phpmd/phpmd phpstan/phpstan + image: joomlaprojects/docker-images:php8.1 + name: composer volumes: - name: composer-cache path: /tmp/composer-cache - -- name: phpcs - image: joomlaprojects/docker-images:php7.4 - commands: - - vendor/bin/phpcs --config-set installed_paths vendor/joomla/coding-standards - - vendor/bin/phpcs -p --report=full --extensions=php --standard=ruleset.xml src/ - -- name: phpmd - image: joomlaprojects/docker-images:php7.4 - 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 +- commands: + - vendor/bin/phpcs --standard=ruleset.xml src/ + depends: + - composer + image: joomlaprojects/docker-images:php8.1 + name: phpcs +- commands: + - vendor/bin/phan + depends: + - composer failure: ignore - -- name: phpstan - image: joomlaprojects/docker-images:php7.4 - commands: + image: joomlaprojects/docker-images:php8.1-ast + name: phan +- commands: - vendor/bin/phpstan analyse src + depends: + - composer failure: ignore - -- name: phploc - image: joomlaprojects/docker-images:php7.4 - commands: + image: joomlaprojects/docker-images:php8.1 + name: phpstan +- commands: - phploc src + depends: + - composer failure: ignore - -- name: phpcpd - image: joomlaprojects/docker-images:php7.4 - commands: + image: joomlaprojects/docker-images:php8.1 + name: phploc +- commands: - phpcpd src + depends: + - composer failure: ignore - + image: joomlaprojects/docker-images:php8.1 + name: phpcpd volumes: -- name: composer-cache - host: +- host: path: /tmp/composer-cache - + name: composer-cache --- kind: pipeline -name: PHP 5.3 lowest - -platform: - os: linux - arch: amd64 - +name: PHP 8.1 lowest steps: -- name: composer - image: joomlaprojects/docker-images:php5.3 - commands: +- commands: - php -v - composer update --prefer-stable --prefer-lowest - - composer update phpunit/phpunit-mock-objects - volumes: - - name: composer-cache - path: /tmp/composer-cache - -- name: PHPUnit - image: joomlaprojects/docker-images:php5.3 - commands: - - vendor/bin/phpunit - -volumes: -- name: composer-cache - host: - path: /tmp/composer-cache - ---- -kind: pipeline -name: PHP 5.3 - -platform: - os: linux - arch: amd64 - -steps: -- name: composer - image: joomlaprojects/docker-images:php5.3 - commands: - - php -v - - composer update --prefer-stable - volumes: - - name: composer-cache - path: /tmp/composer-cache - -- name: PHPUnit - image: joomlaprojects/docker-images:php5.3 - commands: - - vendor/bin/phpunit - -volumes: -- name: composer-cache - host: - path: /tmp/composer-cache - ---- -kind: pipeline -name: PHP 5.4 - -platform: - os: linux - arch: amd64 - -steps: -- name: composer - image: joomlaprojects/docker-images:php5.4 - commands: - - php -v - - composer update --prefer-stable - volumes: - - name: composer-cache - path: /tmp/composer-cache - -- name: PHPUnit - image: joomlaprojects/docker-images:php5.4 - commands: - - vendor/bin/phpunit - -volumes: -- name: composer-cache - host: - path: /tmp/composer-cache - ---- -kind: pipeline -name: PHP 5.5 - -platform: - os: linux - arch: amd64 - -steps: -- name: composer - image: joomlaprojects/docker-images:php5.5 - commands: - - php -v - - composer update --prefer-stable - volumes: - - name: composer-cache - path: /tmp/composer-cache - -- name: PHPUnit - image: joomlaprojects/docker-images:php5.5 - commands: - - vendor/bin/phpunit - -volumes: -- name: composer-cache - host: - path: /tmp/composer-cache - ---- -kind: pipeline -name: PHP 5.6 - -platform: - os: linux - arch: amd64 - -steps: -- name: composer - image: joomlaprojects/docker-images:php5.6 - commands: - - php -v - - composer update --prefer-stable - volumes: - - name: composer-cache - path: /tmp/composer-cache - -- name: PHPUnit - image: joomlaprojects/docker-images:php5.6 - commands: - - vendor/bin/phpunit - -volumes: -- name: composer-cache - host: - path: /tmp/composer-cache - ---- -kind: pipeline -name: PHP 7.0 - -platform: - os: linux - arch: amd64 - -steps: -- name: composer - image: joomlaprojects/docker-images:php7.0 - commands: - - php -v - - composer update --prefer-stable - volumes: - - name: composer-cache - path: /tmp/composer-cache - -- name: PHPUnit - image: joomlaprojects/docker-images:php7.0 - commands: - - vendor/bin/phpunit - -volumes: -- name: composer-cache - host: - path: /tmp/composer-cache - ---- -kind: pipeline -name: PHP 7.1 - -platform: - os: linux - arch: amd64 - -steps: -- name: composer - image: joomlaprojects/docker-images:php7.1 - commands: - - php -v - - composer update --prefer-stable - volumes: - - name: composer-cache - path: /tmp/composer-cache - -- name: PHPUnit - image: joomlaprojects/docker-images:php7.1 - commands: - - vendor/bin/phpunit - -volumes: -- name: composer-cache - host: - path: /tmp/composer-cache - ---- -kind: pipeline -name: PHP 7.2 - -platform: - os: linux - arch: amd64 - -steps: -- name: composer - image: joomlaprojects/docker-images:php7.2 - commands: - - php -v - - composer update --prefer-stable + image: joomlaprojects/docker-images:php8.1 + name: composer volumes: - name: composer-cache path: /tmp/composer-cache - -- name: PHPUnit - image: joomlaprojects/docker-images:php7.2 - commands: +- commands: - vendor/bin/phpunit - + image: joomlaprojects/docker-images:php8.1 + name: PHPUnit volumes: -- name: composer-cache - host: +- host: path: /tmp/composer-cache - + name: composer-cache --- kind: pipeline -name: PHP 7.3 - -platform: - os: linux - arch: amd64 - +name: PHP 8.1 steps: -- name: composer - image: joomlaprojects/docker-images:php7.3 - commands: +- commands: - php -v - composer update --prefer-stable + image: joomlaprojects/docker-images:php8.1 + name: composer volumes: - name: composer-cache path: /tmp/composer-cache - -- name: PHPUnit - image: joomlaprojects/docker-images:php7.3 - commands: +- commands: - vendor/bin/phpunit - + image: joomlaprojects/docker-images:php8.1 + name: PHPUnit volumes: -- name: composer-cache - host: +- host: path: /tmp/composer-cache - + name: composer-cache --- kind: pipeline -name: PHP 7.4 - -platform: - os: linux - arch: amd64 - +name: PHP 8.2 steps: -- name: composer - image: joomlaprojects/docker-images:php7.4 - commands: +- commands: - php -v - composer update --prefer-stable + image: joomlaprojects/docker-images:php8.2 + name: composer volumes: - name: composer-cache path: /tmp/composer-cache - -- name: PHPUnit - image: joomlaprojects/docker-images:php7.4 - commands: +- commands: - vendor/bin/phpunit - + image: joomlaprojects/docker-images:php8.2 + name: PHPUnit volumes: -- name: composer-cache - host: +- host: path: /tmp/composer-cache - ---- -kind: pipeline -name: PHP 8.0 - -platform: - os: linux - arch: amd64 - -steps: -- name: composer - image: joomlaprojects/docker-images:php8.0 - commands: - - php -v - - composer update --ignore-platform-reqs --prefer-stable - volumes: - - name: composer-cache - path: /tmp/composer-cache - -- name: PHPUnit - image: joomlaprojects/docker-images:php8.0 - commands: - - vendor/bin/phpunit - failure: ignore - -volumes: -- name: composer-cache - host: - path: /tmp/composer-cache - + name: composer-cache --- kind: signature -hmac: c732468b134cba58a2c7c0148566f552bb2a9c9e22e56d5a425ac284fedab713 +hmac: 5e5d25d380c8471aa6a55d802339463ba763c8b2337c8810984e93a0c2f6b6e4 ... diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 00000000..78a64203 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,10 @@ +# EditorConfig is awesome: https://EditorConfig.org + +# Unix-style newlines with a newline ending every file +[*] +indent_style = space +indent_size = 4 +end_of_line = lf +charset = utf-8 +trim_trailing_whitespace = true +insert_final_newline = true 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 ef61a36a..f648e067 100644 --- a/README.md +++ b/README.md @@ -1,17 +1,22 @@ -# The Github Package [](https://ci.joomla.org/joomla-framework/github-api) +# The GitHub Package [](https://github.com/joomla-framework/github-api) -## Using the Github Package +[](https://packagist.org/packages/joomla/github) +[](https://packagist.org/packages/joomla/github) +[](https://packagist.org/packages/joomla/github) +[](https://packagist.org/packages/joomla/github) -The Github package is designed to be a straightforward interface for working with Github. It is based on version 3 of -the Github API. You can find documentation on the API at [http://developer.github.com/v3/](http://developer.github.com/v3/). +## Using the GitHub Package -Github is built upon the Http package which provides an easy way to consume URLs and web services in a transport +The GitHub package is designed to be a straightforward interface for working with GitHub. It is based on version 3 of +the GitHub API. You can find documentation on the API at [http://developer.github.com/v3/](http://developer.github.com/v3/). + +GitHub is built upon the Http package which provides an easy way to consume URLs and web services in a transport independent way. `Joomla\Http` currently supports streams, sockets and cURL. It is possible to create a custom -context and inject it into the Github class if one so desires. +context and inject it into the GitHub class if one so desires. -### Instantiating Github +### Instantiating GitHub -Instantiating Github is easy: +Instantiating GitHub is easy: ```php use Joomla\Github\Github; @@ -19,11 +24,11 @@ use Joomla\Github\Github; $github = new Github; ``` -This creates a basic Github object that can be used to access publicly available resources on [github.com](https://github.com). +This creates a basic GitHub object that can be used to access publicly available resources on [github.com](https://github.com). Sometimes it is necessary to specify additional options. This can be done by injecting in a Registry object with your -preferred options. Support is available for optionally providing a custom Github account username and password, -as well as a custom URL for the Github server (as would be the case for using a local instance of [Github Enterprise](https://enterprise.github.com)). +preferred options. Support is available for optionally providing a custom GitHub account username and password, +as well as a custom URL for the GitHub server (as would be the case for using a local instance of [GitHub Enterprise](https://enterprise.github.com)). ```php use Joomla\Github\Github; @@ -39,7 +44,7 @@ $github = new Github($options); A `gh.token` option is also available. -Here is an example demonstrating more of the Github package: +Here is an example demonstrating more of the GitHub package: ```php use Joomla\Github\Github; @@ -67,13 +72,13 @@ $summary = implode("\n", $issueSummary); $github->gists->create(array('issue_summary.txt' => $summary)); ``` -## Accessing the Github APIs +## Accessing the GitHub APIs -The Github object using magic methods to access sub-packages of the Github server's API that can be accessed using +The GitHub object using magic methods to access sub-packages of the GitHub server's API that can be accessed using the `->` object operator. Where a result is returned by a PHP method, the result is the PHP equivalent of the JSON response that can be found in -the Github API documentation. +the GitHub API documentation. ### Activity @@ -743,17 +748,17 @@ $github->pulls->comments->delete(':owner', ':repo', ':commentId'); ## See Also The following resources contain more information: [Joomla! API Reference](http://api.joomla.org), -[Github API Reference](http://developer.github.com). +[GitHub API Reference](http://developer.github.com). ## Installation via Composer -Add `"joomla/github": "~1.0"` to the require block in your composer.json and then run `composer install`. +Add `"joomla/github": "~2.0"` to the require block in your composer.json and then run `composer install`. ```json { "require": { - "joomla/github": "~1.0" + "joomla/github": "~2.0" } } ``` @@ -761,11 +766,11 @@ Add `"joomla/github": "~1.0"` to the require block in your composer.json and the Alternatively, you can simply run the following from the command line: ```sh -composer require joomla/github "~1.0" +composer require joomla/github "~2.0" ``` If you want to include the test sources, use ```sh -composer require --prefer-source joomla/github "~1.0" +composer require --prefer-source joomla/github "~2.0" ``` diff --git a/SECURITY.md b/SECURITY.md new file mode 100644 index 00000000..4574d2ad --- /dev/null +++ b/SECURITY.md @@ -0,0 +1,22 @@ +# Security Policy + +## Supported Versions + +These versions are currently being supported with security updates: + +| Version | Supported | +| ------- | ------------------ | +| 2.0.x | :white_check_mark: | +| 1.7.x | :white_check_mark: | +| < 1.7 | :x: | + +## Reporting a Vulnerability + +To report a security issue in the core Joomla! CMS or Framework, or with a joomla.org website, please submit +[the form on our portal](https://developer.joomla.org/security/contact-the-team.html) containing as much detail +as possible about the issue. Additional information about our security team and their processes may be found on +our [Security page](https://developer.joomla.org/security.html). + +To report an issue in a Joomla! extension, please submit it to the [Vulnerable Extensions List](https://vel.joomla.org/submit-vel). + +For support with a site which has been attacked, please visit the [Joomla! Forum](https://forum.joomla.org/viewforum.php?f=714). diff --git a/Tests/GithubObjectTest.php b/Tests/GithubObjectTest.php index 4d75ff4b..43bf0795 100755 --- a/Tests/GithubObjectTest.php +++ b/Tests/GithubObjectTest.php @@ -1,16 +1,14 @@ client = new Http(array(), $transport); - $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 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); - - self::assertEquals( - $expected, - $this->object->fetchUrl($path, $page, $limit), - 'URL is not as 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'); - - self::assertEquals( - 'https://MyTestUser:MyTestPass@api.github.com/gists', - $this->object->fetchUrl('/gists', 0, 0), - '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'); - - self::assertEquals( - 'https://api.github.com/gists', - (string) $this->object->fetchUrl('/gists', 0, 0), - 'URL is not as expected.' - ); - - self::assertEquals( - array('Authorization' => 'token MyTestToken'), - $this->client->getOption('headers'), - '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 d954df2b..f372a0cb 100755 --- a/Tests/GithubTest.php +++ b/Tests/GithubTest.php @@ -1,6 +1,7 @@ object = new Github($this->options, $this->client); - } - - /** - * Tests the magic __get method - forks - * - * @return void - * - * @since 1.0 - */ - public function test__GetForks() - { - $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 test__GetCommits() - { - $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 test__GetStatuses() - { - $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 test__GetHooks() - { - $this->assertThat( - $this->object->repositories->hooks, - $this->isInstanceOf('Joomla\Github\Package\Repositories\Hooks') - ); - } - - /** - * Tests the magic __get method - failure - * - * @return void - * - * @since 1.0 - * @expectedException \InvalidArgumentException - */ - public function test__GetFailure() - { - $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/HttpTest.php b/Tests/HttpTest.php deleted file mode 100755 index 48ef3a6f..00000000 --- a/Tests/HttpTest.php +++ /dev/null @@ -1,68 +0,0 @@ -transport = $this->getMockBuilder('Joomla\\Http\\TransportInterface') - ->setConstructorArgs(array($this->options)) - ->getMock(); - - $this->object = new Http($this->options, $this->transport); - } - - /** - * Tests the __construct method - * - * @return void - * - * @since 1.0 - */ - public function test__Construct() - { - // Verify the options are set in the object - $this->assertThat( - $this->object->getOption('userAgent'), - $this->equalTo('JGitHub/2.0') - ); - - $this->assertThat( - $this->object->getOption('timeout'), - $this->equalTo(120) - ); - } -} diff --git a/Tests/Package/Activity/EventsTest.php b/Tests/Package/Activity/EventsTest.php index f65762df..1e39801c 100644 --- a/Tests/Package/Activity/EventsTest.php +++ b/Tests/Package/Activity/EventsTest.php @@ -1,6 +1,7 @@ object = new Events($this->options, $this->client); - } - - /** - * Tests the getPublic method - * - * @return void - */ - public function testGetPublic() - { - $this->response->code = 200; - $this->response->body = $this->sampleString; - - $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() - { - $this->response->code = 200; - $this->response->body = $this->sampleString; - - $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() - { - $this->response->code = 200; - $this->response->body = $this->sampleString; - - $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() - { - $this->response->code = 200; - $this->response->body = $this->sampleString; - - $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() - { - $this->response->code = 200; - $this->response->body = $this->sampleString; - - $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() - { - $this->response->code = 200; - $this->response->body = $this->sampleString; - - $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() - { - $this->response->code = 200; - $this->response->body = $this->sampleString; - - $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() - { - $this->response->code = 200; - $this->response->body = $this->sampleString; - - $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() - { - $this->response->code = 200; - $this->response->body = $this->sampleString; - - $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() - { - $this->response->code = 200; - $this->response->body = $this->sampleString; - - $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 7290d74d..173c7010 100644 --- a/Tests/Package/Activity/FeedsTest.php +++ b/Tests/Package/Activity/FeedsTest.php @@ -1,6 +1,7 @@ object = new Feeds($this->options, $this->client); - } - - /** - * Tests the getFeeds method - * - * @return void - */ - public function testGetFeeds() - { - $this->response->code = 200; - $this->response->body = $this->sampleString; - - $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 7af79b0e..66d06e7b 100644 --- a/Tests/Package/Activity/NotificationsTest.php +++ b/Tests/Package/Activity/NotificationsTest.php @@ -1,6 +1,7 @@ object = new Notifications($this->options, $this->client); - } - - /** - * Tests the getList method - * - * @return void - */ - public function testGetList() - { - $this->response->code = 200; - $this->response->body = $this->sampleString; - - $this->client->expects($this->once()) - ->method('get') - ->with('/notifications?all=1&participating=1', array(), 0) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->getList(), - $this->equalTo(json_decode($this->response->body)) - ); - } - - /** - * Tests the getListRepository method - * - * @return void - */ - public function testGetListRepository() - { - $this->response->code = 200; - $this->response->body = $this->sampleString; - - $this->client->expects($this->once()) - ->method('get') - ->with('/repos/joomla/joomla-platform/notifications?all=1&participating=1', array(), 0) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->getListRepository('joomla', 'joomla-platform'), - $this->equalTo(json_decode($this->response->body)) - ); - } - - /** - * Tests the markRead method - * - * @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) - ); - } - - /** - * Tests the markReadLastRead method - * - * @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) - ); - } - - /** - * Tests the markReadRepository method - * - * @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) - ); - } - - /** - * Tests the markReadRepositoryLastRead method - * - * @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) - ); - } - - /** - * Tests the viewThread method - * - * @return void - */ - public function testViewThread() - { - $this->response->code = 200; - $this->response->body = $this->sampleString; - - $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)) - ); - } - - /** - * Tests the markReadThread method - * - * @return void - */ - public function testMarkReadThread() - { - $this->response->code = 205; - $this->response->body = $this->sampleString; - - $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)) - ); - } - - /** - * Tests the getThreadSubscription method - * - * @return void - */ - public function testGetThreadSubscription() - { - $this->response->code = 200; - $this->response->body = $this->sampleString; - - $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)) - ); - } - - /** - * Tests the setThreadSubscription method - * - * @return void - */ - public function testSetThreadSubscription() - { - $this->response->code = 200; - $this->response->body = $this->sampleString; - - $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)) - ); - } - - /** - * Tests the deleteThreadSubscription method - * - * @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 fd4dca7e..c1c4cf8f 100644 --- a/Tests/Package/Activity/StarringTest.php +++ b/Tests/Package/Activity/StarringTest.php @@ -1,6 +1,7 @@ object = new Starring($this->options, $this->client); - } - - /** - * Tests the getList method - * - * @return void - */ - public function testGetList() - { - $this->response->code = 200; - $this->response->body = $this->sampleString; - - $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)) - ); - } - - /** - * Tests the getRepositories method - * - * @return void - */ - public function testGetRepositories() - { - $this->response->code = 200; - $this->response->body = $this->sampleString; - - $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)) - ); - } - - /** - * Tests the getRepositories method - invalid sort option - * - * @return void - * - * @expectedException \InvalidArgumentException - */ - public function testGetRepositoriesInvalidSort() - { - $this->object->getRepositories('', 'invalid'); - } - - /** - * Tests the getRepositories method - invalid direction option - * - * @return void - * - * @expectedException \InvalidArgumentException - */ - public function testGetRepositoriesInvalidDirection() - { - $this->object->getRepositories('', 'created', 'invalid'); - } - - /** - * Tests the check method - * - * @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)) - ); - } - - /** - * Tests the checkFalse method - * - * @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)) - ); - } - - /** - * Tests the checkUnexpected method - * - * @expectedException \UnexpectedValueException - * @return void - */ - public function testCheckUnexpected() - { - $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)) - ); - } - - /** - * Tests the star method - * - * @return void - */ - public function testStar() - { - $this->response->code = 204; - $this->response->body = $this->sampleString; - - $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)) - ); - } - - /** - * Tests the unstar method - * - * @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 245392ae..5bc9b1e5 100644 --- a/Tests/Package/Activity/WatchingTest.php +++ b/Tests/Package/Activity/WatchingTest.php @@ -1,6 +1,7 @@ object = new Watching($this->options, $this->client); - } - - /** - * Tests the getList method - * - * @return void - */ - public function testGetList() - { - $this->response->code = 200; - $this->response->body = $this->sampleString; - - $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->response->code = 200; - $this->response->body = $this->sampleString; - - $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->response->code = 200; - $this->response->body = $this->sampleString; - - $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->response->code = 200; - $this->response->body = $this->sampleString; - - $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->response->code = 200; - $this->response->body = $this->sampleString; - - $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 - * - * @expectedException \UnexpectedValueException - * @return void - */ - public function testCheckUnexpected() - { - $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 d0f3b9a6..8d56ef88 100644 --- a/Tests/Package/ActivityTest.php +++ b/Tests/Package/ActivityTest.php @@ -1,6 +1,7 @@ object = new Activity($this->options, $this->client); - } + $this->object = new Activity($this->options, $this->client); + } - /** - * Tests the construct method. - * - * @return void - * - * @since 1.0 - */ - public function testConstruct() - { - } + /** + * 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 04e6c5ce..0a303f9a 100644 --- a/Tests/Package/AuthorizationsTest.php +++ b/Tests/Package/AuthorizationsTest.php @@ -1,6 +1,7 @@ object = new Authorization($this->options, $this->client); - } - - /** - * Tests the createAuthorisation method - * - * @return void - * - * @since 1.0 - */ - public function testCreate() - { - $this->response->code = 201; - $this->response->body = $this->sampleString; - - $authorisation = new \stdClass; - $authorisation->scopes = array('public_repo'); - $authorisation->note = 'My test app'; - $authorisation->note_url = 'http://www.joomla.org'; - - $this->client->expects($this->once()) - ->method('post') - ->with('/authorizations', json_encode($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 = new \stdClass; - $authorisation->scopes = array('public_repo'); - $authorisation->note = 'My test app'; - $authorisation->note_url = 'http://www.joomla.org'; - - $this->client->expects($this->once()) - ->method('post') - ->with('/authorizations', json_encode($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->response->body = $this->sampleString; - - $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->response->body = $this->sampleString; - - $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() - { - $this->response->code = 200; - $this->response->body = $this->sampleString; - - $authorisation = new \stdClass; - $authorisation->add_scopes = array('public_repo', 'gist'); - $authorisation->note = 'My test app'; - $authorisation->note_url = 'http://www.joomla.org'; - - $this->client->expects($this->once()) - ->method('patch') - ->with('/authorizations/42', json_encode($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() - { - $this->response->code = 200; - $this->response->body = $this->sampleString; - - $authorisation = new \stdClass; - $authorisation->remove_scopes = array('public_repo', 'gist'); - $authorisation->note = 'My test app'; - $authorisation->note_url = 'http://www.joomla.org'; - - $this->client->expects($this->once()) - ->method('patch') - ->with('/authorizations/42', json_encode($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() - { - $this->response->code = 200; - $this->response->body = $this->sampleString; - - $authorisation = new \stdClass; - $authorisation->scopes = array('public_repo', 'gist'); - $authorisation->note = 'My test app'; - $authorisation->note_url = 'http://www.joomla.org'; - - $this->client->expects($this->once()) - ->method('patch') - ->with('/authorizations/42', json_encode($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 = new \stdClass; - $authorisation->add_scopes = array('public_repo', 'gist'); - $authorisation->note = 'My test app'; - $authorisation->note_url = 'http://www.joomla.org'; - - $this->client->expects($this->once()) - ->method('patch') - ->with('/authorizations/42', json_encode($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 - * - * @expectedException \RuntimeException - */ - public function testEditTooManyScopes() - { - $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->response->code = 200; - $this->response->body = $this->sampleString; - - $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 - * - * @expectedException \DomainException - */ - public function testGetFailure() - { - $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->response->code = 200; - $this->response->body = $this->sampleString; - - $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 - * - * @expectedException \DomainException - */ - public function testGetGrantFailure() - { - $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->response->code = 200; - $this->response->body = $this->sampleString; - - $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 - * - * @expectedException \DomainException - */ - public function testGetListFailure() - { - $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->response->code = 200; - $this->response->body = $this->sampleString; - - $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 - * - * @expectedException \DomainException - */ - public function testGetListGrantsFailure() - { - $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->response->code = 200; - $this->response->body = $this->sampleString; - - $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 testGetRateLimit_unlimited() - { - $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 - * - * @expectedException \DomainException - */ - public function testGetRateLimitFailure() - { - $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 - * - * @expectedException \UnexpectedValueException - */ - public function testRequestTokenInvalidFormat() - { - $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->response->body = $this->sampleString; - - $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 - * - * @expectedException \DomainException - */ - public function testRevokeGrantForApplicationFailure() - { - $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 00f652e6..856fabd5 100644 --- a/Tests/Package/Data/BlobsTest.php +++ b/Tests/Package/Data/BlobsTest.php @@ -1,6 +1,7 @@ object = new Blobs($this->options, $this->client); - } + /** + * 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(); - /** - * Tests the get method - * - * @return void - */ - public function testGet() - { - $this->response->code = 200; - $this->response->body = $this->sampleString; + $this->object = new Blobs($this->options, $this->client); + } - $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; - $this->response->body = $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/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 1dc87818..21b8f959 100644 --- a/Tests/Package/Data/CommitsTest.php +++ b/Tests/Package/Data/CommitsTest.php @@ -1,6 +1,7 @@ object = new Commits($this->options, $this->client); - } + /** + * 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(); - /** - * Tests the get method - * - * @return void - */ - public function testGet() - { - $this->response->code = 200; - $this->response->body = $this->sampleString; + $this->object = new Commits($this->options, $this->client); + } - $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; - $this->response->body = $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/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 d8aa0543..36af0dc5 100755 --- a/Tests/Package/Data/RefsTest.php +++ b/Tests/Package/Data/RefsTest.php @@ -1,6 +1,7 @@ object = new Refs($this->options, $this->client); - } - - /** - * Tests the get method - * - * @return void - */ - public function testGet() - { - $this->response->code = 200; - $this->response->body = $this->sampleString; - - $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 - * - * @expectedException \DomainException - * - * @return void - */ - public function testGetFailure() - { - $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; - $this->response->body = $this->sampleString; - - // 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 - * - * @expectedException \DomainException - * - * @return void - */ - public function testCreateFailure() - { - $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() - { - $this->response->code = 200; - $this->response->body = $this->sampleString; - - // 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 - * - * @expectedException \DomainException - * - * @return void - */ - public function testEditFailure() - { - $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->response->code = 200; - $this->response->body = $this->sampleString; - - $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->response->code = 200; - $this->response->body = $this->sampleString; - - $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 - * - * @expectedException \DomainException - * - * @return void - */ - public function testGetListFailure() - { - $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 - * - * @expectedException \DomainException - * - * @return void - */ - public function testDeleteFailure() - { - $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 4a37b70c..f3861735 100644 --- a/Tests/Package/Data/TagsTest.php +++ b/Tests/Package/Data/TagsTest.php @@ -1,6 +1,7 @@ object = new Tags($this->options, $this->client); - } + /** + * 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(); - /** - * Tests the get method - * - * @return void - */ - public function testGet() - { - $this->response->code = 200; - $this->response->body = $this->sampleString; + $this->object = new Tags($this->options, $this->client); + } - $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; - $this->response->body = $this->sampleString; + /** + * 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 3cbf2df7..f3459cfd 100644 --- a/Tests/Package/Data/TreesTest.php +++ b/Tests/Package/Data/TreesTest.php @@ -1,6 +1,7 @@ object = new Trees($this->options, $this->client); - } + /** + * @var Trees Object under test. + * @since 1.0 + */ + protected $object; - /** - * Tests the get method - * - * @return void - */ - public function testGet() - { - $this->response->code = 200; - $this->response->body = $this->sampleString; + /** + * 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->client->expects($this->once()) - ->method('get') - ->with('/repos/joomla/joomla-platform/git/trees/12345', array(), 0) - ->will($this->returnValue($this->response)); + $this->object = new Trees($this->options, $this->client); + } - $this->assertThat( - $this->object->get('joomla', 'joomla-platform', '12345'), - $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/git/trees/12345', [], 0) + ->will($this->returnValue($this->response)); - /** - * Tests the getRecursively method - * - * @return void - */ - public function testGetRecursively() - { - $this->response->code = 200; - $this->response->body = $this->sampleString; + $this->assertThat( + $this->object->get('joomla', 'joomla-platform', '12345'), + $this->equalTo(json_decode($this->response->body)) + ); + } - $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; - $this->response->body = $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/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 e899eddf..95a997dc 100644 --- a/Tests/Package/DataTest.php +++ b/Tests/Package/DataTest.php @@ -1,6 +1,7 @@ object = new Data($this->options, $this->client); - } + $this->object = new Data($this->options, $this->client); + } - /** - * Tests the construct method. - * - * @return void - * - * @since 1.0 - */ - public function testConstruct() - { - } + /** + * 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 95f7d3be..0ad9dbd7 100755 --- a/Tests/Package/EmojisTest.php +++ b/Tests/Package/EmojisTest.php @@ -1,6 +1,7 @@ object = new Emojis($this->options, $this->client); - } + /** + * 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(); - /** - * Tests the getList method - * - * @return void - */ - public function testGetList() - { - $this->response->code = 200; - $this->response->body = $this->sampleString; + $this->object = new Emojis($this->options, $this->client); + } - $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 4ed0a6ad..26f5454d 100755 --- a/Tests/Package/GistsTest.php +++ b/Tests/Package/GistsTest.php @@ -1,6 +1,7 @@ object = new Gists($this->options, $this->client); - } - - /** - * Tests the create method - * - * @return void - */ - public function testCreate() - { - $this->response->code = 201; - $this->response->body = $this->sampleString; - - // 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; - $this->response->body = $this->sampleString; - - // 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 - * - * @expectedException \InvalidArgumentException - * - * @return void - */ - public function testCreateGistFromFileNotFound() - { - $this->response->code = 501; - $this->response->body = $this->sampleString; - - $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; - $this->response->body = $this->sampleString; - - $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->response->body = $this->sampleString; - - $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->response->body = $this->sampleString; - - $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() - { - $this->response->code = 200; - $this->response->body = $this->sampleString; - - // 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() - { - $this->response->code = 200; - $this->response->body = $this->sampleString; - - $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->response->body = $this->sampleString; - - $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->response->code = 200; - $this->response->body = $this->sampleString; - - $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->response->code = 200; - $this->response->body = $this->sampleString; - - $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->response->code = 200; - $this->response->body = $this->sampleString; - - $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->response->code = 200; - $this->response->body = $this->sampleString; - - $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->response->code = 200; - $this->response->body = $this->sampleString; - - $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->response->code = 200; - $this->response->body = $this->sampleString; - - $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->response->code = 200; - $this->response->body = $this->sampleString; - - $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->response->code = 200; - $this->response->body = $this->sampleString; - - $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->response->code = 200; - $this->response->body = $this->sampleString; - - $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->response->code = 200; - $this->response->body = $this->sampleString; - - $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->response->body = $this->sampleString; - - $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->response->body = $this->sampleString; - - $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->response->body = $this->sampleString; - - $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->response->body = $this->sampleString; - - $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 b79af71f..8a9de29d 100644 --- a/Tests/Package/GitignoreTest.php +++ b/Tests/Package/GitignoreTest.php @@ -1,6 +1,7 @@ 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,54 +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" + "source": "# Object files\n*.o\n\n# Libraries\n*.lib\n*.a\n\n# Shared objects (inc. Windows DLLs)\n' + . '*.dll\n*.so\n*.so.*\n*.dylib\n\n# Executables\n*.exe\n*.out\n*.app\n" }'; - $this->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 @@ -122,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. - * - * @expectedException \DomainException - * - * @since 1.0 - * @return void - */ - public function testGetFailure() - { - $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 e1c874e1..6538debb 100644 --- a/Tests/Package/GraphqlTest.php +++ b/Tests/Package/GraphqlTest.php @@ -1,6 +1,7 @@ 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 c9c21811..6ce15ec9 100644 --- a/Tests/Package/Issues/AssigneesTest.php +++ b/Tests/Package/Issues/AssigneesTest.php @@ -1,6 +1,7 @@ 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. - * - * @expectedException \DomainException - * - * @return void - */ - public function testCheckException() - { - $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', array(), null, json_encode(array('assignees' => array('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 c9822e13..86e13639 100644 --- a/Tests/Package/Issues/CommentsTest.php +++ b/Tests/Package/Issues/CommentsTest.php @@ -1,6 +1,7 @@ object = new Comments($this->options, $this->client); - } - - /** - * Tests the getList method - * - * @return void - */ - public function testGetList() - { - $this->response->code = 200; - $this->response->body = $this->sampleString; - - $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->response->code = 200; - $this->response->body = $this->sampleString; - - $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 - * - * @expectedException \UnexpectedValueException - * @return void - */ - public function testGetRepositoryListInvalidSort() - { - $this->response->code = 200; - $this->response->body = $this->sampleString; - - $this->object->getRepositoryList('joomla', 'joomla-platform', 'invalid'); - } - - /** - * Tests the getRepositoryListInvalidDirection method - * - * @expectedException \UnexpectedValueException - * @return void - */ - public function testGetRepositoryListInvalidDirection() - { - $this->response->code = 200; - $this->response->body = $this->sampleString; - - $this->object->getRepositoryList('joomla', 'joomla-platform', 'created', 'invalid'); - } - - /** - * Tests the getRepositoryListSince method - * - * @return void - */ - public function testGetRepositoryListSince() - { - $this->response->code = 200; - $this->response->body = $this->sampleString; - - $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->response->code = 200; - $this->response->body = $this->sampleString; - - $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->response->code = 200; - $this->response->body = $this->sampleString; - - $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->response->body = $this->sampleString; - - $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 420b2037..b0a4189c 100644 --- a/Tests/Package/Issues/EventsTest.php +++ b/Tests/Package/Issues/EventsTest.php @@ -1,6 +1,7 @@ object = new Events($this->options, $this->client); - } - - /** - * Tests the getList method - * - * @return void - */ - public function testGetList() - { - $this->response->code = 200; - $this->response->body = $this->sampleString; + /** + * @var Events Object under test. + * @since 1.0 + */ + protected $object; - $this->client->expects($this->once()) - ->method('get') - ->with('/repos/joomla/joomla-platform/issues/1/events', array(), 0) - ->will($this->returnValue($this->response)); + /** + * 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->assertThat( - $this->object->getList('joomla', 'joomla-platform', '1'), - $this->equalTo(json_decode($this->response->body)) - ); - } + $this->object = new Events($this->options, $this->client); + } - /** - * Tests the getListRepository method - * - * @return void - */ - public function testGetListRepository() - { - $this->response->code = 200; - $this->response->body = $this->sampleString; + /** + * 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->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)) + ); + } - $this->assertThat( - $this->object->getListRepository('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', [], 0) + ->will($this->returnValue($this->response)); - /** - * Tests the get method - * - * @return void - */ - public function testGet() - { - $this->response->code = 200; - $this->response->body = $this->sampleString; + $this->assertThat( + $this->object->getListRepository('joomla', 'joomla-platform', '1'), + $this->equalTo(json_decode($this->response->body)) + ); + } - $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 be8dee1e..400e62ea 100644 --- a/Tests/Package/Issues/LabelsTest.php +++ b/Tests/Package/Issues/LabelsTest.php @@ -1,6 +1,7 @@ object = new Labels($this->options, $this->client); - } - - /** - * Tests the getList method - * - * @return void - */ - public function testGetList() - { - $this->response->code = 200; - $this->response->body = $this->sampleString; - - $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->response->code = 200; - $this->response->body = $this->sampleString; - - $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->response->body = $this->sampleString; - - $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 - * - * @expectedException \DomainException - * @return void - */ - public function testCreateFailure() - { - $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->response->code = 200; - $this->response->body = $this->sampleString; - - $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->response->body = $this->sampleString; - - $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->response->code = 200; - $this->response->body = $this->sampleString; - - $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->response->code = 200; - $this->response->body = $this->sampleString; - - $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->response->code = 200; - $this->response->body = $this->sampleString; - - $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->response->code = 200; - $this->response->body = $this->sampleString; - - $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->response->body = $this->sampleString; - - $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->response->code = 200; - $this->response->body = $this->sampleString; - - $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 c6959f5d..e1fbcee1 100644 --- a/Tests/Package/Issues/MilestonesTest.php +++ b/Tests/Package/Issues/MilestonesTest.php @@ -1,6 +1,7 @@ object = new Milestones($this->options, $this->client); - } - - /** - * Tests the create method - * - * @return void - * - * @since 1.0 - */ - public function testCreate() - { - $this->response->code = 201; - $this->response->body = $this->sampleString; - - $milestone = new \stdClass; - $milestone->title = 'My Milestone'; - $milestone->state = 'open'; - $milestone->description = 'This milestone is impossible'; - $milestone->due_on = '2012-12-25T20:09:31Z'; - - $this->client->expects($this->once()) - ->method('post') - ->with('/repos/joomla/joomla-platform/milestones', json_encode($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 - * - * @expectedException \DomainException - * - * @return void - * - * @since 12.3 - */ - public function testCreateFailure() - { - $this->response->code = 501; - $this->response->body = $this->errorString; - - $milestone = new \stdClass; - $milestone->title = 'My Milestone'; - $milestone->state = 'open'; - $milestone->description = 'This milestone is impossible'; - $milestone->due_on = '2012-12-25T20:09:31Z'; - - $this->client->expects($this->once()) - ->method('post') - ->with('/repos/joomla/joomla-platform/milestones', json_encode($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() - { - $this->response->code = 200; - $this->response->body = $this->sampleString; - - $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() - { - $this->response->code = 200; - $this->response->body = $this->sampleString; - - $milestone = new \stdClass; - $milestone->title = 'This is the revised title.'; - $milestone->state = 'closed'; - $milestone->description = 'This describes it perfectly.'; - $milestone->due_on = '2012-12-25T20:09:31Z'; - - $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, 'This is the revised title.', 'closed', 'This describes it perfectly.', - '2012-12-25T20:09:31Z'), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Tests the edit method - failure - * - * @expectedException \DomainException - * - * @return void - * - * @since 12.3 - */ - public function testEditFailure() - { - $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->response->code = 200; - $this->response->body = $this->sampleString; - - $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 - * - * @expectedException \DomainException - * - * @return void - * - * @since 12.3 - */ - public function testGetFailure() - { - $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->response->code = 200; - $this->response->body = $this->sampleString; - - $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 - * - * @expectedException \DomainException - * - * @return void - * - * @since 12.3 - */ - public function testGetListFailure() - { - $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->response->body = $this->sampleString; - - $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 - * - * @expectedException \DomainException - * - * @return void - * - * @since 12.3 - */ - public function testDeleteFailure() - { - $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 a53908a6..5272c0f3 100755 --- a/Tests/Package/IssuesTest.php +++ b/Tests/Package/IssuesTest.php @@ -1,6 +1,7 @@ object = new Issues($this->options, $this->client); - } - - /** - * Tests the create method with assignee - * - * @return void - */ - public function testCreate() - { - $this->response->code = 201; - $this->response->body = $this->sampleString; - - $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->assertThat( - $this->object->create('{user}', '{repo}', '{title}', '{body}', '{assignee}', '{milestone}', array('{label1}')), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Tests the create method with assignees - * - * @return void - */ - public function testCreate2() - { - $this->response->code = 201; - $this->response->body = $this->sampleString; - - $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)) - ); - } - - /** - * Tests the create method - failure - * - * @expectedException \DomainException - * - * @return void - */ - public function testCreateFailure() - { - $this->response->code = 501; - $this->response->body = $this->errorString; - - $issue = new \stdClass; - $issue->title = '{title}'; - $issue->milestone = '{milestone}'; - $issue->labels = array(); - $issue->body = '{body}'; - - $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}', null, '{milestone}'); - } - - /** - * Tests the create method - failure assigning both assignee and assignees. - * - * @expectedException \UnexpectedValueException - * @expectedExceptionMessage You cannot pass both assignee and assignees. Only one may be provided. - * - * @return void - */ - public function testCreateFailure2() - { - $this->object->create('{user}', '{repo}', '{title}', '{body}', '{assignee]', '{milestone}', array('{label1}'), array('{assignee1]')); - } - - /** - * Tests the createComment method - * - * @return void - */ - public function testCreateComment() - { - $this->response->code = 201; - $this->response->body = $this->sampleString; - - $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)) - ); - } - - /** - * Tests the createComment method - failure - * - * @expectedException \DomainException - * - * @return void - */ - public function testCreateCommentFailure() - { - $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'); - } - - /** - * Tests the createLabel method - * @todo move - * @return void - * - public function testCreateLabel() - { - $this->response->code = 201; - $this->response->body = $this->sampleString; - - $issue = new \stdClass; - $issue->name = 'My Insightful Label'; - $issue->color = 'My Insightful Color'; - - $this->client->expects($this->once()) - ->method('post') - ->with('/repos/joomla/joomla-platform/labels', json_encode($issue)) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->createLabel('joomla', 'joomla-platform', 'My Insightful Label', 'My Insightful Color'), - $this->equalTo(json_decode($this->sampleString)) - ); - } - */ - - /** - * Tests the createLabel method - failure - * @todo move - * @expectedException \DomainException - * - * @return void - * - public function testCreateLabelFailure() - { - $this->response->code = 501; - $this->response->body = $this->errorString; - - $issue = new \stdClass; - $issue->name = 'My Insightful Label'; - $issue->color = 'My Insightful Color'; - - $this->client->expects($this->once()) - ->method('post') - ->with('/repos/joomla/joomla-platform/labels', json_encode($issue)) - ->will($this->returnValue($this->response)); - - $this->object->createLabel('joomla', 'joomla-platform', 'My Insightful Label', 'My Insightful Color'); - } - */ - - /** - * Tests the deleteComment method - * @todo move - * @return void - * - public function testDeleteComment() - { - $this->response->code = 204; - $this->response->body = $this->sampleString; - - $this->client->expects($this->once()) - ->method('delete') - ->with('/repos/joomla/joomla-platform/issues/comments/254') - ->will($this->returnValue($this->response)); - - $this->object->deleteComment('joomla', 'joomla-platform', 254); - } - */ - - /** - * Tests the deleteComment method - failure - * @todo move - * @expectedException \DomainException - * - * @return void - * - public function testDeleteCommentFailure() - { - $this->response->code = 504; - $this->response->body = $this->errorString; - - $this->client->expects($this->once()) - ->method('delete') - ->with('/repos/joomla/joomla-platform/issues/comments/254') - ->will($this->returnValue($this->response)); - - $this->object->deleteComment('joomla', 'joomla-platform', 254); - } - */ - - /** - * Tests the deleteLabel method - * @todo move - * @return void - * - public function testDeleteLabel() - { - $this->response->code = 204; - $this->response->body = $this->sampleString; - - $this->client->expects($this->once()) - ->method('delete') - ->with('/repos/joomla/joomla-platform/labels/254') - ->will($this->returnValue($this->response)); - - $this->object->deleteLabel('joomla', 'joomla-platform', 254); - } - */ - - /** - * Tests the deleteLabel method - failure - * @todo move - * @expectedException \DomainException - * - * @return void - * - public function testDeleteLabelFailure() - { - $this->response->code = 504; - $this->response->body = $this->errorString; - - $this->client->expects($this->once()) - ->method('delete') - ->with('/repos/joomla/joomla-platform/labels/254') - ->will($this->returnValue($this->response)); - - $this->object->deleteLabel('joomla', 'joomla-platform', 254); - } - */ - - /** - * Tests the edit method - * - * @return void - */ - public function testEdit() - { - $this->response->code = 200; - $this->response->body = $this->sampleString; - - $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)) - ); - } - - /** - * Tests the edit method - failure - * - * @expectedException \DomainException - * - * @return void - */ - public function testEditFailure() - { - $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'); - } - - /** - * Tests the editComment method - * @todo move - * @return void - * - public function testEditComment() - { - $this->response->code = 200; - $this->response->body = $this->sampleString; - - $issue = new \stdClass; - $issue->body = 'This comment is now even more insightful'; - - $this->client->expects($this->once()) - ->method('patch') - ->with('/repos/joomla/joomla-platform/issues/comments/523', json_encode($issue)) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->editComment('joomla', 'joomla-platform', 523, 'This comment is now even more insightful'), - $this->equalTo(json_decode($this->sampleString)) - ); - } - */ - - /** - * Tests the editComment method - failure - * @todo move - * @expectedException \DomainException - * - * @return void - * - public function testEditCommentFailure() - { - $this->response->code = 500; - $this->response->body = $this->errorString; - - $issue = new \stdClass; - $issue->body = 'This comment is now even more insightful'; - - $this->client->expects($this->once()) - ->method('patch') - ->with('/repos/joomla/joomla-platform/issues/comments/523', json_encode($issue)) - ->will($this->returnValue($this->response)); - - $this->object->editComment('joomla', 'joomla-platform', 523, 'This comment is now even more insightful'); - } - */ - - /** - * Tests the editLabel method - * @todo move - * @return void - * - public function testEditLabel() - { - $this->response->code = 200; - $this->response->body = $this->sampleString; - - $issue = new \stdClass; - $issue->name = 'This label is now even more insightful'; - $issue->color = 'This color is now even more insightful'; - - $this->client->expects($this->once()) - ->method('patch') - ->with('/repos/joomla/joomla-platform/labels/523', json_encode($issue)) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->editLabel('joomla', 'joomla-platform', 523, 'This label is now even more insightful', 'This color is now even more insightful'), - $this->equalTo(json_decode($this->sampleString)) - ); - } - */ - - /** - * Tests the editLabel method - failure - * @todo move - * @expectedException \DomainException - * - * @return void - * - public function testEditLabelFailure() - { - $this->response->code = 500; - $this->response->body = $this->errorString; - - $issue = new \stdClass; - $issue->name = 'This label is now even more insightful'; - $issue->color = 'This color is now even more insightful'; - - $this->client->expects($this->once()) - ->method('patch') - ->with('/repos/joomla/joomla-platform/labels/523', json_encode($issue)) - ->will($this->returnValue($this->response)); - - $this->object->editLabel('joomla', 'joomla-platform', 523, 'This label is now even more insightful', 'This color is now even more insightful'); - } - */ - - /** - * Tests the get method - * - * @return void - */ - public function testGet() - { - $this->response->code = 200; - $this->response->body = $this->sampleString; - - $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)) - ); - } - - /** - * Tests the get method - failure - * - * @expectedException \DomainException - * - * @return void - */ - public function testGetFailure() - { - $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); - } - - /** - * Tests the getComment method - * @todo move - * @return void - * - public function testGetComment() - { - $this->response->code = 200; - $this->response->body = $this->sampleString; - - $this->client->expects($this->once()) - ->method('get') - ->with('/repos/joomla/joomla-platform/issues/comments/523') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->getComment('joomla', 'joomla-platform', 523), - $this->equalTo(json_decode($this->sampleString)) - ); - } - */ - - /** - * Tests the getComment method - failure - * @todo move - * @expectedException \DomainException - * - * @return void - * - public function testGetCommentFailure() - { - $this->response->code = 500; - $this->response->body = $this->errorString; - - $this->client->expects($this->once()) - ->method('get') - ->with('/repos/joomla/joomla-platform/issues/comments/523') - ->will($this->returnValue($this->response)); - - $this->object->getComment('joomla', 'joomla-platform', 523); - } - */ - - /** - * Tests the getComments method - * @todo move - * @return void - * - public function testGetComments() - { - $this->response->code = 200; - $this->response->body = $this->sampleString; - - $this->client->expects($this->once()) - ->method('get') - ->with('/repos/joomla/joomla-platform/issues/523/comments') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->getComments('joomla', 'joomla-platform', 523), - $this->equalTo(json_decode($this->sampleString)) - ); - } - */ - - /** - * Tests the getComments method - failure - * @todo move - * @expectedException \DomainException - * - * @return void - * - public function testGetCommentsFailure() - { - $this->response->code = 500; - $this->response->body = $this->errorString; - - $this->client->expects($this->once()) - ->method('get') - ->with('/repos/joomla/joomla-platform/issues/523/comments') - ->will($this->returnValue($this->response)); - - $this->object->getComments('joomla', 'joomla-platform', 523); - } - */ - - /** - * Tests the getLabel method - * @todo move - * @return void - * - public function testGetLabel() - { - $this->response->code = 200; - $this->response->body = $this->sampleString; - - $this->client->expects($this->once()) - ->method('get') - ->with('/repos/joomla/joomla-platform/labels/My Insightful Label') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->getLabel('joomla', 'joomla-platform', 'My Insightful Label'), - $this->equalTo(json_decode($this->sampleString)) - ); - } - */ - - /** - * Tests the getLabel method - failure - * @todo move - * @expectedException \DomainException - * - * @return void - * - public function testGetLabelFailure() - { - $this->response->code = 500; - $this->response->body = $this->errorString; - - $this->client->expects($this->once()) - ->method('get') - ->with('/repos/joomla/joomla-platform/labels/My Insightful Label') - ->will($this->returnValue($this->response)); - - $this->object->getLabel('joomla', 'joomla-platform', 'My Insightful Label'); - } - */ - - /** - * Tests the getLabels method - * @todo move - * @return void - * - public function testGetLabels() - { - $this->response->code = 200; - $this->response->body = $this->sampleString; - - $this->client->expects($this->once()) - ->method('get') - ->with('/repos/joomla/joomla-platform/labels') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->getLabels('joomla', 'joomla-platform'), - $this->equalTo(json_decode($this->sampleString)) - ); - } - */ - - /** - * Tests the getLabels method - failure - * @todo move - * @expectedException \DomainException - * - * @return void - * - public function testGetLabelsFailure() - { - $this->response->code = 500; - $this->response->body = $this->errorString; - - $this->client->expects($this->once()) - ->method('get') - ->with('/repos/joomla/joomla-platform/labels') - ->will($this->returnValue($this->response)); - - $this->object->getLabels('joomla', 'joomla-platform'); - } - */ - - /** - * Tests the getList method - * - * @return void - */ - public function testGetList() - { - $this->response->code = 200; - $this->response->body = $this->sampleString; - - $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)) - ); - } - - /** - * Tests the getList method - failure - * - * @expectedException \DomainException - * - * @return void - */ - public function testGetListFailure() - { - $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(); - } - - /** - * Tests the getListByRepository method - * - * @return void - */ - public function testGetListByRepository() - { - $this->response->code = 200; - $this->response->body = $this->sampleString; - - $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)) - ); - } - - /** - * Tests the getListByRepository method with all parameters - * - * @return void - */ - public function testGetListByRepositoryAll() - { - $date = new \DateTime('January 1, 2012 12:12:12', new \DateTimeZone('UTC')); - $this->response->code = 200; - $this->response->body = $this->sampleString; - - $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)) - ); - } - - /** - * Tests the getListByRepository method - failure - * - * @expectedException \DomainException - * - * @return void - */ - public function testGetListByRepositoryFailure() - { - $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'); - } - - /** - * Tests the lock method - * - * @return void - */ - public function testLock() - { - $this->response->code = 204; - $this->response->body = $this->sampleString; - - $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)) - ); - } - - /** - * Tests the lock method - failure - * - * @expectedException \DomainException - * - * @return void - */ - public function testLockFailure() - { - $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); - } - - /** - * Tests the unlock method - * - * @return void - */ - public function testUnlock() - { - $this->response->code = 204; - $this->response->body = $this->sampleString; - - $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)) - ); - } - - /** - * Tests the unlock method - failure - * - * @expectedException \DomainException - * - * @return void - */ - public function testUnlockFailure() - { - $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 0686788a..8f31d555 100644 --- a/Tests/Package/MarkdownTest.php +++ b/Tests/Package/MarkdownTest.php @@ -1,6 +1,7 @@ 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 - * - * @expectedException \InvalidArgumentException - */ - public function testRenderInvalidMode() - { - $this->assertThat( - $this->object->render('', 'xxx', 'github/gollum'), - $this->equalTo('') - ); - } - - /** - * Tests the renderFailure method - * - * @return void - * - * @expectedException \DomainException - */ - public function testRenderFailure() - { - $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 15a15bc9..dd20ee95 100644 --- a/Tests/Package/MetaTest.php +++ b/Tests/Package/MetaTest.php @@ -1,6 +1,7 @@ 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() - { - $this->response->code = 200; - $this->response->body = $this->sampleString; + /** + * 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']; - $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'); + $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 - * - * @expectedException \DomainException - */ - public function testGetMetaFailure() - { - $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 17e415e2..b99201f5 100644 --- a/Tests/Package/Orgs/HooksTest.php +++ b/Tests/Package/Orgs/HooksTest.php @@ -1,6 +1,7 @@ object = new Hooks($this->options, $this->client); - } - - /** - * Tests the getList method - * - * @return void - */ - public function testGetList() - { - $this->response->code = 200; - $this->response->body = $this->sampleString; - - $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)) - ); - } - - /** - * Tests the get method - * - * @return void - */ - public function testGet() - { - $this->response->code = 200; - $this->response->body = $this->sampleString; - - $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)) - ); - } - - /** - * Tests the create method - * - * @return void - */ - public function testCreate() - { - $this->response->code = 201; - $this->response->body = $this->sampleString; - - $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)) - ); - } - - /** - * Tests the create method - * - * @return void - * - * @expectedException \UnexpectedValueException - */ - public function testCreateFailure() - { - $this->object->create('joomla', '{url}', '{invalid}'); - } - - /** - * Tests the edit method - * - * @return void - */ - public function testEdit() - { - $this->response->code = 201; - $this->response->body = $this->sampleString; - - $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)) - ); - } - - /** - * Tests the edit method - * - * @return void - * - * @expectedException \UnexpectedValueException - */ - public function testEditFailure() - { - $this->object->edit('joomla', '{url}', '{invalid}'); - } - - /** - * Tests the edit method - * - * @return void - * - * @expectedException \RuntimeException - */ - public function testEditFailure2() - { - $this->object->edit('{org}', '{url}', 'json', '{secret}', 1, array('{invalid}')); - } - - /** - * Tests the ping method - * - * @return void - */ - public function testPing() - { - $this->response->code = 204; - $this->response->body = $this->sampleString; - - $this->client->expects($this->once()) - ->method('post') - ->with('/orgs/joomla/hooks/123/pings') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->ping('joomla', 123), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Tests the delete method - * - * @return void - */ - public function testDelete() - { - $this->response->code = 204; - $this->response->body = $this->sampleString; - - $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 4b54f2a2..604ed50a 100644 --- a/Tests/Package/Orgs/MembersTest.php +++ b/Tests/Package/Orgs/MembersTest.php @@ -1,338 +1,503 @@ object = new Members($this->options, $this->client); - } - - /** - * Tests the getList method - * - * @return void - */ - public function testGetList() - { - $this->response->code = 200; - $this->response->body = $this->sampleString; - - $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)) - ); - } - - /** - * Tests the getListNotAMember method - * - * @return void - */ - public function testGetListNotAMember() - { - $this->response->code = 302; - $this->response->body = $this->sampleString; - - $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) - ); - } - - /** - * Tests the getListUnexpected method - * - * @return void - * - * @expectedException \UnexpectedValueException - */ - public function testGetListUnexpected() - { - $this->response->code = 666; - $this->response->body = $this->sampleString; - - $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)) - ); - } - - /** - * Tests the check method - * - * @return void - */ - public function testCheck() - { - $this->response->code = 204; - $this->response->body = $this->sampleString; - - $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) - ); - } - - /** - * Tests the checkNoMember method - * - * @return void - */ - public function testCheckNoMember() - { - $this->response->code = 404; - $this->response->body = $this->sampleString; - - $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) - ); - } - - /** - * Tests the checkRequesterNoMember method - * - * @return void - */ - public function testCheckRequesterNoMember() - { - $this->response->code = 302; - $this->response->body = $this->sampleString; - - $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) - ); - } - - /** - * Tests the checkUnexpectedr method - * - * @return void - * - * @expectedException \UnexpectedValueException - */ - public function testCheckUnexpectedr() - { - $this->response->code = 666; - $this->response->body = $this->sampleString; - - $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) - ); - } - - /** - * Tests the remove method - * - * @return void - */ - public function testRemove() - { - $this->response->code = 204; - $this->response->body = $this->sampleString; - - $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)) - ); - } - - /** - * Tests the getListPublic method - * - * @return void - */ - public function testGetListPublic() - { - $this->response->code = 200; - $this->response->body = $this->sampleString; - - $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)) - ); - } - - /** - * Tests the checkPublic method - * - * @return void - */ - public function testCheckPublic() - { - $this->response->code = 204; - $this->response->body = $this->sampleString; - - $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) - ); - } - - /** - * Tests the checkPublicNo method - * - * @return void - */ - public function testCheckPublicNo() - { - $this->response->code = 404; - $this->response->body = $this->sampleString; - - $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) - ); - } - - /** - * Tests the checkPublicUnexpected method - * - * @return void - * - * @expectedException \UnexpectedValueException - */ - public function testCheckPublicUnexpected() - { - $this->response->code = 666; - $this->response->body = $this->sampleString; - - $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) - ); - } - - /** - * Tests the publicize method - * - * @return void - */ - public function testPublicize() - { - $this->response->code = 204; - $this->response->body = $this->sampleString; - - $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)) - ); - } - - /** - * Tests the conceal method - * - * @return void - */ - public function testConceal() - { - $this->response->code = 204; - $this->response->body = $this->sampleString; - - $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)) - ); - } + /** + * @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 ee54d2ee..2e55c2dd 100644 --- a/Tests/Package/Orgs/TeamsTest.php +++ b/Tests/Package/Orgs/TeamsTest.php @@ -1,6 +1,7 @@ object = new Teams($this->options, $this->client); - } - - /** - * Tests the getList method - * - * @return void - */ - public function testGetList() - { - $this->response->code = 200; - $this->response->body = $this->sampleString; - - $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)) - ); - } - - /** - * Tests the get method - * - * @return void - */ - public function testGet() - { - $this->response->code = 200; - $this->response->body = $this->sampleString; - - $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)) - ); - } - - /** - * Tests the create method - * - * @return void - */ - public function testCreate() - { - $this->response->code = 201; - $this->response->body = $this->sampleString; - - $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)) - ); - } - - /** - * Tests the createWrongPermission method - * - * @return void - * - * @expectedException \UnexpectedValueException - */ - public function testCreateWrongPermission() - { - $this->response->code = 201; - $this->response->body = $this->sampleString; - - $this->object->create('joomla', 'TheTeam', array('joomla-platform'), 'invalid'); - } - - /** - * Tests the edit method - * - * @return void - */ - public function testEdit() - { - $this->response->code = 200; - $this->response->body = $this->sampleString; - - $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)) - ); - } - - /** - * Tests the editWrongPermission method - * - * @return void - * - * @expectedException \UnexpectedValueException - */ - public function testEditWrongPermission() - { - $this->response->code = 200; - $this->response->body = $this->sampleString; - - $this->object->edit(123, 'TheTeam', 'invalid'); - } - - /** - * Tests the delete method - * - * @return void - */ - public function testDelete() - { - $this->response->code = 204; - $this->response->body = $this->sampleString; - - $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)) - ); - } - - /** - * Tests the getListMembers method - * - * @return void - */ - public function testGetListMembers() - { - $this->response->code = 200; - $this->response->body = $this->sampleString; - - $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)) - ); - } - - /** - * Tests the isMember method - * - * @return void - */ - public function testIsMember() - { - $this->response->code = 204; - $this->response->body = $this->sampleString; - - $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)) - ); - } - - /** - * Tests the isMemberNo method - * - * @return void - */ - public function testIsMemberNo() - { - $this->response->code = 404; - $this->response->body = $this->sampleString; - - $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)) - ); - } - - /** - * Tests the isMemberUnexpected method - * - * @return void - * - * @expectedException \UnexpectedValueException - */ - public function testIsMemberUnexpected() - { - $this->response->code = 666; - $this->response->body = $this->sampleString; - - $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)) - ); - } - - /** - * Tests the addMember method - * - * @return void - */ - public function testAddMember() - { - $this->response->code = 204; - $this->response->body = $this->sampleString; - - $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)) - ); - } - - /** - * Tests the removeMember method - * - * @return void - */ - public function testRemoveMember() - { - $this->response->code = 204; - $this->response->body = $this->sampleString; - - $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)) - ); - } - - /** - * Tests the getListRepos method - * - * @return void - */ - public function testGetListRepos() - { - $this->response->code = 200; - $this->response->body = $this->sampleString; - - $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)) - ); - } - - /** - * Tests the checkRepo method - * - * @return void - */ - public function testCheckRepo() - { - $this->response->code = 204; - $this->response->body = $this->sampleString; - - $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) - ); - } - - /** - * Tests the checkRepoNo method - * - * @return void - */ - public function testCheckRepoNo() - { - $this->response->code = 404; - $this->response->body = $this->sampleString; - - $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) - ); - } - - /** - * Tests the checkRepoUnexpected method - * - * @return void - * - * @expectedException \UnexpectedValueException - */ - public function testCheckRepoUnexpected() - { - $this->response->code = 666; - $this->response->body = $this->sampleString; - - $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) - ); - } - - /** - * Tests the addRepo method - * - * @return void - */ - public function testAddRepo() - { - $this->response->code = 204; - $this->response->body = $this->sampleString; - - $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)) - ); - } - - /** - * Tests the removeRepo method - * - * @return void - */ - public function testRemoveRepo() - { - $this->response->code = 204; - $this->response->body = $this->sampleString; - - $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)) - ); - } + /** + * @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 7b9a795d..28acae74 100644 --- a/Tests/Package/OrgsTest.php +++ b/Tests/Package/OrgsTest.php @@ -1,6 +1,7 @@ object = new Orgs($this->options, $this->client); - } - - /** - * Tests the getList method - * - * @return void - */ - public function testGetList() - { - $this->response->code = 200; - $this->response->body = $this->sampleString; + /** + * @var Orgs + */ + protected $object; - $this->client->expects($this->once()) - ->method('get') - ->with('/users/joomla/orgs') - ->will($this->returnValue($this->response)); + /** + * 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->assertThat( - $this->object->getList('joomla'), - $this->equalTo(json_decode($this->sampleString)) - ); - } + $this->object = new Orgs($this->options, $this->client); + } - /** - * Tests the get method - * - * @return void - */ - public function testGet() - { - $this->response->code = 200; - $this->response->body = $this->sampleString; + /** + * 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->client->expects($this->once()) - ->method('get') - ->with('/orgs/joomla') - ->will($this->returnValue($this->response)); + $this->assertThat( + $this->object->getList('joomla'), + $this->equalTo(json_decode($this->sampleString)) + ); + } - $this->assertThat( - $this->object->get('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 edit method - * - * @return void - */ - public function testEdit() - { - $this->response->code = 200; - $this->response->body = $this->sampleString; + $this->assertThat( + $this->object->get('joomla'), + $this->equalTo(json_decode($this->sampleString)) + ); + } - $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 12e4fc15..faaea5a5 100644 --- a/Tests/Package/Pulls/CommentsTest.php +++ b/Tests/Package/Pulls/CommentsTest.php @@ -1,6 +1,7 @@ object = new Comments($this->options, $this->client); - } - - /** - * Tests the create method - * - * @return void - */ - public function testCreate() - { - $this->response->code = 201; - $this->response->body = $this->sampleString; - - $this->client->expects($this->once()) - ->method('post') - ->with('/repos/joomla/joomla-platform/pulls/1/comments', '{"body":"The Body","commit_id":"123abc","path":"a\/b\/c","position":456}', 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)) - ); - } - - /** - * Tests the createReply method - * - * @return void - */ - public function testCreateReply() - { - $this->response->code = 201; - $this->response->body = $this->sampleString; - - $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)) - ); - } - - /** - * 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/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)) - ); - } - - /** - * Tests the edit method - * - * @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)) - ); - } - - /** - * Tests the get method - * - * @return void - */ - public function testGet() - { - $this->response->code = 200; - $this->response->body = $this->sampleString; - - $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)) - ); - } - - /** - * Tests the getList method - * - * @return void - */ - public function testGetList() - { - $this->response->code = 200; - $this->response->body = $this->sampleString; - - $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)) - ); - } + /** + * @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 b56098b0..e75bd4d6 100755 --- a/Tests/Package/PullsTest.php +++ b/Tests/Package/PullsTest.php @@ -1,6 +1,7 @@ object = new Pulls($this->options, $this->client); - } - - /** - * Tests the create method - * - * @return void - */ - public function testCreate() - { - $this->response->code = 201; - $this->response->body = $this->sampleString; - - $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 - * - * @expectedException \DomainException - * - * @return void - */ - public function testCreateFailure() - { - $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 createComment method - * @todo move - * @return void - * - public function testCreateComment() - { - $this->response->code = 201; - $this->response->body = $this->sampleString; - - $pull = new \stdClass; - $pull->body = 'My Insightful Comment'; - $pull->commit_id = 'abcde12345'; - $pull->path = '/path/to/file'; - $pull->position = 254; - - $this->client->expects($this->once()) - ->method('post') - ->with('/repos/joomla/joomla-platform/pulls/523/comments', json_encode($pull)) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->createComment('joomla', 'joomla-platform', 523, 'My Insightful Comment', 'abcde12345', '/path/to/file', 254), - $this->equalTo(json_decode($this->sampleString)) - ); - } - */ - - /** - * Tests the createComment method - failure - * @todo move - * @expectedException \DomainException - * - * @return void - * - public function testCreateCommentFailure() - { - $this->response->code = 501; - $this->response->body = $this->errorString; - - $pull = new \stdClass; - $pull->body = 'My Insightful Comment'; - $pull->commit_id = 'abcde12345'; - $pull->path = '/path/to/file'; - $pull->position = 254; - - $this->client->expects($this->once()) - ->method('post') - ->with('/repos/joomla/joomla-platform/pulls/523/comments', json_encode($pull)) - ->will($this->returnValue($this->response)); - - $this->object->createComment('joomla', 'joomla-platform', 523, 'My Insightful Comment', 'abcde12345', '/path/to/file', 254); - } - */ - - /** - * Tests the createCommentReply method - * @todo move - * @return void - * - public function testCreateCommentReply() - { - $this->response->code = 201; - $this->response->body = $this->sampleString; - - $pull = new \stdClass; - $pull->body = 'My Insightful Comment'; - $pull->in_reply_to = 434; - - $this->client->expects($this->once()) - ->method('post') - ->with('/repos/joomla/joomla-platform/pulls/523/comments', json_encode($pull)) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->createCommentReply('joomla', 'joomla-platform', 523, 'My Insightful Comment', 434), - $this->equalTo(json_decode($this->sampleString)) - ); - } - */ - - /** - * Tests the createCommentReply method - failure - * @todo move - * @expectedException \DomainException - * - * @return void - * - public function testCreateCommentReplyFailure() - { - $this->response->code = 501; - $this->response->body = $this->errorString; - - $pull = new \stdClass; - $pull->body = 'My Insightful Comment'; - $pull->in_reply_to = 434; - - $this->client->expects($this->once()) - ->method('post') - ->with('/repos/joomla/joomla-platform/pulls/523/comments', json_encode($pull)) - ->will($this->returnValue($this->response)); - - $this->object->createCommentReply('joomla', 'joomla-platform', 523, 'My Insightful Comment', 434); - } - */ - - /** - * Tests the createFromIssue method - * - * @return void - */ - public function testCreateFromIssue() - { - $this->response->code = 201; - $this->response->body = $this->sampleString; - - $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 - * - * @expectedException \DomainException - * - * @return void - */ - public function testCreateFromIssueFailure() - { - $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 deleteComment method - * @todo move - * @return void - * - public function testDeleteComment() - { - $this->response->code = 204; - $this->response->body = $this->sampleString; - - $this->client->expects($this->once()) - ->method('delete') - ->with('/repos/joomla/joomla-platform/pulls/comments/254') - ->will($this->returnValue($this->response)); - - $this->object->deleteComment('joomla', 'joomla-platform', 254); - } - */ - - /** - * Tests the deleteComment method - failure - * @todo move - * @expectedException \DomainException - * - * @return void - * - public function testDeleteCommentFailure() - { - $this->response->code = 504; - $this->response->body = $this->errorString; - - $this->client->expects($this->once()) - ->method('delete') - ->with('/repos/joomla/joomla-platform/pulls/comments/254') - ->will($this->returnValue($this->response)); - - $this->object->deleteComment('joomla', 'joomla-platform', 254); - } - */ - - /** - * Tests the edit method - * - * @return void - */ - public function testEdit() - { - $this->response->code = 200; - $this->response->body = $this->sampleString; - - $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 - * - * @expectedException \DomainException - * - * @return void - */ - public function testEditFailure() - { - $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 editComment method - * @todo move - * @return void - * - public function testEditComment() - { - $this->response->code = 200; - $this->response->body = $this->sampleString; - - $pull = new \stdClass; - $pull->body = 'This comment is now even more insightful'; - - $this->client->expects($this->once()) - ->method('patch') - ->with('/repos/joomla/joomla-platform/pulls/comments/523', json_encode($pull)) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->editComment('joomla', 'joomla-platform', 523, 'This comment is now even more insightful'), - $this->equalTo(json_decode($this->sampleString)) - ); - } - */ - - /** - * Tests the editComment method - failure - * @todo move - * @expectedException \DomainException - * - * @return void - * - public function testEditCommentFailure() - { - $this->response->code = 500; - $this->response->body = $this->errorString; - - $pull = new \stdClass; - $pull->body = 'This comment is now even more insightful'; - - $this->client->expects($this->once()) - ->method('patch') - ->with('/repos/joomla/joomla-platform/pulls/comments/523', json_encode($pull)) - ->will($this->returnValue($this->response)); - - $this->object->editComment('joomla', 'joomla-platform', 523, 'This comment is now even more insightful'); - } - */ - - /** - * Tests the get method - * - * @return void - */ - public function testGet() - { - $this->response->code = 200; - $this->response->body = $this->sampleString; - - $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 - * - * @expectedException \DomainException - * - * @return void - */ - public function testGetFailure() - { - $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 getComment method - * @todo move - * @return void - * - public function testGetComment() - { - $this->response->code = 200; - $this->response->body = $this->sampleString; - - $this->client->expects($this->once()) - ->method('get') - ->with('/repos/joomla/joomla-platform/pulls/comments/523') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->getComment('joomla', 'joomla-platform', 523), - $this->equalTo(json_decode($this->sampleString)) - ); - } - */ - - /** - * Tests the getComment method - failure - * @todo move - * @expectedException \DomainException - * - * @return void - * - public function testGetCommentFailure() - { - $this->response->code = 500; - $this->response->body = $this->errorString; - - $this->client->expects($this->once()) - ->method('get') - ->with('/repos/joomla/joomla-platform/pulls/comments/523') - ->will($this->returnValue($this->response)); - - $this->object->getComment('joomla', 'joomla-platform', 523); - } - */ - - /** - * Tests the getComments method - * @todo move - * @return void - * - public function testGetComments() - { - $this->response->code = 200; - $this->response->body = $this->sampleString; - - $this->client->expects($this->once()) - ->method('get') - ->with('/repos/joomla/joomla-platform/pulls/523/comments') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->getComments('joomla', 'joomla-platform', 523), - $this->equalTo(json_decode($this->sampleString)) - ); - } - */ - - /** - * Tests the getComments method - failure - * @todo move - * @expectedException \DomainException - * - * @return void - * - public function testGetCommentsFailure() - { - $this->response->code = 500; - $this->response->body = $this->errorString; - - $this->client->expects($this->once()) - ->method('get') - ->with('/repos/joomla/joomla-platform/pulls/523/comments') - ->will($this->returnValue($this->response)); - - $this->object->getComments('joomla', 'joomla-platform', 523); - } - */ - - /** - * Tests the getCommits method - * - * @return void - */ - public function testGetCommits() - { - $this->response->code = 200; - $this->response->body = $this->sampleString; - - $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 - * - * @expectedException \DomainException - * - * @return void - */ - public function testGetCommitsFailure() - { - $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->response->code = 200; - $this->response->body = $this->sampleString; - - $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 - * - * @expectedException \DomainException - * - * @return void - */ - public function testGetFilesFailure() - { - $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->response->code = 200; - $this->response->body = $this->sampleString; - - $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 - * - * @expectedException \DomainException - * - * @return void - */ - public function testGetListFailure() - { - $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->response->body = $this->sampleString; - - $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->response->body = $this->sampleString; - - $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 - * - * @expectedException \DomainException - * - * @return void - */ - public function testIsMergedFailure() - { - $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->response->code = 200; - $this->response->body = $this->sampleString; - - $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 - * - * @expectedException \DomainException - * - * @return void - */ - public function testMergeFailure() - { - $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 new file mode 100644 index 00000000..c9899301 --- /dev/null +++ b/Tests/Package/Repositories/BranchesTest.php @@ -0,0 +1,81 @@ +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)); + + $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)); + + $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 59fdda15..d365db94 100644 --- a/Tests/Package/Repositories/CollaboratorsTest.php +++ b/Tests/Package/Repositories/CollaboratorsTest.php @@ -1,6 +1,7 @@ object = new Collaborators($this->options, $this->client); - } - - /** - * Tests the GetList method. - * - * @return void - */ - public function testGetList() - { - $this->response->code = 200; - $this->response->body = $this->sampleString; - - $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 - * - * @expectedException \UnexpectedValueException - */ - public function testGetUnexpected() - { - $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->response->body = $this->sampleString; - - $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->response->body = $this->sampleString; - - $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 a5c178c6..0b6e441d 100644 --- a/Tests/Package/Repositories/CommentsTest.php +++ b/Tests/Package/Repositories/CommentsTest.php @@ -1,6 +1,7 @@ object = new Comments($this->options, $this->client); - } - - /** - * Tests the GetListRepository method. - * - * @return void - */ - public function testGetListRepository() - { - $this->response->code = 200; - $this->response->body = $this->sampleString; - - $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->response->code = 200; - $this->response->body = $this->sampleString; - - $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->response->code = 200; - $this->response->body = $this->sampleString; - - $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->response->code = 200; - $this->response->body = $this->sampleString; - - $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->response->body = $this->sampleString; - - $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->response->body = $this->sampleString; - - $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 e1688fba..1d7e9065 100644 --- a/Tests/Package/Repositories/CommitsTest.php +++ b/Tests/Package/Repositories/CommitsTest.php @@ -1,6 +1,7 @@ object = new Commits($this->options, $this->client); - } - - /** - * Tests the getCommit method - * - * @return void - * - * @since 1.0 - */ - public function testGetCommit() - { - $this->response->code = 200; - $this->response->body = $this->sampleString; - - $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)) - ); - } - - /** - * Tests the getCommit method - failure - * - * @return void - * - * @since 1.0 - * - * @expectedException \DomainException - */ - public function testGetCommitFailure() - { - $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'); - } - - /** - * Tests the getList method - * - * @return void - * - * @since 1.0 - */ - public function testGetList() - { - $this->response->code = 200; - $this->response->body = $this->sampleString; - - $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)) - ); - } - - /** - * Tests the getList method - failure - * - * @return void - * - * @since 1.0 - * - * @expectedException \DomainException - */ - public function testGetListFailure() - { - $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'); - } - - /** - * Tests the Compare method - * - * @return void - * - * @since 1.0 - */ - public function testCompare() - { - $this->response->code = 200; - $this->response->body = $this->sampleString; - - $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)) - ); - } + /** + * @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 d2dc3bd3..a3467a42 100644 --- a/Tests/Package/Repositories/ContentsTest.php +++ b/Tests/Package/Repositories/ContentsTest.php @@ -1,6 +1,7 @@ object = new Contents($this->options, $this->client); - } - - /** - * Tests the GetReadme method. - * - * @return void - */ - public function testGetReadme() - { - $this->response->code = 200; - $this->response->body = $this->sampleString; - - $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->response->code = 200; - $this->response->body = $this->sampleString; - - $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->response->code = 200; - $this->response->body = $this->sampleString; - - $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->response->code = 200; - $this->response->body = $this->sampleString; - - $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->response->body = $this->sampleString; - - $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->response->body = $this->sampleString; - - $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 - * - * @expectedException \UnexpectedValueException - */ - public function testGetArchiveLinkInvalidFormat() - { - $this->response->code = 302; - $this->response->body = $this->sampleString; - - $this->object->getArchiveLink('joomla', 'joomla-platform', 'invalid'); - } - - /** - * Tests the create method. - * - * @return void - */ - public function testCreate() - { - $this->response->code = 201; - $this->response->body = $this->sampleString; - - $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. - * - * @expectedException \UnexpectedValueException - * - * @return void - */ - public function testCreateFail1() - { - $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. - * - * @expectedException \UnexpectedValueException - * - * @return void - */ - public function testCreateFail2() - { - $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->response->code = 200; - $this->response->body = $this->sampleString; - - $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. - * - * @expectedException \UnexpectedValueException - * - * @return void - */ - public function testUpdateFail1() - { - $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. - * - * @expectedException \UnexpectedValueException - * - * @return void - */ - public function testUpdateFail2() - { - $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->response->code = 200; - $this->response->body = $this->sampleString; - - $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. - * - * @expectedException \UnexpectedValueException - * - * @return void - */ - public function testDeleteFail1() - { - $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. - * - * @expectedException \UnexpectedValueException - * - * @return void - */ - public function testDeleteFail2() - { - $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 188ccab6..a135b672 100644 --- a/Tests/Package/Repositories/DeploymentsTest.php +++ b/Tests/Package/Repositories/DeploymentsTest.php @@ -1,6 +1,7 @@ object = new Deployments($this->options, $this->client); - } - - /** - * Tests the GetList method. - * - * @return void - */ - public function testGetList() - { - $this->response->code = 200; - $this->response->body = $this->sampleString; - - $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->response->body = $this->sampleString; - - $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. - * - * @expectedException \RuntimeException - * - * @return void - */ - public function testCreateMergeConflict() - { - $this->response->code = 409; - $this->response->body = $this->sampleString; - - $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. - * - * @expectedException \UnexpectedValueException - * - * @return void - */ - public function testCreateFailure() - { - $this->response->code = 666; - $this->response->body = $this->sampleString; - - $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->response->code = 200; - $this->response->body = $this->sampleString; - - $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->response->body = $this->sampleString; - - $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. - * - * @expectedException \InvalidArgumentException - * - * @return void - */ - public function testCreateStatusFailure() - { - $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 2eca0846..9e11539e 100644 --- a/Tests/Package/Repositories/DownloadsTest.php +++ b/Tests/Package/Repositories/DownloadsTest.php @@ -1,6 +1,7 @@ object = new Downloads($this->options, $this->client); - } - - /** - * Tests the GetList method. - * - * @return void - */ - public function testGetList() - { - $this->response->code = 200; - $this->response->body = $this->sampleString; - - $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->response->code = 200; - $this->response->body = $this->sampleString; - - $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 - * - * @expectedException \RuntimeException - * @expectedExceptionMessage The GitHub API no longer supports creating downloads. The Releases API should be used instead. - */ - public function testCreate() - { - $this->object->create('joomla', 'joomla-platform', 'aaa.zip', 1234, 'Description', 'content_type'); - } - - /** - * Tests the Upload method. - * - * @return void - * - * @expectedException \RuntimeException - * @expectedExceptionMessage The GitHub API no longer supports creating downloads. The Releases API should be used instead. - */ - public function testUpload() - { - $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->response->body = $this->sampleString; - - $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 febae8ba..a6b6cc20 100755 --- a/Tests/Package/Repositories/ForksTest.php +++ b/Tests/Package/Repositories/ForksTest.php @@ -1,6 +1,7 @@ object = new Forks($this->options, $this->client); - } - - /** - * Tests the create method - * - * @return void - */ - public function testCreate() - { - $this->response->code = 202; - $this->response->body = $this->sampleString; - - // 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 - * - * @expectedException \DomainException - * - * @return void - */ - public function testCreateFailure() - { - $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->response->code = 200; - $this->response->body = $this->sampleString; - - $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 - * - * @expectedException \DomainException - * - * @return void - */ - public function testGetListFailure() - { - $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 028a4f30..4bf84c16 100644 --- a/Tests/Package/Repositories/HooksTest.php +++ b/Tests/Package/Repositories/HooksTest.php @@ -1,6 +1,7 @@ object = new Hooks($this->options, $this->client); - } - - /** - * Tests the create method - * - * @return void - * - * @since 1.0 - */ - public function testCreate() - { - $this->response->code = 201; - $this->response->body = $this->sampleString; - - $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)) - ); - } - - /** - * Tests the create method - simulated failure - * - * @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); - } - - /** - * Tests the create method - unauthorised event - * - * @return void - * - * @since 1.0 - * - * @expectedException \RuntimeException - */ - public function testCreateUnauthorisedEvent() - { - $this->object->create('joomla', 'joomla-platform', 'acunote', array('token' => '123456789'), array('push', 'faker')); - } - - /** - * Tests the delete method - * - * @return void - * - * @since 1.0 - */ - public function testDelete() - { - $this->response->code = 204; - $this->response->body = $this->sampleString; - - $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)) - ); - } - - /** - * 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('/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); - } - - /** - * Tests the edit method - * - * @return void - * - * @since 1.0 - */ - public function testEdit() - { - $this->response->code = 200; - $this->response->body = $this->sampleString; - - $hook = new \stdClass; - $hook->name = 'acunote'; - $hook->config = array('token' => '123456789'); - $hook->events = array('push', 'public'); - $hook->add_events = array('watch'); - $hook->remove_events = array('watch'); - $hook->active = true; - - $this->client->expects($this->once()) - ->method('patch') - ->with('/repos/joomla/joomla-platform/hooks/42', json_encode($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)) - ); - } - - /** - * Tests the edit method - simulated failure - * - * @return void - * - * @since 1.0 - */ - public function testEditFailure() - { - $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->add_events = array('watch'); - $hook->remove_events = array('watch'); - $hook->active = true; - - $this->client->expects($this->once()) - ->method('patch') - ->with('/repos/joomla/joomla-platform/hooks/42', json_encode($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); - } - - /** - * Tests the edit method - unauthorised event - * - * @return void - * - * @since 1.0 - * - * @expectedException RuntimeException - */ - public function testEditUnauthorisedEvent() - { - $this->object->edit('joomla', 'joomla-platform', 42, 'acunote', array('token' => '123456789'), array('invalid')); - } - - /** - * Tests the edit method - unauthorised event - * - * @return void - * - * @since 1.0 - * - * @expectedException \RuntimeException - */ - public function testEditUnauthorisedAddEvent() - { - $this->object->edit('joomla', 'joomla-platform', 42, 'acunote', array('token' => '123456789'), array('push'), array('invalid')); - } - - /** - * Tests the edit method - unauthorised event - * - * @return void - * - * @since 1.0 - * - * @expectedException \RuntimeException - */ - public function testEditUnauthorisedRemoveEvent() - { - $this->object->edit('joomla', 'joomla-platform', 42, 'acunote', array('token' => '123456789'), array('push'), array('push'), array('invalid')); - } - - /** - * Tests the get method - * - * @return void - * - * @since 1.0 - */ - public function testGet() - { - $this->response->code = 200; - $this->response->body = $this->sampleString; - - $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)) - ); - } - - /** - * Tests the get method - failure - * - * @return void - * - * @since 1.0 - * - * @expectedException \DomainException - */ - public function testGetFailure() - { - $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); - } - - /** - * Tests the getList method - * - * @return void - * - * @since 1.0 - */ - public function testGetList() - { - $this->response->code = 200; - $this->response->body = $this->sampleString; - - $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)) - ); - } - - /** - * Tests the getList method - failure - * - * @return void - * - * @since 1.0 - * - * @expectedException \DomainException - */ - public function testGetListFailure() - { - $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'); - } - - /** - * Tests the test method - * - * @return void - * - * @since 1.0 - */ - public function testTest() - { - $this->response->code = 204; - $this->response->body = $this->sampleString; - - $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)) - ); - } - - /** - * Tests the test method - failure - * - * @return void - * - * @since 1.0 - * - * @expectedException \DomainException - */ - public function testTestFailure() - { - $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); - } + /** + * @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 6a9d9498..0243ff46 100644 --- a/Tests/Package/Repositories/KeysTest.php +++ b/Tests/Package/Repositories/KeysTest.php @@ -1,6 +1,7 @@ object = new Keys($this->options, $this->client); - } - - /** - * Tests the GetList method. - * - * @return void - */ - public function testGetList() - { - $this->response->code = 200; - $this->response->body = $this->sampleString; - - $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->response->code = 200; - $this->response->body = $this->sampleString; - - $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->response->body = $this->sampleString; - - $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->response->code = 200; - $this->response->body = $this->sampleString; - - $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 f8531d8f..c7e0c3f1 100644 --- a/Tests/Package/Repositories/MergingTest.php +++ b/Tests/Package/Repositories/MergingTest.php @@ -1,6 +1,7 @@ object = new Merging($this->options, $this->client); - } - - /** - * Tests the Perform method. - * - * @return void - */ - public function testPerform() - { - $this->response->code = 201; - $this->response->body = $this->sampleString; - - $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 - * - * @expectedException \UnexpectedValueException - */ - public function testPerformNoOp() - { - $this->response->code = 204; - $this->response->body = $this->sampleString; - - $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. - * - * @expectedException \UnexpectedValueException - * - * @return void - */ - public function testPerformMissing() - { - $this->response->code = 404; - $this->response->body = $this->sampleString; - - $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. - * - * @expectedException \UnexpectedValueException - * - * @return void - */ - public function testPerformConflict() - { - $this->response->code = 409; - $this->response->body = $this->sampleString; - - $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. - * - * @expectedException \UnexpectedValueException - * - * @return void - */ - public function testPerformUnexpected() - { - $this->response->code = 666; - $this->response->body = $this->sampleString; - - $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 2c422a3c..e723d41d 100644 --- a/Tests/Package/Repositories/PagesTest.php +++ b/Tests/Package/Repositories/PagesTest.php @@ -1,6 +1,6 @@ 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->response->code = 200; - $this->response->body = $this->sampleString; + /** + * 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->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->response->code = 200; - $this->response->body = $this->sampleString; + $this->assertThat( + $this->object->getList('{owner}', '{repo}'), + $this->equalTo(json_decode($this->sampleString)) + ); + } - $this->client->expects($this->once()) - ->method('get') - ->with('/repos/{owner}/{repo}/pages/builds') - ->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->getList('{owner}', '{repo}'), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Tests the GetLatest method. - * - * @return void - */ - public function testGetLatest() - { - $this->response->code = 200; - $this->response->body = $this->sampleString; - - $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 e846c00c..ddd596c8 100644 --- a/Tests/Package/Repositories/ReleasesTest.php +++ b/Tests/Package/Repositories/ReleasesTest.php @@ -1,6 +1,6 @@ object = new Releases($this->options, $this->client); - } - - /** - * Tests the get method - * - * @return void - */ - public function testGet() - { - $this->response->code = 200; - $this->response->body = $this->sampleString; - - $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; - $this->response->body = $this->sampleString; - - $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; - $this->response->body = $this->sampleString; - - $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() - { - $this->response->code = 200; - $this->response->body = $this->sampleString; - - $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 $release) - { - $releases[$release->tag_name] = $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->response->body = $this->sampleString; - - $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->response->code = 200; - $this->response->body = $this->sampleString; - - $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->response->code = 200; - $this->response->body = $this->sampleString; - - $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->response->code = 200; - $this->response->body = $this->sampleString; - - $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() - { - $this->response->code = 200; - $this->response->body = $this->sampleString; - - $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 68d4b43d..4aefac24 100644 --- a/Tests/Package/Repositories/StatisticsTest.php +++ b/Tests/Package/Repositories/StatisticsTest.php @@ -1,6 +1,6 @@ object = new Statistics($this->options, $this->client); - } - - /** - * Tests the getListContributors method. - * - * @return void - */ - public function testContributors() - { - $this->response->code = 200; - $this->response->body = $this->sampleString; - - $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->response->code = 200; - $this->response->body = $this->sampleString; - - $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->response->code = 200; - $this->response->body = $this->sampleString; - - $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->response->code = 200; - $this->response->body = $this->sampleString; - - $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->response->code = 200; - $this->response->body = $this->sampleString; - - $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. - * - * @expectedException \DomainException - * @return void - */ - public function testProcessResponse202() - { - $this->response->code = 202; - $this->response->body = $this->sampleString; - - $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 0a588593..d51a6b73 100755 --- a/Tests/Package/Repositories/StatusesTest.php +++ b/Tests/Package/Repositories/StatusesTest.php @@ -1,6 +1,6 @@ object = new Statuses($this->options, $this->client); - } - - /** - * Tests the create method - * - * @return void - */ - public function testCreate() - { - $this->response->code = 201; - $this->response->body = $this->sampleString; - - // 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)) - ); - } - - /** - * Tests the create method - failure - * - * @expectedException \DomainException - * - * @return void - */ - public function testCreateFailure() - { - $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'); - } - - /** - * Tests the create method - failure - * - * @expectedException \InvalidArgumentException - * - * @return void - */ - public function testCreateInvalidState() - { - $this->response->code = 501; - $this->response->body = $this->errorString; - - $this->object->create('joomla', 'joomla-platform', '6dcb09b5b57875f334f61aebed695e2e4193db5e', 'INVALID'); - } - - /** - * Tests the getList method - * - * @return void - */ - public function testGetList() - { - $this->response->code = 200; - $this->response->body = $this->sampleString; - - $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)) - ); - } - - /** - * Tests the getList method - failure - * - * @expectedException \DomainException - * - * @return void - */ - public function testGetListFailure() - { - $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'); - } + /** + * @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 81781bfb..667d5f0c 100644 --- a/Tests/Package/RepositoriesTest.php +++ b/Tests/Package/RepositoriesTest.php @@ -1,6 +1,6 @@ object = new Repositories($this->options, $this->client); - } - - /** - * Tests the GetListOwn method. - * - * @return void - */ - public function testGetListOwn() - { - $this->response->code = 200; - $this->response->body = $this->sampleString; - - $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. - * - * @expectedException \RuntimeException - * - * @return void - */ - public function testGetListOwnInvalidType() - { - $this->object->getListOwn('INVALID'); - } - - /** - * Tests the GetListOwn method. - * - * @expectedException \RuntimeException - * - * @return void - */ - public function testGetListOwnInvalidSortField() - { - $this->object->getListOwn('all', 'INVALID'); - } - - /** - * Tests the GetListOwn method. - * - * @expectedException \RuntimeException - * - * @return void - */ - public function testGetListOwnInvalidSortOrder() - { - $this->object->getListOwn('all', 'full_name', 'INVALID'); - } - - /** - * Tests the GetListUser method. - * - * @return void - */ - public function testGetListUser() - { - $this->response->code = 200; - $this->response->body = $this->sampleString; - - $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. - * - * @expectedException \RuntimeException - * - * @return void - */ - public function testGetListUserInvalidType() - { - $this->object->getListUser('joomla', 'INVALID'); - } - - /** - * Tests the GetListUser method. - * - * @expectedException \RuntimeException - * - * @return void - */ - public function testGetListUserInvalidSortField() - { - $this->object->getListUser('joomla', 'all', 'INVALID'); - } - - /** - * Tests the GetListUser method. - * - * @expectedException \RuntimeException - * - * @return void - */ - public function testGetListUserInvalidSortOrder() - { - $this->object->getListUser('joomla', 'all', 'full_name', 'INVALID'); - } - - /** - * Tests the GetListOrg method. - * - * @return void - */ - public function testGetListOrg() - { - $this->response->code = 200; - $this->response->body = $this->sampleString; - - $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->response->code = 200; - $this->response->body = $this->sampleString; - - $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->response->body = $this->sampleString; - - $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->response->body = $this->sampleString; - - $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->response->code = 200; - $this->response->body = $this->sampleString; - - $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. - * - * @expectedException \RuntimeException - * - * @return void - */ - public function testGetListOrgInvalidType() - { - $this->object->getListOrg('joomla', 'INVALID'); - } - - /** - * Tests the Edit method. - * - * @return void - */ - public function testEdit() - { - $this->response->code = 200; - $this->response->body = $this->sampleString; - - $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->response->code = 200; - $this->response->body = $this->sampleString; - - $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->response->code = 200; - $this->response->body = $this->sampleString; - - $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->response->code = 200; - $this->response->body = $this->sampleString; - - $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->response->code = 200; - $this->response->body = $this->sampleString; - - $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 GetListBranches method. - * - * @return void - */ - public function testGetListBranches() - { - $this->response->code = 200; - $this->response->body = $this->sampleString; - - $this->client->expects($this->once()) - ->method('get') - ->with('/repos/joomla/joomla-cms/branches', array(), 0) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->getListBranches('joomla', 'joomla-cms'), - $this->equalTo(json_decode($this->response->body)) - ); - } - - /** - * Tests the GetBranch method. - * - * @return void - */ - public function testGetBranch() - { - $this->response->code = 200; - $this->response->body = $this->sampleString; - - $this->client->expects($this->once()) - ->method('get') - ->with('/repos/joomla/joomla-cms/branches/master', array(), 0) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->getBranch('joomla', 'joomla-cms', 'master'), - $this->equalTo(json_decode($this->response->body)) - ); - } - - /** - * Tests the Delete method. - * - * @return void - */ - public function testDelete() - { - $this->response->code = 200; - $this->response->body = $this->sampleString; - - $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 6a9915bf..ea8c758f 100644 --- a/Tests/Package/SearchTest.php +++ b/Tests/Package/SearchTest.php @@ -1,6 +1,6 @@ object = new Search($this->options, $this->client); - } - - /** - * Tests the issues method - * - * @return void - */ - public function testIssues() - { - $this->response->code = 200; - $this->response->body = $this->sampleString; - - $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)) - ); - } - - /** - * Tests the issuesInvalidState method - * - * @return void - * - * @expectedException \UnexpectedValueException - */ - public function testIssuesInvalidState() - { - $this->response->code = 200; - $this->response->body = $this->sampleString; - - $this->object->issues('joomla', 'joomla-platform', 'invalid', 'github'); - } - - /** - * Tests the repositories method - * - * @return void - */ - public function testRepositories() - { - $this->response->code = 200; - $this->response->body = $this->sampleString; - - $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)) - ); - } - - /** - * Tests the users method - * - * @return void - */ - public function testUsers() - { - $this->response->code = 200; - $this->response->body = $this->sampleString; - - $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)) - ); - } - - /** - * Tests the email method - * - * @return void - */ - public function testEmail() - { - $this->response->code = 200; - $this->response->body = $this->sampleString; - - $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)) - ); - } + /** + * @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(); + + $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)); + + $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); + + $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)); + + $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)); + + $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)); + + $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 56bb1b6b..a08eda6b 100644 --- a/Tests/Package/Users/EmailsTest.php +++ b/Tests/Package/Users/EmailsTest.php @@ -1,6 +1,6 @@ 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->response->code = 200; - $this->response->body = $this->sampleString; + /** + * 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->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->response->body = $this->sampleString; + $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->response->body = $this->sampleString; + $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 c4edc77e..00a1c247 100644 --- a/Tests/Package/Users/FollowersTest.php +++ b/Tests/Package/Users/FollowersTest.php @@ -1,6 +1,6 @@ object = new Followers($this->options, $this->client); - } - - /** - * Tests the getList method - * - * @return void - */ - public function testGetList() - { - $this->response->code = 200; - $this->response->body = $this->sampleString; - - $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)) - ); - } - - /** - * Tests the getListWithUser method - * - * @return void - */ - public function testGetListWithUser() - { - $this->response->code = 200; - $this->response->body = $this->sampleString; - - $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)) - ); - } - - /** - * Tests the getListFollowedBy method - * - * @return void - */ - public function testGetListFollowedBy() - { - $this->response->code = 200; - $this->response->body = $this->sampleString; - - $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)) - ); - } - - /** - * Tests the getListFollowedByWithUser method - * - * @return void - */ - public function testGetListFollowedByWithUser() - { - $this->response->code = 200; - $this->response->body = $this->sampleString; - - $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)) - ); - } - - /** - * Tests the check method - * - * @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) - ); - } - - /** - * Tests the checkNo method - * - * @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) - ); - } - - /** - * Tests the checkUnexpected method - * - * @return void - * - * @expectedException \UnexpectedValueException - */ - public function testCheckUnexpected() - { - $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) - ); - } - - /** - * Tests the follow method - * - * @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) - ); - } - - /** - * Tests the unfollow method - * - * @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) - ); - } + /** + * @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 69d42a2d..a5be5862 100644 --- a/Tests/Package/Users/KeysTest.php +++ b/Tests/Package/Users/KeysTest.php @@ -1,6 +1,6 @@ object = new Keys($this->options, $this->client); - } - - /** - * Tests the getListUser method - * - * @return void - */ - public function testGetListUser() - { - $this->response->code = 200; - $this->response->body = $this->sampleString; - - $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->response->code = 200; - $this->response->body = $this->sampleString; - - $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->response->code = 200; - $this->response->body = $this->sampleString; - - $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->response->body = $this->sampleString; - - $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->response->code = 200; - $this->response->body = $this->sampleString; - - $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->response->body = $this->sampleString; - - $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 abc0bd1e..83845b1c 100755 --- a/Tests/Package/UsersTest.php +++ b/Tests/Package/UsersTest.php @@ -1,6 +1,6 @@ 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,48 +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 - * - * @expectedException \DomainException - * @return void - */ - public function testGetFailure() - { - $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", @@ -140,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 - * - * @expectedException \DomainException - * - * @return void - */ - public function testGetAuthenticatedUserFailure() - { - $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, @@ -200,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", @@ -260,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 - * - * @expectedException \DomainException - * - * @return void - */ - public function testEditFailure() - { - $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 7984307e..f7ab1943 100644 --- a/Tests/Package/ZenTest.php +++ b/Tests/Package/ZenTest.php @@ -1,6 +1,6 @@ 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. - * - * @expectedException \RuntimeException - * - * @return void - */ - public function testGetFailure() - { - $this->response->code = 400; - $this->response->body = 'My Zen'; + /** + * Tests the Get method. + * + * @return void + */ + public function testGetFailure() + { + $this->expectException(\RuntimeException::class); - $this->client->expects($this->once()) - ->method('get') - ->with('/zen', array(), 0) - ->will($this->returnValue($this->response)); + $this->response->code = 400; + $this->response->body = 'My Zen'; - $this->assertThat( - $this->object->get(), - $this->equalTo($this->response->body) - ); - } + $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) + ); + } } diff --git a/Tests/PackageTest.php b/Tests/PackageTest.php index 45957570..c86e3c42 100755 --- a/Tests/PackageTest.php +++ b/Tests/PackageTest.php @@ -1,6 +1,6 @@ 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 test__Get() - { - $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 - * - * @expectedException \InvalidArgumentException - */ - public function test__GetInvalid() - { - $this->object->repositories->INVALID; - } + /** + * 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; + } } diff --git a/Tests/Stub/GitHubTestCase.php b/Tests/Stub/GitHubTestCase.php index 7ce28204..c4c91664 100644 --- a/Tests/Stub/GitHubTestCase.php +++ b/Tests/Stub/GitHubTestCase.php @@ -1,6 +1,6 @@ options = new Registry; + $this->options = new Registry(); - $this->client = $this->getMockBuilder('\\Joomla\\Github\\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; + } } diff --git a/Tests/Stub/ObjectMock.php b/Tests/Stub/ObjectMock.php index 7dc91950..fe40373e 100644 --- a/Tests/Stub/ObjectMock.php +++ b/Tests/Stub/ObjectMock.php @@ -1,6 +1,6 @@ -