From 259f67174d02114fba42a304671b00d909f5bd17 Mon Sep 17 00:00:00 2001 From: Wilmer Arambula Date: Wed, 27 Sep 2023 08:15:55 -0300 Subject: [PATCH 1/3] Raise min version to `PHP 7.3`, check compatibility `PHP 8.3`. --- .github/workflows/build.yml | 71 ++++++++++++------------------- composer.json | 18 ++------ tests/CurlFormatterTest.php | 4 +- tests/MockTransportTest.php | 2 +- tests/RequestTest.php | 6 +-- tests/TestCase.php | 2 +- tests/TransportTestCase.php | 12 +++--- tests/UrlEncodedFormatterTest.php | 4 +- tests/XmlFormatterTest.php | 4 +- tests/bootstrap.php | 2 - tests/compatibility.php | 51 ---------------------- 11 files changed, 48 insertions(+), 128 deletions(-) delete mode 100644 tests/compatibility.php diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index fbb1946..97eab04 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -1,47 +1,32 @@ -name: build +on: + pull_request: + paths-ignore: + - 'docs/**' + - 'README.md' + - 'CHANGELOG.md' + - '.gitignore' + - '.gitattributes' + - 'infection.json.dist' + - 'psalm.xml' -on: [push, pull_request] + push: + branches: ['master'] + paths-ignore: + - 'docs/**' + - 'README.md' + - 'CHANGELOG.md' + - '.gitignore' + - '.gitattributes' + - 'infection.json.dist' + - 'psalm.xml' -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 + with: + os: >- + ['ubuntu-latest'] + php: >- + ['7.3', '7.4', '8.0', '8.1', '8.2', '8.3'] diff --git a/composer.json b/composer.json index 33709d7..dc489c1 100644 --- a/composer.json +++ b/composer.json @@ -18,12 +18,11 @@ } ], "require": { - "yiisoft/yii2": "~2.0.13", - "paragonie/random_compat": ">=1" + "php": ">=7.3", + "yiisoft/yii2": "~2.0.13" }, "require-dev": { - "cweagans/composer-patches": "^1.7", - "phpunit/phpunit": "4.8.34" + "phpunit/phpunit": "^9.6" }, "repositories": [ { @@ -33,7 +32,6 @@ ], "config": { "allow-plugins": { - "cweagans/composer-patches": true, "yiisoft/yii2-composer": true } }, @@ -43,16 +41,6 @@ "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" - } } } } 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..160c080 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); } /** @@ -93,8 +93,8 @@ public function testBatchSend() $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->assertStringContainsString('

Documentation

', $responses['docs']->getContent()); + $this->assertStringContainsString('Mailing Lists', $responses['support']->getContent()); } /** @@ -305,6 +305,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 diff --git a/tests/compatibility.php b/tests/compatibility.php deleted file mode 100644 index 126890e..0000000 --- a/tests/compatibility.php +++ /dev/null @@ -1,51 +0,0 @@ -setExpectedException($exception); - } - - /** - * @param string $message - */ - public function expectExceptionMessage($message) - { - $parentClassMethods = get_class_methods('PHPUnit_Framework_TestCase'); - if (in_array('expectExceptionMessage', $parentClassMethods)) { - parent::expectExceptionMessage($message); - return; - } - $this->setExpectedException($this->getExpectedException(), $message); - } - - /** - * @param string $messageRegExp - */ - public function expectExceptionMessageRegExp($messageRegExp) - { - $parentClassMethods = get_class_methods('PHPUnit_Framework_TestCase'); - if (in_array('expectExceptionMessageRegExp', $parentClassMethods)) { - parent::expectExceptionMessageRegExp($messageRegExp); - return; - } - $this->setExpectedExceptionRegExp($this->getExpectedException(), $messageRegExp); - } - } - } -} From 6d69e1ba3c9e863ebc3eaaa8bb7b3aa8f5d0a46b Mon Sep 17 00:00:00 2001 From: Wilmer Arambula Date: Wed, 27 Sep 2023 08:26:09 -0300 Subject: [PATCH 2/3] Use `AssertInstanceOf()` method. --- tests/TransportTestCase.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/tests/TransportTestCase.php b/tests/TransportTestCase.php index 160c080..d09c63f 100644 --- a/tests/TransportTestCase.php +++ b/tests/TransportTestCase.php @@ -90,9 +90,8 @@ public function testBatchSend() $this->assertResponseIsOK($response); } - $this->assertTrue($responses['docs'] instanceof Response, $responses); - $this->assertTrue($responses['support'] instanceof Response, $responses); - + $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()); } From 9615f5e898142109f8c93363cab8762f8d58f09c Mon Sep 17 00:00:00 2001 From: Wilmer Arambula Date: Wed, 27 Sep 2023 09:28:36 -0300 Subject: [PATCH 3/3] Add `.scrutinizer.yml`. --- .scrutinizer.yml | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 .scrutinizer.yml diff --git a/.scrutinizer.yml b/.scrutinizer.yml new file mode 100644 index 0000000..9eb4027 --- /dev/null +++ b/.scrutinizer.yml @@ -0,0 +1,31 @@ +checks: + php: true + +filter: + paths: + - src/ + +build: + image: default-bionic + + environment: + php: + version: 8.0.18 + ini: + xdebug.mode: coverage + + nodes: + analysis: + tests: + override: + - php-scrutinizer-run + + phpunit: + dependencies: + override: + - composer self-update + - composer update --prefer-dist --no-interaction --no-progress --optimize-autoloader --ansi + + tests: + override: + - command: ./vendor/bin/phpunit