From 9ce9935b4165d1fcd33032379218e6e735b5793d Mon Sep 17 00:00:00 2001 From: Wilmer Arambula Date: Sun, 11 May 2025 11:24:37 -0400 Subject: [PATCH 1/8] Use Yii2 `2.2`. --- composer.json | 34 ++++++++--------------- phpunit.xml.dist | 45 +++++++++++++++++-------------- src/Client.php | 12 ++++----- tests/CurlFormatterTest.php | 4 +-- tests/MockTransportTest.php | 2 +- tests/RequestTest.php | 6 ++--- tests/TestCase.php | 2 +- tests/TransportTestCase.php | 17 ++++++------ tests/UrlEncodedFormatterTest.php | 4 +-- tests/XmlFormatterTest.php | 4 +-- tests/bootstrap.php | 2 -- 11 files changed, 61 insertions(+), 71 deletions(-) diff --git a/composer.json b/composer.json index 33709d7..03e29b0 100644 --- a/composer.json +++ b/composer.json @@ -1,7 +1,12 @@ { "name": "yiisoft/yii2-httpclient", "description": "HTTP client extension for the Yii framework", - "keywords": ["yii2", "http", "httpclient", "curl"], + "keywords": [ + "yii2", + "http", + "httpclient", + "curl" + ], "type": "yii2-extension", "license": "BSD-3-Clause", "support": { @@ -17,23 +22,16 @@ "email": "klimov.paul@gmail.com" } ], + "minimum-stability": "dev", "require": { - "yiisoft/yii2": "~2.0.13", - "paragonie/random_compat": ">=1" + "php": ">=8.1", + "yiisoft/yii2": "2.2.x-dev" }, "require-dev": { - "cweagans/composer-patches": "^1.7", - "phpunit/phpunit": "4.8.34" + "phpunit/phpunit": "^9.6" }, - "repositories": [ - { - "type": "composer", - "url": "https://asset-packagist.org" - } - ], "config": { "allow-plugins": { - "cweagans/composer-patches": true, "yiisoft/yii2-composer": true } }, @@ -42,17 +40,7 @@ }, "extra": { "branch-alias": { - "dev-master": "2.0.x-dev" - }, - "composer-exit-on-patch-failure": true, - "patches": { - "phpunit/phpunit-mock-objects": { - "Fix PHP 7 and 8 compatibility": "https://yiisoft.github.io/phpunit-patches/phpunit_mock_objects.patch" - }, - "phpunit/phpunit": { - "Fix PHP 7 compatibility": "https://yiisoft.github.io/phpunit-patches/phpunit_php7.patch", - "Fix PHP 8 compatibility": "https://yiisoft.github.io/phpunit-patches/phpunit_php8.patch" - } + "dev-master": "22.0.x-dev" } } } diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 044cc4e..3b285a2 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,22 +1,27 @@ - - - - ./tests - - - - - ./src - - ./src/debug - - - + + + + + + + + + ./tests + + + + + + ./src + + diff --git a/src/Client.php b/src/Client.php index ca2e516..7c09212 100644 --- a/src/Client.php +++ b/src/Client.php @@ -203,7 +203,7 @@ public function createRequest() /** * Creates a response instance. - * @param string $content raw content + * @param string|null $content raw content * @param array $headers headers list. * @return Response request instance. * @throws \yii\base\InvalidConfigException @@ -285,7 +285,7 @@ public function createRequestLogToken($method, $url, $headers, $content) /** * Creates 'GET' request. * @param array|string $url target URL. - * @param array|string $data if array - request data, otherwise - request content. + * @param array|string|null $data if array - request data, otherwise - request content. * @param array $headers request headers. * @param array $options request options. * @return Request request instance. @@ -298,7 +298,7 @@ public function get($url, $data = null, $headers = [], $options = []) /** * Creates 'POST' request. * @param array|string $url target URL. - * @param array|string $data if array - request data, otherwise - request content. + * @param array|string|null $data if array - request data, otherwise - request content. * @param array $headers request headers. * @param array $options request options. * @return Request request instance. @@ -311,7 +311,7 @@ public function post($url, $data = null, $headers = [], $options = []) /** * Creates 'PUT' request. * @param array|string $url target URL. - * @param array|string $data if array - request data, otherwise - request content. + * @param array|string|null $data if array - request data, otherwise - request content. * @param array $headers request headers. * @param array $options request options. * @return Request request instance. @@ -324,7 +324,7 @@ public function put($url, $data = null, $headers = [], $options = []) /** * Creates 'PATCH' request. * @param array|string $url target URL. - * @param array|string $data if array - request data, otherwise - request content. + * @param array|string|null $data if array - request data, otherwise - request content. * @param array $headers request headers. * @param array $options request options. * @return Request request instance. @@ -337,7 +337,7 @@ public function patch($url, $data = null, $headers = [], $options = []) /** * Creates 'DELETE' request. * @param array|string $url target URL. - * @param array|string $data if array - request data, otherwise - request content. + * @param array|string|null $data if array - request data, otherwise - request content. * @param array $headers request headers. * @param array $options request options. * @return Request request instance. diff --git a/tests/CurlFormatterTest.php b/tests/CurlFormatterTest.php index a4885cf..7f50ac7 100644 --- a/tests/CurlFormatterTest.php +++ b/tests/CurlFormatterTest.php @@ -7,7 +7,7 @@ class CurlFormatterTest extends TestCase { - protected function setUp() + protected function setUp(): void { $this->mockApplication(); } @@ -52,7 +52,7 @@ public function testFormatMethodGet() $formatter = new CurlFormatter(); $formatter->format($request); $this->assertEmpty($request->getContent()); - $this->assertContains(http_build_query($data), $request->getFullUrl()); + $this->assertStringContainsString(http_build_query($data), $request->getFullUrl()); $this->assertFalse($request->getHeaders()->has('Content-Type')); } diff --git a/tests/MockTransportTest.php b/tests/MockTransportTest.php index c3a33e0..467d666 100644 --- a/tests/MockTransportTest.php +++ b/tests/MockTransportTest.php @@ -19,7 +19,7 @@ final class MockTransportTest extends TestCase */ private $transport; - protected function setUp() + protected function setUp(): void { $this->transport = new MockTransport(); $this->client = new Client(['transport' => $this->transport]); diff --git a/tests/RequestTest.php b/tests/RequestTest.php index 55f6492..6e3bade 100644 --- a/tests/RequestTest.php +++ b/tests/RequestTest.php @@ -7,7 +7,7 @@ class RequestTest extends TestCase { - protected function setUp() + protected function setUp(): void { $this->mockApplication(); } @@ -216,8 +216,8 @@ public function testToString() $request->addFileContent('some-file', 'some content'); $result = $request->toString(); - $this->assertContains('Content-Type: multipart/form-data; boundary=', $result); - $this->assertContains('some content', $result); + $this->assertStringContainsString('Content-Type: multipart/form-data; boundary=', $result); + $this->assertStringContainsString('some content', $result); } /** diff --git a/tests/TestCase.php b/tests/TestCase.php index 80365ab..c881cb4 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -15,7 +15,7 @@ abstract class TestCase extends \PHPUnit\Framework\TestCase * Clean up after test. * By default the application created with [[mockApplication]] will be destroyed. */ - protected function tearDown() + protected function tearDown(): void { parent::tearDown(); $this->destroyApplication(); diff --git a/tests/TransportTestCase.php b/tests/TransportTestCase.php index 0edb11f..d09c63f 100644 --- a/tests/TransportTestCase.php +++ b/tests/TransportTestCase.php @@ -14,7 +14,7 @@ */ abstract class TransportTestCase extends TestCase { - protected function setUp() + protected function setUp(): void { $this->mockApplication(); } @@ -49,7 +49,7 @@ public function testSend() $this->assertResponseIsOK($response); $content = $response->getContent(); $this->assertNotEmpty($content); - $this->assertContains('

Documentation

', $content); + $this->assertStringContainsString('

Documentation

', $content); } /** @@ -90,11 +90,10 @@ public function testBatchSend() $this->assertResponseIsOK($response); } - $this->assertTrue($responses['docs'] instanceof Response, $responses); - $this->assertTrue($responses['support'] instanceof Response, $responses); - - $this->assertContains('

Documentation

', $responses['docs']->getContent()); - $this->assertContains('Mailing Lists', $responses['support']->getContent()); + $this->assertInstanceOf(Response::class, $responses['docs']); + $this->assertInstanceOf(Response::class, $responses['support']); + $this->assertStringContainsString('

Documentation

', $responses['docs']->getContent()); + $this->assertStringContainsString('Mailing Lists', $responses['support']->getContent()); } /** @@ -305,6 +304,6 @@ public function testCustomSslCertificate() $this->assertResponseIsOK($response); $content = $response->getContent(); $this->assertNotEmpty($content); - $this->assertContains('

Documentation

', $content); + $this->assertStringContainsString('

Documentation

', $content); } -} \ No newline at end of file +} diff --git a/tests/UrlEncodedFormatterTest.php b/tests/UrlEncodedFormatterTest.php index 0083a87..ae3339f 100644 --- a/tests/UrlEncodedFormatterTest.php +++ b/tests/UrlEncodedFormatterTest.php @@ -7,7 +7,7 @@ class UrlEncodedFormatterTest extends TestCase { - protected function setUp() + protected function setUp(): void { $this->mockApplication(); } @@ -47,7 +47,7 @@ public function testFormatMethodGet() $formatter = new UrlEncodedFormatter(); $formatter->format($request); $this->assertEmpty($request->getContent()); - $this->assertContains(http_build_query($data), $request->getFullUrl()); + $this->assertStringContainsString(http_build_query($data), $request->getFullUrl()); $this->assertFalse($request->getHeaders()->has('Content-Type')); } diff --git a/tests/XmlFormatterTest.php b/tests/XmlFormatterTest.php index 917d4ba..4fd20ba 100644 --- a/tests/XmlFormatterTest.php +++ b/tests/XmlFormatterTest.php @@ -10,7 +10,7 @@ class XmlFormatterTest extends TestCase { - protected function setUp() + protected function setUp(): void { $this->mockApplication(); } @@ -194,4 +194,4 @@ public function toArray(array $fields = [], array $expand = [], $recursive = tru { return ['name1' => 'value1']; } -} \ No newline at end of file +} diff --git a/tests/bootstrap.php b/tests/bootstrap.php index ca55512..b7b6ff1 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -13,5 +13,3 @@ Yii::setAlias('@yiiunit/extensions/httpclient', __DIR__); Yii::setAlias('@yii/httpclient', dirname(__DIR__) . '/src'); - -require_once(__DIR__ . '/compatibility.php'); \ No newline at end of file From 7f61d4218adfc350912dbc258313fca8316d98c0 Mon Sep 17 00:00:00 2001 From: Wilmer Arambula Date: Sun, 11 May 2025 11:26:25 -0400 Subject: [PATCH 2/8] Refactor GitHub Actions workflow to streamline build process and remove redundant configurations. --- .github/workflows/build.yml | 61 +++++++++++-------------------------- 1 file changed, 18 insertions(+), 43 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index fbb1946..da6f5b4 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -1,47 +1,22 @@ -name: build +on: + pull_request: + paths-ignore: + - 'docs/**' + - 'README.md' + - 'CHANGELOG.md' + - '.gitignore' + - '.gitattributes' -on: [push, pull_request] + push: + paths-ignore: + - 'docs/**' + - 'README.md' + - 'CHANGELOG.md' + - '.gitignore' + - '.gitattributes' -env: - DEFAULT_COMPOSER_FLAGS: "--prefer-dist --no-interaction --no-progress --optimize-autoloader --ansi" +name: build jobs: - phpunit: - name: PHP ${{ matrix.php }} on ${{ matrix.os }} - runs-on: ${{ matrix.os }} - strategy: - fail-fast: false - matrix: - os: [ubuntu-latest] - php: ['5.4', '5.5', '5.6', '7.0', '7.1', '7.2', '7.3', '7.4', '8.0', '8.1'] - - steps: - - name: Checkout - uses: actions/checkout@v2 - - name: Install PHP - uses: shivammathur/setup-php@v2 - with: - php-version: ${{ matrix.php }} - - name: Get composer cache directory - id: composer-cache - run: echo "::set-output name=dir::$(composer config cache-files-dir)" - - name: Cache composer dependencies - uses: actions/cache@v1 - with: - path: ${{ steps.composer-cache.outputs.dir }} - key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }} - restore-keys: ${{ runner.os }}-composer- - - name: Install dependencies - run: composer update $DEFAULT_COMPOSER_FLAGS - - name: Run unit tests with coverage - run: vendor/bin/phpunit --verbose --coverage-clover=coverage.clover --colors=always - if: matrix.php == '7.1' - - name: Run unit tests without coverage - run: vendor/bin/phpunit --verbose --colors=always - if: matrix.php != '7.1' - - name: Upload code coverage - run: | - wget https://scrutinizer-ci.com/ocular.phar - php ocular.phar code-coverage:upload --format=php-clover coverage.clover - if: matrix.php == '7.1' - continue-on-error: true # if is fork + phpunit: + uses: yiisoft/actions/.github/workflows/phpunit.yml@master \ No newline at end of file From cc8b081ee5f5544579b656bdd4eca7ab3c878b24 Mon Sep 17 00:00:00 2001 From: Wilmer Arambula Date: Sun, 11 May 2025 11:30:06 -0400 Subject: [PATCH 3/8] Use `InvalidArgumentException` for `InvalidParamException` removed in `2.2`. --- src/Client.php | 10 +++++----- tests/ClientTest.php | 6 +++--- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/Client.php b/src/Client.php index 7c09212..5502121 100644 --- a/src/Client.php +++ b/src/Client.php @@ -9,7 +9,7 @@ use yii\base\Component; use Yii; -use yii\base\InvalidParamException; +use yii\base\InvalidArgumentException; use yii\helpers\StringHelper; /** @@ -124,7 +124,7 @@ public function getTransport() * Returns HTTP message formatter instance for the specified format. * @param string $format format name. * @return FormatterInterface formatter instance. - * @throws InvalidParamException on invalid format name. + * @throws InvalidArgumentException on invalid format name. * @throws \yii\base\InvalidConfigException */ public function getFormatter($format) @@ -145,7 +145,7 @@ public function getFormatter($format) if (!isset($this->formatters[$format])) { if (!isset($defaultFormatters[$format])) { - throw new InvalidParamException("Unrecognized format '{$format}'"); + throw new InvalidArgumentException("Unrecognized format '{$format}'"); } $this->formatters[$format] = $defaultFormatters[$format]; } @@ -161,7 +161,7 @@ public function getFormatter($format) * Returns HTTP message parser instance for the specified format. * @param string $format format name * @return ParserInterface parser instance. - * @throws InvalidParamException on invalid format name. + * @throws InvalidArgumentException on invalid format name. * @throws \yii\base\InvalidConfigException */ public function getParser($format) @@ -175,7 +175,7 @@ public function getParser($format) if (!isset($this->parsers[$format])) { if (!isset($defaultParsers[$format])) { - throw new InvalidParamException("Unrecognized format '{$format}'"); + throw new InvalidArgumentException("Unrecognized format '{$format}'"); } $this->parsers[$format] = $defaultParsers[$format]; } diff --git a/tests/ClientTest.php b/tests/ClientTest.php index 9dbebdd..e988c46 100644 --- a/tests/ClientTest.php +++ b/tests/ClientTest.php @@ -40,7 +40,7 @@ public function testGetUnrecognizedFormatter() { $client = new Client(); $unrecognizedFormat = 'unrecognizedFormat'; - $this->expectException('\yii\base\InvalidParamException'); + $this->expectException('\yii\base\InvalidArgumentException'); $this->expectExceptionMessage("Unrecognized format '{$unrecognizedFormat}'"); $client->getFormatter($unrecognizedFormat); } @@ -108,7 +108,7 @@ public function testGetUnrecognizedParser() { $client = new Client(); $unrecognizedParser = 'unrecognizedParser'; - $this->expectException('\yii\base\InvalidParamException'); + $this->expectException('\yii\base\InvalidargumentException'); $this->expectExceptionMessage("Unrecognized format '{$unrecognizedParser}'"); $client->getParser($unrecognizedParser); } @@ -273,4 +273,4 @@ public function testRequestShortcutMethods() $client->head($url, $headers, $options); $client->options($url, $options); } -} \ No newline at end of file +} From 3c3211d34a0ccc7ffd6642b810edd4b7e5bdd756 Mon Sep 17 00:00:00 2001 From: Wilmer Arambula Date: Sun, 11 May 2025 11:31:55 -0400 Subject: [PATCH 4/8] Update `.editorconfig`. --- .editorconfig | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.editorconfig b/.editorconfig index 257221d..5e9a93e 100644 --- a/.editorconfig +++ b/.editorconfig @@ -12,3 +12,6 @@ trim_trailing_whitespace = true [*.md] trim_trailing_whitespace = false + +[*.yml] +indent_size = 2 From d3d2d1122836b221c100e7bdd9822c70a829957c Mon Sep 17 00:00:00 2001 From: Wilmer Arambula Date: Sun, 11 May 2025 11:34:22 -0400 Subject: [PATCH 5/8] Remove `CURLOPT_BINARYTRANSFER` deprecated. --- tests/UrlEncodedFormatterTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/UrlEncodedFormatterTest.php b/tests/UrlEncodedFormatterTest.php index ae3339f..3126f0d 100644 --- a/tests/UrlEncodedFormatterTest.php +++ b/tests/UrlEncodedFormatterTest.php @@ -86,8 +86,8 @@ public function testFormatPutRequestWithInfileOption() $request->setOptions([ CURLOPT_INFILE => $fh, CURLOPT_INFILESIZE => filesize(__DIR__ . '/test_file.txt'), - CURLOPT_BINARYTRANSFER => true, CURLOPT_PUT => 1, + CURLOPT_RETURNTRANSFER => 1, ]); $formatter = new UrlEncodedFormatter(); From 4de1bdc94f7d67593b979b53ad72090e55af0a2e Mon Sep 17 00:00:00 2001 From: Wilmer Arambula Date: Sun, 11 May 2025 13:26:15 -0400 Subject: [PATCH 6/8] Update `phpunit.xml.dist`. --- phpunit.xml.dist | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 3b285a2..b440dad 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,27 +1,22 @@ - - - - - ./tests - - ./src + src From c025583a63107f9711ca5a2f2c7d18f087b791f8 Mon Sep 17 00:00:00 2001 From: Wilmer Arambula Date: Mon, 12 May 2025 08:41:55 -0400 Subject: [PATCH 7/8] Remove unused "extra" section from `composer.json`. --- composer.json | 5 ----- 1 file changed, 5 deletions(-) diff --git a/composer.json b/composer.json index 03e29b0..17d8fc6 100644 --- a/composer.json +++ b/composer.json @@ -37,10 +37,5 @@ }, "autoload": { "psr-4": { "yii\\httpclient\\": "src" } - }, - "extra": { - "branch-alias": { - "dev-master": "22.0.x-dev" - } } } From 4409985bcee9f2a4635c0a7c279d3a511f8becdb Mon Sep 17 00:00:00 2001 From: Wilmer Arambula Date: Wed, 21 May 2025 18:26:42 -0400 Subject: [PATCH 8/8] Update to version `22.0.x-dev` in `composer.json`. --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 17d8fc6..4a5e053 100644 --- a/composer.json +++ b/composer.json @@ -25,7 +25,7 @@ "minimum-stability": "dev", "require": { "php": ">=8.1", - "yiisoft/yii2": "2.2.x-dev" + "yiisoft/yii2": "22.0.x-dev" }, "require-dev": { "phpunit/phpunit": "^9.6"