From f8d541e472e164d037533ba5867e9404c806ecfb Mon Sep 17 00:00:00 2001 From: ADmad Date: Mon, 17 Jul 2023 18:58:05 +0530 Subject: [PATCH 1/4] Update for phpunit 10 and namespaced functions --- .github/workflows/ci.yml | 63 +++---------------- .gitignore | 1 + composer.json | 6 +- phpunit.xml.dist | 22 +++---- src/View/Helper/FormHelper.php | 2 + src/View/Helper/PaginatorHelper.php | 1 + templates/element/flash/default.php | 1 + .../TestCase/View/Helper/FlashHelperTest.php | 4 +- tests/bootstrap.php | 10 +-- 9 files changed, 29 insertions(+), 81 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index fb3d0333..9ae4a913 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -8,66 +8,17 @@ on: branches: - '*' +permissions: + contents: read + jobs: testsuite: - runs-on: ubuntu-20.04 - strategy: - fail-fast: false - matrix: - php-version: ['8.1', '8.2'] - prefer-lowest: [''] - include: - - php-version: '8.1' - prefer-lowest: 'prefer-lowest' - - services: - postgres: - image: postgres - ports: - - 5432:5432 - env: - POSTGRES_PASSWORD: postgres - - steps: - - uses: actions/checkout@v3 - - - name: Setup PHP - uses: shivammathur/setup-php@v2 - with: - php-version: ${{ matrix.php-version }} - extensions: mbstring, intl - coverage: pcov - - - name: Composer install - run: | - if ${{ matrix.prefer-lowest == 'prefer-lowest' }}; then - composer update --prefer-lowest --prefer-stable - elif ${{ matrix.php-version == '8.2' }}; then - composer update --ignore-platform-req=php - else - composer update - fi - - - name: Setup problem matchers for PHPUnit - if: matrix.php-version == '8.1' - run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json" - - - name: Run PHPUnit - run: | - if [[ ${{ matrix.php-version }} == '8.1' ]]; then - vendor/bin/phpunit --coverage-clover=coverage.xml - else - vendor/bin/phpunit - fi - continue-on-error: ${{ matrix.prefer-lowest == 'prefer-lowest' }} - - - name: Code Coverage Report - if: matrix.php-version == '8.1' - uses: codecov/codecov-action@v3 + uses: cakephp/.github/.github/workflows/testsuite-with-db.yml@5.x + secrets: inherit cs-stan: name: Coding Standard & Static Analysis - runs-on: ubuntu-20.04 + runs-on: ubuntu-22.04 steps: - uses: actions/checkout@v3 @@ -78,7 +29,7 @@ jobs: php-version: '8.1' extensions: mbstring, intl coverage: none - tools: cs2pr, vimeo/psalm:4.23, phpstan:1.7 + tools: cs2pr, vimeo/psalm:5, phpstan:1.10 - name: Composer Install run: composer install diff --git a/.gitignore b/.gitignore index 6fb0d54c..0c225561 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,7 @@ vendor/ composer.lock node_modules .phpunit.result.cache +.phpunit.cache # Generated test files tests/test_app/webroot/bootstrap_u_i diff --git a/composer.json b/composer.json index 6285fa05..8b43ca23 100644 --- a/composer.json +++ b/composer.json @@ -20,9 +20,9 @@ "cakephp/cakephp": "5.x-dev" }, "require-dev": { - "phpunit/phpunit": "^9.5.19", - "cakephp/bake": "dev-cake5", - "cakephp/cakephp-codesniffer": "5.x-dev" + "phpunit/phpunit": "^10.1", + "cakephp/bake": "3.x-dev", + "cakephp/cakephp-codesniffer": "^5.0" }, "support": { "issues": "http://github.com/friendsofcake/bootstrap-ui/issues", diff --git a/phpunit.xml.dist b/phpunit.xml.dist index b3e1dd7e..fb379f75 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,27 +1,19 @@ - - + tests/TestCase/ - - + - - - - src/ - - - + + + src/ + + diff --git a/src/View/Helper/FormHelper.php b/src/View/Helper/FormHelper.php index b26aa75d..20f5d10c 100644 --- a/src/View/Helper/FormHelper.php +++ b/src/View/Helper/FormHelper.php @@ -9,6 +9,8 @@ use Cake\View\Helper\FormHelper as CoreFormHelper; use Cake\View\View; use InvalidArgumentException; +use function Cake\Core\h; +use function Cake\I18n\__; class FormHelper extends CoreFormHelper { diff --git a/src/View/Helper/PaginatorHelper.php b/src/View/Helper/PaginatorHelper.php index a8f78d18..a6e7c6d7 100644 --- a/src/View/Helper/PaginatorHelper.php +++ b/src/View/Helper/PaginatorHelper.php @@ -5,6 +5,7 @@ use Cake\View\Helper\PaginatorHelper as CorePaginatorHelper; use Cake\View\View; +use function Cake\Core\h; class PaginatorHelper extends CorePaginatorHelper { diff --git a/templates/element/flash/default.php b/templates/element/flash/default.php index 76fe7c90..9f615a27 100644 --- a/templates/element/flash/default.php +++ b/templates/element/flash/default.php @@ -4,6 +4,7 @@ * @var array $params * @var string $message */ +use function Cake\Core\h; $icon = $params['icon']; $class = array_unique((array)$params['class']); diff --git a/tests/TestCase/View/Helper/FlashHelperTest.php b/tests/TestCase/View/Helper/FlashHelperTest.php index f03f062a..30f899dc 100644 --- a/tests/TestCase/View/Helper/FlashHelperTest.php +++ b/tests/TestCase/View/Helper/FlashHelperTest.php @@ -51,7 +51,7 @@ public function tearDown(): void unset($this->View, $this->Flash); } - public function flashTypeDefaultsDataProvider(): array + public static function flashTypeDefaultsDataProvider(): array { return [ ['default', 'info', 'info-circle-fill'], @@ -433,7 +433,7 @@ public function testCustomHtmlIcon() $this->assertHtml($expected, $result, true); } - public function flashTypeDataProvider(): array + public static function flashTypeDataProvider(): array { return [ ['default'], diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 1958d59e..3d5b9b25 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -84,16 +84,16 @@ ], ]); -if (!getenv('db_dsn')) { - putenv('db_dsn=sqlite:///:memory:'); +if (!getenv('DB_URL')) { + putenv('DB_URL=sqlite:///:memory:'); } -ConnectionManager::setConfig('test', ['url' => getenv('db_dsn')]); +ConnectionManager::setConfig('test', ['url' => getenv('DB_URL')]); Plugin::getCollection()->add(new BootstrapUIPlugin(['path' => ROOT . DS])); Plugin::getCollection()->add(new BakePlugin()); // Create test database schema -if (env('FIXTURE_SCHEMA_METADATA')) { +if (getenv('FIXTURE_SCHEMA_METADATA')) { $loader = new SchemaLoader(); - $loader->loadInternalFile(env('FIXTURE_SCHEMA_METADATA')); + $loader->loadInternalFile(getenv('FIXTURE_SCHEMA_METADATA')); } From 434ea3101303fe9e8858e0f10f6a5f8b75624eb3 Mon Sep 17 00:00:00 2001 From: ADmad Date: Mon, 17 Jul 2023 18:59:07 +0530 Subject: [PATCH 2/4] update psalm config --- psalm.xml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/psalm.xml b/psalm.xml index 12c5ed33..bb4ae33a 100644 --- a/psalm.xml +++ b/psalm.xml @@ -6,6 +6,8 @@ xmlns="https://getpsalm.org/schema/config" xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd" autoloader="tests/bootstrap.php" + findUnusedBaselineEntry="false" + findUnusedCode="false" > From d6223ef626f87d0af06dd03b35e15d4252d49522 Mon Sep 17 00:00:00 2001 From: ADmad Date: Wed, 13 Sep 2023 21:34:50 +0530 Subject: [PATCH 3/4] Exclude abstract class from testsuite. --- phpunit.xml.dist | 1 + 1 file changed, 1 insertion(+) diff --git a/phpunit.xml.dist b/phpunit.xml.dist index fb379f75..0c8957f8 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -3,6 +3,7 @@ tests/TestCase/ + tests/TestCase/View/Helper/FormHelper/AbstractFormHelperTest.php From c3296af1e78e6472dd8c3d9f82d73b340e5ed328 Mon Sep 17 00:00:00 2001 From: ADmad Date: Wed, 13 Sep 2023 21:36:24 +0530 Subject: [PATCH 4/4] Update deps to stable releases. --- composer.json | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/composer.json b/composer.json index 8b43ca23..d2536c7e 100644 --- a/composer.json +++ b/composer.json @@ -17,11 +17,11 @@ } ], "require": { - "cakephp/cakephp": "5.x-dev" + "cakephp/cakephp": "^5.0" }, "require-dev": { "phpunit/phpunit": "^10.1", - "cakephp/bake": "3.x-dev", + "cakephp/bake": "^3.0", "cakephp/cakephp-codesniffer": "^5.0" }, "support": { @@ -52,7 +52,5 @@ "allow-plugins": { "dealerdirect/phpcodesniffer-composer-installer": true } - }, - "minimum-stability": "dev", - "prefer-stable": true + } }