From d490489375cdeecd61cae96444bf9d9dfae9ba3c Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Fri, 3 Dec 2021 09:17:02 +0100 Subject: [PATCH 1/8] Test on PHP 8 Also: - update PHP-CS-Fixer to 3.0 - use Composer v2 in tests --- .github/workflows/coding-standards.yml | 6 +-- .github/workflows/continuous-integration.yml | 6 ++- .gitignore | 1 + .php-cs-fixer.php | 30 +++++++++++++ .php_cs | 45 -------------------- composer.json | 7 ++- lib/Imgur/Auth/OAuth2.php | 4 +- 7 files changed, 45 insertions(+), 54 deletions(-) create mode 100644 .php-cs-fixer.php delete mode 100644 .php_cs diff --git a/.github/workflows/coding-standards.yml b/.github/workflows/coding-standards.yml index 92843a0..64e4a12 100644 --- a/.github/workflows/coding-standards.yml +++ b/.github/workflows/coding-standards.yml @@ -16,7 +16,7 @@ jobs: strategy: matrix: php: - - "7.3" + - "7.4" steps: - name: "Checkout" @@ -27,7 +27,7 @@ jobs: with: coverage: "none" php-version: "${{ matrix.php }}" - tools: cs2pr, composer:v1 + tools: composer:v2 ini-values: "date.timezone=Europe/Paris" env: COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }} @@ -36,4 +36,4 @@ jobs: uses: "ramsey/composer-install@v1" - name: "Run PHP CS Fixer" - run: "vendor/bin/php-cs-fixer fix --verbose --dry-run --format=checkstyle | cs2pr" + run: "vendor/bin/php-cs-fixer fix --verbose --dry-run" diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index 1a1dab8..42265a8 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -25,6 +25,8 @@ jobs: - "7.2" - "7.3" - "7.4" + - "8.0" + - "8.1" steps: - name: "Checkout" @@ -37,7 +39,7 @@ jobs: with: php-version: "${{ matrix.php }}" coverage: "none" - tools: composer:v1 + tools: composer:v2 extensions: curl ini-values: "date.timezone=Europe/Paris" env: @@ -69,7 +71,7 @@ jobs: with: php-version: "${{ matrix.php }}" coverage: "pcov" - tools: composer:v1 + tools: composer:v2 extensions: curl ini-values: "date.timezone=Europe/Paris" env: diff --git a/.gitignore b/.gitignore index f8b5071..50c4a87 100644 --- a/.gitignore +++ b/.gitignore @@ -4,4 +4,5 @@ vendor coverage build .php_cs.cache +.php-cs-fixer.cache .phpunit.result.cache diff --git a/.php-cs-fixer.php b/.php-cs-fixer.php new file mode 100644 index 0000000..460eecd --- /dev/null +++ b/.php-cs-fixer.php @@ -0,0 +1,30 @@ +in(__DIR__) + ->exclude(['vendor']) +; + +return (new PhpCsFixer\Config()) + ->setRiskyAllowed(true) + ->setRules([ + '@Symfony' => true, + '@Symfony:risky' => true, + 'array_syntax' => ['syntax' => 'short'], + 'combine_consecutive_unsets' => true, + 'heredoc_to_nowdoc' => true, + 'no_extra_blank_lines' => ['tokens' => ['break', 'continue', 'extra', 'return', 'throw', 'use', 'parenthesis_brace_block', 'square_brace_block', 'curly_brace_block']], + 'no_unreachable_default_argument_value' => true, + 'no_useless_else' => true, + 'no_useless_return' => true, + 'ordered_class_elements' => true, + 'ordered_imports' => true, + 'php_unit_strict' => true, + 'phpdoc_order' => true, + // 'psr4' => true, + 'strict_comparison' => true, + 'strict_param' => true, + 'concat_space' => ['spacing' => 'one'], + ]) + ->setFinder($finder) +; diff --git a/.php_cs b/.php_cs deleted file mode 100644 index 5184eaf..0000000 --- a/.php_cs +++ /dev/null @@ -1,45 +0,0 @@ -setRiskyAllowed(true) - ->setRules([ - '@Symfony' => true, - '@Symfony:risky' => true, - 'array_syntax' => [ - 'syntax' => 'short' - ], - 'combine_consecutive_unsets' => true, - 'heredoc_to_nowdoc' => true, - 'no_extra_consecutive_blank_lines' => [ - 'break', - 'continue', - 'extra', - 'return', - 'throw', - 'use', - 'parenthesis_brace_block', - 'square_brace_block', - 'curly_brace_block' - ], - 'no_unreachable_default_argument_value' => true, - 'no_useless_else' => true, - 'no_useless_return' => true, - 'ordered_class_elements' => true, - 'ordered_imports' => true, - 'php_unit_strict' => true, - 'phpdoc_order' => true, - // 'psr4' => true, - 'strict_comparison' => true, - 'strict_param' => true, - 'concat_space' => [ - 'spacing' => 'one' - ], - ]) - ->setFinder( - PhpCsFixer\Finder::create() - ->exclude([ - 'vendor', - ]) - ->in(__DIR__) - ) -; diff --git a/composer.json b/composer.json index cd8a49b..0e643ba 100644 --- a/composer.json +++ b/composer.json @@ -39,7 +39,10 @@ "guzzlehttp/guzzle": "^6.0" }, "require-dev": { - "friendsofphp/php-cs-fixer": "^2.0", - "symfony/phpunit-bridge": "^5.0" + "friendsofphp/php-cs-fixer": "^3.0", + "symfony/phpunit-bridge": "^6.0" + }, + "config": { + "sort-packages": true } } diff --git a/lib/Imgur/Auth/OAuth2.php b/lib/Imgur/Auth/OAuth2.php index 5da0ce3..38752e5 100644 --- a/lib/Imgur/Auth/OAuth2.php +++ b/lib/Imgur/Auth/OAuth2.php @@ -12,8 +12,8 @@ */ class OAuth2 implements AuthInterface { - const AUTHORIZATION_ENDPOINT = 'https://api.imgur.com/oauth2/authorize'; - const ACCESS_TOKEN_ENDPOINT = 'https://api.imgur.com/oauth2/token'; + public const AUTHORIZATION_ENDPOINT = 'https://api.imgur.com/oauth2/authorize'; + public const ACCESS_TOKEN_ENDPOINT = 'https://api.imgur.com/oauth2/token'; /** * Indicates the client that is making the request. From cbdac22b30c890f3e35298e61648a5a88fd478b2 Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Fri, 3 Dec 2021 09:34:55 +0100 Subject: [PATCH 2/8] Convert `@expectedException` to `$this->expectException` --- composer.json | 2 +- tests/Api/AccountTest.php | 29 +++--- tests/Api/AlbumOrImageTest.php | 22 ++--- tests/Api/AlbumTest.php | 7 +- tests/Api/CommentTest.php | 28 +++--- tests/Api/ConversationTest.php | 14 ++- tests/Api/CustomGalleryTest.php | 36 +++---- tests/Api/GalleryTest.php | 120 ++++++++++------------- tests/Api/ImageTest.php | 21 ++-- tests/Api/MemegenTest.php | 7 +- tests/Api/NotificationTest.php | 7 +- tests/Api/TopicTest.php | 21 ++-- tests/Auth/OAuth2Test.php | 30 +++--- tests/ClientTest.php | 16 ++- tests/HttpClient/HttpClientTest.php | 41 ++++---- tests/Middleware/ErrorMiddlewareTest.php | 57 +++++------ 16 files changed, 199 insertions(+), 259 deletions(-) diff --git a/composer.json b/composer.json index 0e643ba..7e47fc5 100644 --- a/composer.json +++ b/composer.json @@ -40,7 +40,7 @@ }, "require-dev": { "friendsofphp/php-cs-fixer": "^3.0", - "symfony/phpunit-bridge": "^6.0" + "symfony/phpunit-bridge": "^5.0" }, "config": { "sort-packages": true diff --git a/tests/Api/AccountTest.php b/tests/Api/AccountTest.php index af32fde..740ea56 100644 --- a/tests/Api/AccountTest.php +++ b/tests/Api/AccountTest.php @@ -8,16 +8,16 @@ use GuzzleHttp\Psr7\Response; use Imgur\Api\Account; use Imgur\Client; +use Imgur\Exception\InvalidArgumentException; use Imgur\HttpClient\HttpClient; class AccountTest extends ApiTestCase { - /** - * @expectedException \Imgur\Exception\ErrorException - * @expectedExceptionMessage Authentication required - */ public function testBaseReal() { + $this->expectException(\Imgur\Exception\ErrorException::class); + $this->expectExceptionMessage('Authentication required'); + $guzzleClient = new GuzzleClient(['base_uri' => 'https://api.imgur.com/3/']); $httpClient = new HttpClient([], $guzzleClient); $client = new Client(null, $httpClient); @@ -116,12 +116,11 @@ public function testGalleryFavorites() $this->assertSame($expectedValue, $api->galleryFavorites()); } - /** - * @expectedException \Imgur\Exception\InvalidArgumentException - * @expectedExceptionMessage is wrong. Possible values are - */ public function testGalleryFavoritesWrongValues() { + $this->expectException(InvalidArgumentException::class); + $this->expectExceptionMessage('is wrong. Possible values are'); + $this->getApiMock()->galleryFavorites('me', 0, 'bad sort'); } @@ -409,12 +408,11 @@ public function testComments() $this->assertSame($expectedValue, $api->comments()); } - /** - * @expectedException \Imgur\Exception\InvalidArgumentException - * @expectedExceptionMessage is wrong. Possible values are - */ public function testCommentsWrongValues() { + $this->expectException(InvalidArgumentException::class); + $this->expectExceptionMessage('is wrong. Possible values are'); + $this->getApiMock()->comments('me', 0, 'bad sort'); } @@ -460,12 +458,11 @@ public function testCommentIds() $this->assertSame($expectedValue, $api->commentIds()); } - /** - * @expectedException \Imgur\Exception\InvalidArgumentException - * @expectedExceptionMessage is wrong. Possible values are - */ public function testCommentIdsWrongValues() { + $this->expectException(InvalidArgumentException::class); + $this->expectExceptionMessage('is wrong. Possible values are'); + $this->getApiMock()->commentIds('me', 0, 'bad sort'); } diff --git a/tests/Api/AlbumOrImageTest.php b/tests/Api/AlbumOrImageTest.php index 5f59044..9e08384 100644 --- a/tests/Api/AlbumOrImageTest.php +++ b/tests/Api/AlbumOrImageTest.php @@ -8,6 +8,7 @@ use GuzzleHttp\Psr7\Response; use Imgur\Api\AlbumOrImage; use Imgur\Client; +use Imgur\Exception\ErrorException; use Imgur\HttpClient\HttpClient; use PHPUnit\Framework\TestCase; @@ -54,12 +55,11 @@ public function testWithAlbumId() $this->assertSame('ok !', $api->find('8pCqe')); } - /** - * @expectedException \Imgur\Exception\ErrorException - * @expectedExceptionMessage Unable to find an album OR an image with the id - */ public function testWithBadId() { + $this->expectException(ErrorException::class); + $this->expectExceptionMessage('id'); + $mock = new MockHandler([ new Response(404, ['Content-Type' => 'application/json'], json_encode([ 'data' => [ @@ -91,12 +91,11 @@ public function testWithBadId() $api->find('xxxxxxx'); } - /** - * @expectedException \Imgur\Exception\ErrorException - * @expectedExceptionMessage oops - */ public function testWithImageIdButBadResponse() { + $this->expectException(ErrorException::class); + $this->expectExceptionMessage('oops'); + $mock = new MockHandler([ new Response(500, ['Content-Type' => 'application/json'], json_encode([ 'data' => [ @@ -119,12 +118,11 @@ public function testWithImageIdButBadResponse() $api->find('ZOY11VC'); } - /** - * @expectedException \Imgur\Exception\ErrorException - * @expectedExceptionMessage oops - */ public function testWithAlbumIdButBadResponse() { + $this->expectException(ErrorException::class); + $this->expectExceptionMessage('oops'); + $mock = new MockHandler([ new Response(404, ['Content-Type' => 'application/json'], json_encode([ 'data' => [ diff --git a/tests/Api/AlbumTest.php b/tests/Api/AlbumTest.php index 151698e..40c55f1 100644 --- a/tests/Api/AlbumTest.php +++ b/tests/Api/AlbumTest.php @@ -12,12 +12,11 @@ class AlbumTest extends ApiTestCase { - /** - * @expectedException \Imgur\Exception\ErrorException - * @expectedExceptionMessage Authentication required - */ public function testBaseReal() { + $this->expectException(\Imgur\Exception\ErrorException::class); + $this->expectExceptionMessage('Authentication required'); + $guzzleClient = new GuzzleClient(['base_uri' => 'https://api.imgur.com/3/']); $httpClient = new HttpClient([], $guzzleClient); $client = new Client(null, $httpClient); diff --git a/tests/Api/CommentTest.php b/tests/Api/CommentTest.php index b1c0978..f0dff54 100644 --- a/tests/Api/CommentTest.php +++ b/tests/Api/CommentTest.php @@ -12,12 +12,11 @@ class CommentTest extends ApiTestCase { - /** - * @expectedException \Imgur\Exception\ErrorException - * @expectedExceptionMessage Authentication required - */ public function testBaseReal() { + $this->expectException(\Imgur\Exception\ErrorException::class); + $this->expectExceptionMessage('Authentication required'); + $guzzleClient = new GuzzleClient(['base_uri' => 'https://api.imgur.com/3/']); $httpClient = new HttpClient([], $guzzleClient); $client = new Client(null, $httpClient); @@ -115,12 +114,11 @@ public function testCreate() $this->assertSame($expectedValue, $api->create(['image_id' => 'ZOY11VC', 'comment' => 'I agree'])); } - /** - * @expectedException \Imgur\Exception\MissingArgumentException - * @expectedExceptionMessage parameters is missing - */ public function testCreateParamMissing() { + $this->expectException(\Imgur\Exception\MissingArgumentException::class); + $this->expectExceptionMessage('parameters is missing'); + $this->getApiMock()->create('726305564'); } @@ -177,12 +175,11 @@ public function testCreateReply() $this->assertSame($expectedValue, $api->createReply('726305565', ['image_id' => 'ZOY11VC', 'comment' => 'I agree'])); } - /** - * @expectedException \Imgur\Exception\MissingArgumentException - * @expectedExceptionMessage parameters is missing - */ public function testCreateReplyParamMissing() { + $this->expectException(\Imgur\Exception\MissingArgumentException::class); + $this->expectExceptionMessage('parameters is missing'); + $this->getApiMock()->createReply('726305564', []); } @@ -203,12 +200,11 @@ public function testVote() $this->assertSame($expectedValue, $api->vote('726305564', 'up')); } - /** - * @expectedException \Imgur\Exception\InvalidArgumentException - * @expectedExceptionMessage is wrong. Possible values are - */ public function testVoteWrongVoteValue() { + $this->expectException(\Imgur\Exception\InvalidArgumentException::class); + $this->expectExceptionMessage('is wrong. Possible values are'); + $this->getApiMock()->vote('726305564', 'bad vote'); } diff --git a/tests/Api/ConversationTest.php b/tests/Api/ConversationTest.php index 2a26eab..0856d20 100644 --- a/tests/Api/ConversationTest.php +++ b/tests/Api/ConversationTest.php @@ -12,12 +12,11 @@ class ConversationTest extends ApiTestCase { - /** - * @expectedException \Imgur\Exception\ErrorException - * @expectedExceptionMessage Authentication required - */ public function testBaseReal() { + $this->expectException(\Imgur\Exception\ErrorException::class); + $this->expectExceptionMessage('Authentication required'); + $guzzleClient = new GuzzleClient(['base_uri' => 'https://api.imgur.com/3/']); $httpClient = new HttpClient([], $guzzleClient); $client = new Client(null, $httpClient); @@ -118,12 +117,11 @@ public function testMessageCreate() $this->assertSame($expectedValue, $api->messageCreate(['recipient' => 'imgur', 'body' => 'YO !'])); } - /** - * @expectedException \Imgur\Exception\MissingArgumentException - * @expectedExceptionMessage parameters is missing - */ public function testMessageCreateParamMissing() { + $this->expectException(\Imgur\Exception\MissingArgumentException::class); + $this->expectExceptionMessage('parameters is missing'); + $this->getApiMock()->messageCreate([]); } diff --git a/tests/Api/CustomGalleryTest.php b/tests/Api/CustomGalleryTest.php index 11bd6bc..1e8ce5c 100644 --- a/tests/Api/CustomGalleryTest.php +++ b/tests/Api/CustomGalleryTest.php @@ -8,16 +8,16 @@ use GuzzleHttp\Psr7\Response; use Imgur\Api\CustomGallery; use Imgur\Client; +use Imgur\Exception\InvalidArgumentException; use Imgur\HttpClient\HttpClient; class CustomGalleryTest extends ApiTestCase { - /** - * @expectedException \Imgur\Exception\ErrorException - * @expectedExceptionMessage Authentication required - */ public function testBaseReal() { + $this->expectException(\Imgur\Exception\ErrorException::class); + $this->expectExceptionMessage('Authentication required'); + $guzzleClient = new GuzzleClient(['base_uri' => 'https://api.imgur.com/3/']); $httpClient = new HttpClient([], $guzzleClient); $client = new Client(null, $httpClient); @@ -109,21 +109,19 @@ public function testCustomGallery() $this->assertSame($expectedValue, $api->customGallery()); } - /** - * @expectedException \Imgur\Exception\InvalidArgumentException - * @expectedExceptionMessage is wrong. Possible values are - */ public function testCustomGalleryWrongSortValue() { + $this->expectException(InvalidArgumentException::class); + $this->expectExceptionMessage('is wrong. Possible values are'); + $this->getApiMock()->customGallery('bad sort'); } - /** - * @expectedException \Imgur\Exception\InvalidArgumentException - * @expectedExceptionMessage is wrong. Possible values are - */ public function testCustomGalleryWrongWindowValue() { + $this->expectException(InvalidArgumentException::class); + $this->expectExceptionMessage('is wrong. Possible values are'); + $this->getApiMock()->customGallery('viral', 0, 'bad window'); } @@ -146,21 +144,19 @@ public function testFiltered() $this->assertSame($expectedValue, $api->filtered()); } - /** - * @expectedException \Imgur\Exception\InvalidArgumentException - * @expectedExceptionMessage is wrong. Possible values are - */ public function testFilteredWrongSortValue() { + $this->expectException(InvalidArgumentException::class); + $this->expectExceptionMessage('is wrong. Possible values are'); + $this->getApiMock()->filtered('bad sort'); } - /** - * @expectedException \Imgur\Exception\InvalidArgumentException - * @expectedExceptionMessage is wrong. Possible values are - */ public function testFilteredWrongWindowValue() { + $this->expectException(InvalidArgumentException::class); + $this->expectExceptionMessage('is wrong. Possible values are'); + $this->getApiMock()->filtered('viral', 0, 'bad window'); } diff --git a/tests/Api/GalleryTest.php b/tests/Api/GalleryTest.php index 8b7d12e..14d5196 100644 --- a/tests/Api/GalleryTest.php +++ b/tests/Api/GalleryTest.php @@ -8,16 +8,16 @@ use GuzzleHttp\Psr7\Response; use Imgur\Api\Gallery; use Imgur\Client; +use Imgur\Exception\InvalidArgumentException; use Imgur\HttpClient\HttpClient; class GalleryTest extends ApiTestCase { - /** - * @expectedException \Imgur\Exception\ErrorException - * @expectedExceptionMessage Authentication required - */ public function testBaseReal() { + $this->expectException(\Imgur\Exception\ErrorException::class); + $this->expectExceptionMessage('Authentication required'); + $guzzleClient = new GuzzleClient(['base_uri' => 'https://api.imgur.com/3/']); $httpClient = new HttpClient([], $guzzleClient); $client = new Client(null, $httpClient); @@ -126,30 +126,27 @@ public function testGallery() $this->assertSame($expectedValue, $api->gallery()); } - /** - * @expectedException \Imgur\Exception\InvalidArgumentException - * @expectedExceptionMessage is wrong. Possible values are - */ public function testGalleryWrongSortValue() { + $this->expectException(InvalidArgumentException::class); + $this->expectExceptionMessage('is wrong. Possible values are'); + $this->getApiMock()->gallery('hot', 'bad sort'); } - /** - * @expectedException \Imgur\Exception\InvalidArgumentException - * @expectedExceptionMessage is wrong. Possible values are - */ public function testGalleryWrongSectionValue() { + $this->expectException(InvalidArgumentException::class); + $this->expectExceptionMessage('is wrong. Possible values are'); + $this->getApiMock()->gallery('bad section'); } - /** - * @expectedException \Imgur\Exception\InvalidArgumentException - * @expectedExceptionMessage is wrong. Possible values are - */ public function testGalleryWrongWindowValue() { + $this->expectException(InvalidArgumentException::class); + $this->expectExceptionMessage('is wrong. Possible values are'); + $this->getApiMock()->gallery('hot', 'viral', 0, 'bad window'); } @@ -174,21 +171,19 @@ public function testMemesSubgallery() $this->assertSame($expectedValue, $api->memesSubgallery()); } - /** - * @expectedException \Imgur\Exception\InvalidArgumentException - * @expectedExceptionMessage is wrong. Possible values are - */ public function testMemesSubgalleryWrongSortValue() { + $this->expectException(InvalidArgumentException::class); + $this->expectExceptionMessage('is wrong. Possible values are'); + $this->getApiMock()->memesSubgallery('bad sort'); } - /** - * @expectedException \Imgur\Exception\InvalidArgumentException - * @expectedExceptionMessage is wrong. Possible values are - */ public function testMemesSubgalleryWrongWindowValue() { + $this->expectException(InvalidArgumentException::class); + $this->expectExceptionMessage('is wrong. Possible values are'); + $this->getApiMock()->memesSubgallery('viral', 0, 'bad window'); } @@ -232,21 +227,19 @@ public function testSubredditGalleries() $this->assertSame($expectedValue, $api->subredditGalleries('pics')); } - /** - * @expectedException \Imgur\Exception\InvalidArgumentException - * @expectedExceptionMessage is wrong. Possible values are - */ public function testSubredditGalleriesWrongSortValue() { + $this->expectException(InvalidArgumentException::class); + $this->expectExceptionMessage('is wrong. Possible values are'); + $this->getApiMock()->subredditGalleries('pics', 'bad sort'); } - /** - * @expectedException \Imgur\Exception\InvalidArgumentException - * @expectedExceptionMessage is wrong. Possible values are - */ public function testSubredditGalleriesWrongWindowValue() { + $this->expectException(InvalidArgumentException::class); + $this->expectExceptionMessage('is wrong. Possible values are'); + $this->getApiMock()->subredditGalleries('pics', 'time', 0, 'bad window'); } @@ -290,21 +283,19 @@ public function testGalleryTag() $this->assertSame($expectedValue, $api->galleryTag('funny')); } - /** - * @expectedException \Imgur\Exception\InvalidArgumentException - * @expectedExceptionMessage is wrong. Possible values are - */ public function testGalleryTagWrongSortValue() { + $this->expectException(InvalidArgumentException::class); + $this->expectExceptionMessage('is wrong. Possible values are'); + $this->getApiMock()->galleryTag('funny', 'bad sort'); } - /** - * @expectedException \Imgur\Exception\InvalidArgumentException - * @expectedExceptionMessage is wrong. Possible values are - */ public function testGalleryTagWrongWindowValue() { + $this->expectException(InvalidArgumentException::class); + $this->expectExceptionMessage('is wrong. Possible values are'); + $this->getApiMock()->galleryTag('funny', 'time', 0, 'bad window'); } @@ -363,12 +354,11 @@ public function testGalleryVoteTag() $this->assertSame($expectedValue, $api->galleryVoteTag('y1Od4', 'funny', 'up')); } - /** - * @expectedException \Imgur\Exception\InvalidArgumentException - * @expectedExceptionMessage is wrong. Possible values are - */ public function testGalleryVoteTagWrongVoteValue() { + $this->expectException(InvalidArgumentException::class); + $this->expectExceptionMessage('is wrong. Possible values are'); + $this->getApiMock()->galleryVoteTag('y1Od4', 'funny', 'bad vote'); } @@ -393,12 +383,11 @@ public function testSearch() $this->assertSame($expectedValue, $api->search('20minutes')); } - /** - * @expectedException \Imgur\Exception\InvalidArgumentException - * @expectedExceptionMessage is wrong. Possible values are - */ public function testSearchWrongValues() { + $this->expectException(InvalidArgumentException::class); + $this->expectExceptionMessage('is wrong. Possible values are'); + $this->getApiMock()->search('pics', 'bad sort'); } @@ -440,12 +429,11 @@ public function testSubmitToGallery() $this->assertSame($expectedValue, $api->submitToGallery('y1Od4', ['title' => 'yo'])); } - /** - * @expectedException \Imgur\Exception\MissingArgumentException - * @expectedExceptionMessage parameters is missing - */ public function testSubmitToGalleryParamMissing() { + $this->expectException(\Imgur\Exception\MissingArgumentException::class); + $this->expectExceptionMessage('parameters is missing'); + $this->getApiMock()->submitToGallery('y1Od4', []); } @@ -557,12 +545,11 @@ public function testVote() $this->assertSame($expectedValue, $api->vote('VOMXz', 'up')); } - /** - * @expectedException \Imgur\Exception\InvalidArgumentException - * @expectedExceptionMessage is wrong. Possible values are - */ public function testVoteWrongVoteValue() { + $this->expectException(InvalidArgumentException::class); + $this->expectExceptionMessage('is wrong. Possible values are'); + $this->getApiMock()->vote('VOMXz', 'bad vote'); } @@ -587,12 +574,11 @@ public function testComments() $this->assertSame($expectedValue, $api->comments('VOMXz')); } - /** - * @expectedException \Imgur\Exception\InvalidArgumentException - * @expectedExceptionMessage is wrong. Possible values are - */ public function testCommentsWrongValues() { + $this->expectException(InvalidArgumentException::class); + $this->expectExceptionMessage('is wrong. Possible values are'); + $this->getApiMock()->comments('VOMXz', 'bad sort'); } @@ -632,12 +618,11 @@ public function testCreateComment() $this->assertSame($expectedValue, $api->createComment('VOMXz', ['comment' => 'yo'])); } - /** - * @expectedException \Imgur\Exception\MissingArgumentException - * @expectedExceptionMessage parameters is missing - */ public function testCreateCommentParamMissing() { + $this->expectException(\Imgur\Exception\MissingArgumentException::class); + $this->expectExceptionMessage('parameters is missing'); + $this->getApiMock()->createComment('y1Od4', []); } @@ -658,12 +643,11 @@ public function testCreateReply() $this->assertSame($expectedValue, $api->createReply('VOMXz', '123', ['comment' => 'yo'])); } - /** - * @expectedException \Imgur\Exception\MissingArgumentException - * @expectedExceptionMessage parameters is missing - */ public function testCreateReplyParamMissing() { + $this->expectException(\Imgur\Exception\MissingArgumentException::class); + $this->expectExceptionMessage('parameters is missing'); + $this->getApiMock()->createReply('y1Od4', '123', []); } diff --git a/tests/Api/ImageTest.php b/tests/Api/ImageTest.php index 5a44775..6f6cb16 100644 --- a/tests/Api/ImageTest.php +++ b/tests/Api/ImageTest.php @@ -12,12 +12,11 @@ class ImageTest extends ApiTestCase { - /** - * @expectedException \Imgur\Exception\ErrorException - * @expectedExceptionMessage Authentication required - */ public function testBaseReal() { + $this->expectException(\Imgur\Exception\ErrorException::class); + $this->expectExceptionMessage('Authentication required'); + $guzzleClient = new GuzzleClient(['base_uri' => 'https://api.imgur.com/3/']); $httpClient = new HttpClient([], $guzzleClient); $client = new Client(null, $httpClient); @@ -144,21 +143,19 @@ public function testUploadWithFile() $this->assertSame($expectedValue, $api->upload(['type' => 'file', 'image' => __DIR__ . '/ZOY11VC.png'])); } - /** - * @expectedException \Imgur\Exception\InvalidArgumentException - * @expectedExceptionMessage is wrong. Possible values are - */ public function testUploadWithBadType() { + $this->expectException(\Imgur\Exception\InvalidArgumentException::class); + $this->expectExceptionMessage('is wrong. Possible values are'); + $this->getApiMock()->upload(['type' => 'other', 'image' => 'http://i.imgur.com/ZOY11VC.png']); } - /** - * @expectedException \Imgur\Exception\MissingArgumentException - * @expectedExceptionMessage parameters is missing - */ public function testUploadWithUrlParamMissing() { + $this->expectException(\Imgur\Exception\MissingArgumentException::class); + $this->expectExceptionMessage('parameters is missing'); + $this->getApiMock()->upload([]); } diff --git a/tests/Api/MemegenTest.php b/tests/Api/MemegenTest.php index 66dae2f..7dcf2f6 100644 --- a/tests/Api/MemegenTest.php +++ b/tests/Api/MemegenTest.php @@ -12,12 +12,11 @@ class MemegenTest extends ApiTestCase { - /** - * @expectedException \Imgur\Exception\ErrorException - * @expectedExceptionMessage Authentication required - */ public function testBaseReal() { + $this->expectException(\Imgur\Exception\ErrorException::class); + $this->expectExceptionMessage('Authentication required'); + $guzzleClient = new GuzzleClient(['base_uri' => 'https://api.imgur.com/3/']); $httpClient = new HttpClient([], $guzzleClient); $client = new Client(null, $httpClient); diff --git a/tests/Api/NotificationTest.php b/tests/Api/NotificationTest.php index 849f806..a8d9663 100644 --- a/tests/Api/NotificationTest.php +++ b/tests/Api/NotificationTest.php @@ -12,12 +12,11 @@ class NotificationTest extends ApiTestCase { - /** - * @expectedException \Imgur\Exception\ErrorException - * @expectedExceptionMessage Authentication required - */ public function testBaseReal() { + $this->expectException(\Imgur\Exception\ErrorException::class); + $this->expectExceptionMessage('Authentication required'); + $guzzleClient = new GuzzleClient(['base_uri' => 'https://api.imgur.com/3/']); $httpClient = new HttpClient([], $guzzleClient); $client = new Client(null, $httpClient); diff --git a/tests/Api/TopicTest.php b/tests/Api/TopicTest.php index 42a9d6d..c93369e 100644 --- a/tests/Api/TopicTest.php +++ b/tests/Api/TopicTest.php @@ -12,12 +12,11 @@ class TopicTest extends ApiTestCase { - /** - * @expectedException \Imgur\Exception\ErrorException - * @expectedExceptionMessage Authentication required - */ public function testBaseReal() { + $this->expectException(\Imgur\Exception\ErrorException::class); + $this->expectExceptionMessage('Authentication required'); + $this->markTestSkipped('Topic endpoint does not always return 401 with no authentication ...'); $guzzleClient = new GuzzleClient(['base_uri' => 'https://api.imgur.com/3/']); @@ -163,21 +162,19 @@ public function testGalleryTopic() $this->assertSame($expectedValue, $api->galleryTopic(155)); } - /** - * @expectedException \Imgur\Exception\InvalidArgumentException - * @expectedExceptionMessage is wrong. Possible values are - */ public function testGalleryTopicWrongSortValue() { + $this->expectException(\Imgur\Exception\InvalidArgumentException::class); + $this->expectExceptionMessage('is wrong. Possible values are'); + $this->getApiMock()->galleryTopic(155, 'bad sort'); } - /** - * @expectedException \Imgur\Exception\InvalidArgumentException - * @expectedExceptionMessage is wrong. Possible values are - */ public function testGalleryTopicWrongWindowValue() { + $this->expectException(\Imgur\Exception\InvalidArgumentException::class); + $this->expectExceptionMessage('is wrong. Possible values are'); + $this->getApiMock()->galleryTopic(155, 'viral', 0, 'bad window'); } diff --git a/tests/Auth/OAuth2Test.php b/tests/Auth/OAuth2Test.php index c97e6d5..84062ab 100644 --- a/tests/Auth/OAuth2Test.php +++ b/tests/Auth/OAuth2Test.php @@ -5,9 +5,9 @@ use GuzzleHttp\Client as GuzzleClient; use GuzzleHttp\Handler\MockHandler; use GuzzleHttp\HandlerStack; -use GuzzleHttp\Psr7\Request; use GuzzleHttp\Psr7\Response; use Imgur\Auth\OAuth2; +use Imgur\Exception\AuthException; use Imgur\HttpClient\HttpClient; use PHPUnit\Framework\TestCase; @@ -28,12 +28,11 @@ public function testGetAuthenticationUrl() $this->assertSame('https://api.imgur.com/oauth2/authorize?client_id=456&response_type=code&state=draft', $auth->getAuthenticationUrl('code', 'draft')); } - /** - * @expectedException \Imgur\Exception\AuthException - * @expectedExceptionMessage Request for access token failed - */ public function testRequestAccessTokenBadStatusCode() { + $this->expectException(AuthException::class); + $this->expectExceptionMessage('Request for access token failed'); + $mock = new MockHandler([ new Response(400), ]); @@ -78,12 +77,11 @@ public function testRequestAccessTokenWithPin() $this->assertLessThanOrEqual(time(), $result['created_at']); } - /** - * @expectedException \Imgur\Exception\AuthException - * @expectedExceptionMessage Request for refresh access token failed - */ public function testRefreshTokenBadStatusCode() { + $this->expectException(AuthException::class); + $this->expectExceptionMessage('Request for refresh access token failed'); + $mock = new MockHandler([ new Response(400, ['Content-Type' => 'application/json'], json_encode(['data' => ['request' => '/3/account', 'error' => 'oops2', 'method' => 'GET'], 'success' => false, 'status' => 400])), ]); @@ -109,23 +107,21 @@ public function testRefreshToken() $this->assertSame('T0K3N', $result['access_token']); } - /** - * @expectedException \Imgur\Exception\AuthException - * @expectedExceptionMessage Token is not a valid json string. - */ public function testSetAccessTokenNull() { + $this->expectException(AuthException::class); + $this->expectExceptionMessage('Token is not a valid json string.'); + $client = new GuzzleClient(); $auth = new OAuth2(new HttpClient([], $client), 123, 456); $result = $auth->setAccessToken(null); } - /** - * @expectedException \Imgur\Exception\AuthException - * @expectedExceptionMessage Access token could not be retrieved from the decoded json response. - */ public function testSetAccessTokenEmpty() { + $this->expectException(AuthException::class); + $this->expectExceptionMessage('Access token could not be retrieved from the decoded json response.'); + $client = new GuzzleClient(); $auth = new OAuth2(new HttpClient([], $client), 123, 456); $auth->setAccessToken(['data']); diff --git a/tests/ClientTest.php b/tests/ClientTest.php index 79e8897..6fed831 100644 --- a/tests/ClientTest.php +++ b/tests/ClientTest.php @@ -3,6 +3,7 @@ namespace Imgur\tests; use Imgur\Client; +use Imgur\Exception\InvalidArgumentException; use PHPUnit\Framework\TestCase; class ClientTest extends TestCase @@ -60,29 +61,26 @@ public function getApiClassesProvider() ]; } - /** - * @expectedException \Imgur\Exception\InvalidArgumentException - */ public function testNotGetApiInstance() { + $this->expectException(InvalidArgumentException::class); + $client = new Client(); $client->api('do_not_exist'); } - /** - * @expectedException \Imgur\Exception\InvalidArgumentException - */ public function testGetOptionNotDefined() { + $this->expectException(InvalidArgumentException::class); + $client = new Client(); $client->getOption('do_not_exist'); } - /** - * @expectedException \Imgur\Exception\InvalidArgumentException - */ public function testSetOptionNotDefined() { + $this->expectException(InvalidArgumentException::class); + $client = new Client(); $client->setOption('do_not_exist', 'value'); } diff --git a/tests/HttpClient/HttpClientTest.php b/tests/HttpClient/HttpClientTest.php index d368445..85804f6 100644 --- a/tests/HttpClient/HttpClientTest.php +++ b/tests/HttpClient/HttpClientTest.php @@ -5,7 +5,6 @@ use GuzzleHttp\Client as GuzzleClient; use GuzzleHttp\Handler\MockHandler; use GuzzleHttp\HandlerStack; -use GuzzleHttp\Psr7\Request; use GuzzleHttp\Psr7\Response; use Imgur\HttpClient\HttpClient; use PHPUnit\Framework\TestCase; @@ -117,12 +116,11 @@ public function testDoCustomRequest() $this->assertTrue($result); } - /** - * @expectedException \Imgur\Exception\RateLimitException - * @expectedExceptionMessage No user credits available. The limit is 10 - */ public function testThrowExceptionWhenApiIsExceeded() { + $this->expectException(\Imgur\Exception\RateLimitException::class); + $this->expectExceptionMessage('No user credits available. The limit is 10'); + $path = '/some/path'; $parameters = ['a' => 'b']; @@ -139,12 +137,11 @@ public function testThrowExceptionWhenApiIsExceeded() $httpClient->get($path, $parameters); } - /** - * @expectedException \Imgur\Exception\RateLimitException - * @expectedExceptionMessage No application credits available. The limit is 10 and will be reset at - */ public function testThrowExceptionWhenClientApiIsExceeded() { + $this->expectException(\Imgur\Exception\RateLimitException::class); + $this->expectExceptionMessage('No application credits available. The limit is 10 and will be reset at'); + $path = '/some/path'; $parameters = ['a' => 'b']; @@ -164,12 +161,11 @@ public function testThrowExceptionWhenClientApiIsExceeded() $httpClient->get($path, $parameters); } - /** - * @expectedException \Imgur\Exception\RuntimeException - * @expectedExceptionMessage oops - */ public function testThrowExceptionWhenBadRequestPlainError() { + $this->expectException(\Imgur\Exception\RuntimeException::class); + $this->expectExceptionMessage('oops'); + $path = '/some/path'; $parameters = ['a' => 'b']; @@ -188,12 +184,11 @@ public function testThrowExceptionWhenBadRequestPlainError() $httpClient->get($path, $parameters); } - /** - * @expectedException \Imgur\Exception\ErrorException - * @expectedExceptionMessage Request to: /3/account failed with: "oops2" - */ public function testThrowExceptionWhenBadRequestJsonError() { + $this->expectException(\Imgur\Exception\ErrorException::class); + $this->expectExceptionMessage('Request to: /3/account failed with: "oops2"'); + $path = '/some/path'; $parameters = ['a' => 'b']; @@ -212,12 +207,11 @@ public function testThrowExceptionWhenBadRequestJsonError() $httpClient->get($path, $parameters); } - /** - * @expectedException \Imgur\Exception\RuntimeException - * @expectedExceptionMessage oops - */ public function testThrowExceptionWhenBadRequestNoClientMock() { + $this->expectException(\Imgur\Exception\RuntimeException::class); + $this->expectExceptionMessage('oops'); + $path = '/some/path'; $parameters = ['a' => 'b']; @@ -236,11 +230,10 @@ public function testThrowExceptionWhenBadRequestNoClientMock() $httpClient->get($path, $parameters); } - /* - * @expectedException \Imgur\Exception\ErrorException - */ // public function testThrowLogicException() // { + // $this->expectException(\Imgur\Exception\ErrorException::class); + // // $path = '/some/path'; // $parameters = ['a = b']; diff --git a/tests/Middleware/ErrorMiddlewareTest.php b/tests/Middleware/ErrorMiddlewareTest.php index 2851186..c49f36c 100644 --- a/tests/Middleware/ErrorMiddlewareTest.php +++ b/tests/Middleware/ErrorMiddlewareTest.php @@ -6,6 +6,7 @@ use GuzzleHttp\HandlerStack; use GuzzleHttp\Psr7\Request; use GuzzleHttp\Psr7\Response; +use Imgur\Exception\RateLimitException; use Imgur\Middleware\ErrorMiddleware; use PHPUnit\Framework\TestCase; @@ -27,12 +28,11 @@ public function testNothinHappenOnOKResponse() $this->assertSame(200, $response->getStatusCode()); } - /** - * @expectedException \Imgur\Exception\RateLimitException - * @expectedExceptionMessage No user credits available. The limit is 10 - */ public function testRateLimitUser() { + $this->expectException(RateLimitException::class); + $this->expectExceptionMessage('No user credits available. The limit is 10'); + $mock = new MockHandler([ new Response(429, [ 'X-RateLimit-UserRemaining' => 0, @@ -47,12 +47,11 @@ public function testRateLimitUser() $handler($request, [])->wait(); } - /** - * @expectedException \Imgur\Exception\RateLimitException - * @expectedExceptionMessage No application credits available. The limit is 10 and will be reset at 2015-09-04 - */ public function testRateLimitClient() { + $this->expectException(RateLimitException::class); + $this->expectExceptionMessage('No application credits available. The limit is 10 and will be reset at 2015-09-04'); + $mock = new MockHandler([ new Response(429, [ 'X-RateLimit-UserRemaining' => 9, @@ -70,12 +69,11 @@ public function testRateLimitClient() $handler($request, [])->wait(); } - /** - * @expectedException \Imgur\Exception\ErrorException - * @expectedExceptionMessage Request failed with: "Imgur is temporarily over capacity. Please try again later." - */ public function testErrorOverCapacity() { + $this->expectException(\Imgur\Exception\ErrorException::class); + $this->expectExceptionMessage('Request failed with: "Imgur is temporarily over capacity. Please try again later."'); + $mock = new MockHandler([ new Response(429, [ 'X-RateLimit-UserRemaining' => 9, @@ -92,12 +90,11 @@ public function testErrorOverCapacity() $handler($request, [])->wait(); } - /** - * @expectedException \Imgur\Exception\ErrorException - * @expectedExceptionMessage Request to: /3/image.json failed with: "You are uploading too fast. Please wait 59 more minutes." - */ public function testErrorUploadingTooFast() { + $this->expectException(\Imgur\Exception\ErrorException::class); + $this->expectExceptionMessage('Request to: /3/image.json failed with: "You are uploading too fast. Please wait 59 more minutes."'); + $mock = new MockHandler([ new Response(429, [ 'X-RateLimit-UserRemaining' => 9, @@ -114,12 +111,11 @@ public function testErrorUploadingTooFast() $handler($request, [])->wait(); } - /** - * @expectedException \Imgur\Exception\ErrorException - * @expectedExceptionMessage Request to: /3/image.json failed with: "Error code: 666" - */ public function testErrorNoMessageInError() { + $this->expectException(\Imgur\Exception\ErrorException::class); + $this->expectExceptionMessage('Request to: /3/image.json failed with: "Error code: 666"'); + $mock = new MockHandler([ new Response(429, [ 'X-RateLimit-UserRemaining' => 9, @@ -136,12 +132,11 @@ public function testErrorNoMessageInError() $handler($request, [])->wait(); } - /** - * @expectedException \Imgur\Exception\ErrorException - * @expectedExceptionMessage Request to: /here failed with: "oops" - */ public function testErrorWithJson() { + $this->expectException(\Imgur\Exception\ErrorException::class); + $this->expectExceptionMessage('Request to: /here failed with: "oops"'); + $mock = new MockHandler([ new Response(429, [ 'X-RateLimit-UserRemaining' => 9, @@ -158,12 +153,11 @@ public function testErrorWithJson() $handler($request, [])->wait(); } - /** - * @expectedException \Imgur\Exception\RuntimeException - * @expectedExceptionMessage hihi - */ public function testErrorWithoutJson() { + $this->expectException(\Imgur\Exception\RuntimeException::class); + $this->expectExceptionMessage('hihi'); + $mock = new MockHandler([ new Response(429, [ 'X-RateLimit-UserRemaining' => 9, @@ -180,12 +174,11 @@ public function testErrorWithoutJson() $handler($request, [])->wait(); } - /** - * @expectedException \Imgur\Exception\RateLimitException - * @expectedExceptionMessage No post credits available. The limit is 10 and will be reset at 2015-09-04 - */ public function testRateLimitPost() { + $this->expectException(RateLimitException::class); + $this->expectExceptionMessage('No post credits available. The limit is 10 and will be reset at 2015-09-04'); + $mock = new MockHandler([ new Response(429, [ 'X-Post-Rate-Limit-Remaining' => 0, From d01d0a4644bb5a5e0cdbda63fc25ee4cbc46c706 Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Fri, 3 Dec 2021 09:37:16 +0100 Subject: [PATCH 3/8] PHP-CS-Fixer require PHP 7.1, revert --- .php-cs-fixer.php | 30 ------------------------------ .php_cs | 45 +++++++++++++++++++++++++++++++++++++++++++++ composer.json | 2 +- 3 files changed, 46 insertions(+), 31 deletions(-) delete mode 100644 .php-cs-fixer.php create mode 100644 .php_cs diff --git a/.php-cs-fixer.php b/.php-cs-fixer.php deleted file mode 100644 index 460eecd..0000000 --- a/.php-cs-fixer.php +++ /dev/null @@ -1,30 +0,0 @@ -in(__DIR__) - ->exclude(['vendor']) -; - -return (new PhpCsFixer\Config()) - ->setRiskyAllowed(true) - ->setRules([ - '@Symfony' => true, - '@Symfony:risky' => true, - 'array_syntax' => ['syntax' => 'short'], - 'combine_consecutive_unsets' => true, - 'heredoc_to_nowdoc' => true, - 'no_extra_blank_lines' => ['tokens' => ['break', 'continue', 'extra', 'return', 'throw', 'use', 'parenthesis_brace_block', 'square_brace_block', 'curly_brace_block']], - 'no_unreachable_default_argument_value' => true, - 'no_useless_else' => true, - 'no_useless_return' => true, - 'ordered_class_elements' => true, - 'ordered_imports' => true, - 'php_unit_strict' => true, - 'phpdoc_order' => true, - // 'psr4' => true, - 'strict_comparison' => true, - 'strict_param' => true, - 'concat_space' => ['spacing' => 'one'], - ]) - ->setFinder($finder) -; diff --git a/.php_cs b/.php_cs new file mode 100644 index 0000000..5184eaf --- /dev/null +++ b/.php_cs @@ -0,0 +1,45 @@ +setRiskyAllowed(true) + ->setRules([ + '@Symfony' => true, + '@Symfony:risky' => true, + 'array_syntax' => [ + 'syntax' => 'short' + ], + 'combine_consecutive_unsets' => true, + 'heredoc_to_nowdoc' => true, + 'no_extra_consecutive_blank_lines' => [ + 'break', + 'continue', + 'extra', + 'return', + 'throw', + 'use', + 'parenthesis_brace_block', + 'square_brace_block', + 'curly_brace_block' + ], + 'no_unreachable_default_argument_value' => true, + 'no_useless_else' => true, + 'no_useless_return' => true, + 'ordered_class_elements' => true, + 'ordered_imports' => true, + 'php_unit_strict' => true, + 'phpdoc_order' => true, + // 'psr4' => true, + 'strict_comparison' => true, + 'strict_param' => true, + 'concat_space' => [ + 'spacing' => 'one' + ], + ]) + ->setFinder( + PhpCsFixer\Finder::create() + ->exclude([ + 'vendor', + ]) + ->in(__DIR__) + ) +; diff --git a/composer.json b/composer.json index 7e47fc5..d433d73 100644 --- a/composer.json +++ b/composer.json @@ -39,7 +39,7 @@ "guzzlehttp/guzzle": "^6.0" }, "require-dev": { - "friendsofphp/php-cs-fixer": "^3.0", + "friendsofphp/php-cs-fixer": "^2.0", "symfony/phpunit-bridge": "^5.0" }, "config": { From efbd148a10d8be295b9b130bcf9bb6f587c954dd Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Fri, 3 Dec 2021 09:38:44 +0100 Subject: [PATCH 4/8] Revert PHP 7.1 changes --- lib/Imgur/Auth/OAuth2.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/Imgur/Auth/OAuth2.php b/lib/Imgur/Auth/OAuth2.php index 38752e5..5da0ce3 100644 --- a/lib/Imgur/Auth/OAuth2.php +++ b/lib/Imgur/Auth/OAuth2.php @@ -12,8 +12,8 @@ */ class OAuth2 implements AuthInterface { - public const AUTHORIZATION_ENDPOINT = 'https://api.imgur.com/oauth2/authorize'; - public const ACCESS_TOKEN_ENDPOINT = 'https://api.imgur.com/oauth2/token'; + const AUTHORIZATION_ENDPOINT = 'https://api.imgur.com/oauth2/authorize'; + const ACCESS_TOKEN_ENDPOINT = 'https://api.imgur.com/oauth2/token'; /** * Indicates the client that is making the request. From 861bdb458b27f1bf0bc4d42a6b904d93a4ad0ec4 Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Fri, 3 Dec 2021 09:41:50 +0100 Subject: [PATCH 5/8] Silent warning in PHP 8.1 --- phpunit.xml.dist | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/phpunit.xml.dist b/phpunit.xml.dist index dc5cb58..e5cc795 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -16,6 +16,11 @@ + + + + + ./lib/ From fc9ba03a8fa8bf06d8a512322ea1b0fe6abecec2 Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Fri, 3 Dec 2021 09:53:40 +0100 Subject: [PATCH 6/8] Use Coveralls instead of Scrutinizer for coverage --- .github/workflows/continuous-integration.yml | 14 ++++++++------ .scrutinizer.yml | 2 -- README.md | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index 42265a8..959db52 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -81,13 +81,15 @@ jobs: uses: "ramsey/composer-install@v1" - name: "Run PHPUnit (with coverage)" - run: "php vendor/bin/simple-phpunit -v --coverage-clover=coverage.clover" + run: "php vendor/bin/simple-phpunit -v --coverage-clover clover.xml" - - name: "Retrieve ocular.phar" - run: "wget https://scrutinizer-ci.com/ocular.phar" + - name: "Retrieve Coveralls phar" + run: "wget https://github.com/php-coveralls/php-coveralls/releases/download/v2.4.2/php-coveralls.phar" - - name: "Enable ocular.phar" - run: "chmod +x ocular.phar" + - name: "Enable Coveralls phar" + run: "chmod +x php-coveralls.phar" - name: "Upload coverage" - run: "php ocular.phar code-coverage:upload --format=php-clover coverage.clover" + run: "php php-coveralls.phar -v -x clover.xml" + env: + COVERALLS_REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.scrutinizer.yml b/.scrutinizer.yml index dcde80d..22a1d52 100644 --- a/.scrutinizer.yml +++ b/.scrutinizer.yml @@ -1,6 +1,4 @@ tools: - external_code_coverage: - timeout: 1200 php_code_sniffer: config: standard: "PSR2" diff --git a/README.md b/README.md index 0abe8b6..b492a05 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # PHP Imgur API Client ![CI](https://github.com/j0k3r/php-imgur-api-client/workflows/CI/badge.svg) -[![Code Coverage](https://scrutinizer-ci.com/g/j0k3r/php-imgur-api-client/badges/coverage.png?branch=master)](https://scrutinizer-ci.com/g/j0k3r/php-imgur-api-client/?branch=master) +[![Coverage Status](https://coveralls.io/repos/j0k3r/php-imgur-api-client/badge.svg?branch=master&service=github)](https://coveralls.io/github/j0k3r/php-imgur-api-client?branch=master) [![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/j0k3r/php-imgur-api-client/badges/quality-score.png?branch=master)](https://scrutinizer-ci.com/g/j0k3r/php-imgur-api-client/?branch=master) [![Total Downloads](https://poser.pugx.org/j0k3r/php-imgur-api-client/downloads)](https://packagist.org/packages/j0k3r/php-imgur-api-client) [![License](https://poser.pugx.org/j0k3r/php-imgur-api-client/license)](https://packagist.org/packages/j0k3r/php-imgur-api-client) From bb53750b1a651b22f60756564ac3c4d7d4c8e228 Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Fri, 3 Dec 2021 09:57:06 +0100 Subject: [PATCH 7/8] Fix coveralls --- .github/workflows/continuous-integration.yml | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index 959db52..94079d6 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -80,8 +80,11 @@ jobs: - name: "Install dependencies with Composer" uses: "ramsey/composer-install@v1" + - name: "Setup logs" + run: "mkdir -p build/logs" + - name: "Run PHPUnit (with coverage)" - run: "php vendor/bin/simple-phpunit -v --coverage-clover clover.xml" + run: "php vendor/bin/simple-phpunit -v --coverage-clover build/logs/clover.xml" - name: "Retrieve Coveralls phar" run: "wget https://github.com/php-coveralls/php-coveralls/releases/download/v2.4.2/php-coveralls.phar" @@ -90,6 +93,6 @@ jobs: run: "chmod +x php-coveralls.phar" - name: "Upload coverage" - run: "php php-coveralls.phar -v -x clover.xml" + run: "php php-coveralls.phar -v -x build/logs/clover.xml" env: COVERALLS_REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }} From 3801c0f772944a0b1c7766498250c793a232dbb3 Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Fri, 3 Dec 2021 10:04:44 +0100 Subject: [PATCH 8/8] Increase coverage --- tests/HttpClient/HttpClientTest.php | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/tests/HttpClient/HttpClientTest.php b/tests/HttpClient/HttpClientTest.php index 85804f6..792ba01 100644 --- a/tests/HttpClient/HttpClientTest.php +++ b/tests/HttpClient/HttpClientTest.php @@ -59,6 +59,28 @@ public function testDoPOSTRequest() $this->assertSame('ok !', $result); } + public function testDoPOSTRequestWithMultipart() + { + $path = '/some/path'; + $parameters = [ + 'a' => 'b', + 'type' => 'file', + ]; + + $mock = new MockHandler([ + new Response(200, ['Content-Type' => 'application/json'], json_encode(['data' => 'ok !'])), + ]); + $handler = HandlerStack::create($mock); + $client = new GuzzleClient(['handler' => $handler]); + + $httpClient = new HttpClient([], $client); + $response = $httpClient->post($path, $parameters); + + $result = $httpClient->parseResponse($response); + + $this->assertSame('ok !', $result); + } + public function testDoPUTRequest() { $path = '/some/path';