From d31b334d8a375609d6941730c52260b7f7346e03 Mon Sep 17 00:00:00 2001 From: Wilmer Arambula Date: Thu, 5 Oct 2023 08:24:40 -0300 Subject: [PATCH] Raise min `PHP` version to `PHP 7.3`, check compatibility `PHP 8.3`. --- .editorconfig | 3 ++ .github/workflows/build.yml | 73 +++++++++++++++---------------------- composer.json | 22 ++++------- phpunit.xml.dist | 37 +++++++++++++------ tests/DatePickerTest.php | 6 +-- tests/SelectableTest.php | 10 +++-- tests/TestCase.php | 4 +- tests/bootstrap.php | 2 - tests/compatibility.php | 50 ------------------------- 9 files changed, 77 insertions(+), 130 deletions(-) delete mode 100644 tests/compatibility.php diff --git a/.editorconfig b/.editorconfig index 257221d23..5e9a93ea5 100644 --- a/.editorconfig +++ b/.editorconfig @@ -12,3 +12,6 @@ trim_trailing_whitespace = true [*.md] trim_trailing_whitespace = false + +[*.yml] +indent_size = 2 diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 65c872d2e..7b04820fd 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -1,47 +1,34 @@ -name: build +on: + fork: -on: [push, pull_request] + pull_request: + 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" + push: + paths-ignore: + - 'docs/**' + - 'README.md' + - 'CHANGELOG.md' + - '.gitignore' + - '.gitattributes' + - 'infection.json.dist' + - 'psalm.xml' -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'] +name: build - 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 +jobs: + phpunit: + if: github.event.repository.fork == true || (github.event_name == 'push' && github.ref == 'refs/heads/master') + 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 93e9311be..d662eb58b 100644 --- a/composer.json +++ b/composer.json @@ -30,12 +30,11 @@ } ], "require": { - "yiisoft/yii2": "~2.0.4", - "bower-asset/jquery-ui": "~1.12.1" + "bower-asset/jquery-ui": "~1.12.1", + "yiisoft/yii2": "~2.0.4" }, "require-dev": { - "cweagans/composer-patches": "^1.7", - "phpunit/phpunit": "4.8.34" + "phpunit/phpunit": "^9.6" }, "repositories": [ { @@ -51,16 +50,11 @@ "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" - } + } + }, + "config": { + "allow-plugins": { + "yiisoft/yii2-composer": true } } } diff --git a/phpunit.xml.dist b/phpunit.xml.dist index a2bff8953..98c89768c 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,14 +1,27 @@ - - - - ./tests - - + + + + + + + + + ./tests + + + + + + ./src + + diff --git a/tests/DatePickerTest.php b/tests/DatePickerTest.php index 4d5604501..ddc2b39d2 100644 --- a/tests/DatePickerTest.php +++ b/tests/DatePickerTest.php @@ -42,10 +42,10 @@ public function testLanguageAsset() ]); // https://github.com/yiisoft/yii2-jui/issues/6 - static::assertRegExp( + $this->assertMatchesRegularExpression( '~~', $out, - 'There should be language asset registered with timestamp appended.' + 'There should be language asset registered with timestamp appended.', ); } @@ -79,6 +79,6 @@ public function testInvalidDateValue($value) 'value' => $value ]); $output = ob_get_clean(); - $this->assertContains($value, $output); + $this->assertStringContainsString($value, $output); } } diff --git a/tests/SelectableTest.php b/tests/SelectableTest.php index d3d7be3be..b43dd9005 100644 --- a/tests/SelectableTest.php +++ b/tests/SelectableTest.php @@ -58,13 +58,15 @@ public function testBeginEnd() ]); // https://github.com/yiisoft/yii2-jui/issues/46 - static::assertRegExp( + $this->assertMatchesRegularExpression( '~
\n
    \n
  • Item 1
  • \n
  • Item 2
  • \n
  • Item 3
  • \n
  • Item 4
  • \n
\n
\n
\n
Another item
\n
\n
~', $out, - 'There should be a div with class myselectableitems enclosing html between begin()` and `end()` methods'); - static::assertRegExp( + 'There should be a div with class myselectableitems enclosing html between begin()` and `end()` methods', + ); + $this->assertMatchesRegularExpression( '~~', $out, - 'There should be the jQuery UI Selectable plugin initialization for myselectableitems'); + 'There should be the jQuery UI Selectable plugin initialization for myselectableitems', + ); } } diff --git a/tests/TestCase.php b/tests/TestCase.php index abc45ce9c..08c3968f7 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -11,7 +11,7 @@ */ abstract class TestCase extends \PHPUnit\Framework\TestCase { - protected function setUp() + protected function setUp(): void { parent::setUp(); $this->mockWebApplication(); @@ -21,7 +21,7 @@ protected function setUp() * 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/bootstrap.php b/tests/bootstrap.php index ebda25403..88e44aea6 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -13,5 +13,3 @@ Yii::setAlias('@yiiunit/extensions/jui', __DIR__); Yii::setAlias('@yii/jui', 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 95e4cd1bc..000000000 --- a/tests/compatibility.php +++ /dev/null @@ -1,50 +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); - } - } - } -}