From 042346af69f364df78c60787c62891fc78489475 Mon Sep 17 00:00:00 2001 From: bnomei Date: Mon, 22 Jul 2024 12:41:12 +0200 Subject: [PATCH] :recycle: codeclimate, CI tests --- .github/workflows/pest-tests.yml | 43 ++++++-- .github/workflows/phpstan.yml | 10 +- .gitignore | 4 +- .travis.yml | 14 --- README.md | 4 +- classes/Mongodb.php | 11 +- composer.json | 13 ++- composer.lock | 172 +++++++++++++++---------------- phpstan.neon.dist | 7 +- tests/MongodbTest.php | 70 ++++++++++++- tests/site/config/config.php | 2 + vendor/composer/installed.php | 8 +- 12 files changed, 231 insertions(+), 127 deletions(-) delete mode 100644 .travis.yml diff --git a/.github/workflows/pest-tests.yml b/.github/workflows/pest-tests.yml index c6aa7db..2e338ac 100644 --- a/.github/workflows/pest-tests.yml +++ b/.github/workflows/pest-tests.yml @@ -1,15 +1,37 @@ name: Pest Tests -on: ['push', 'pull_request'] +on: [ 'push', 'pull_request' ] jobs: test: runs-on: ubuntu-latest + env: + extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv, imagick, redis, xdebug, mongodb steps: - name: Checkout uses: actions/checkout@v4 + - name: Start MongoDB + uses: supercharge/mongodb-github-action@1.11.0 + with: + mongodb-version: latest + + - name: Setup cache environment + id: extcache + uses: shivammathur/cache-extensions@v1 + with: + php-version: ${{ matrix.php }} + extensions: ${{ env.extensions }} + key: extensions-${{ hashFiles('composer.lock') }} + + - name: Cache extensions + uses: actions/cache@v4 + with: + path: ${{ steps.extcache.outputs.dir }} + key: ${{ steps.extcache.outputs.key }} + restore-keys: ${{ steps.extcache.outputs.key }} + - name: Setup PHP uses: shivammathur/setup-php@v2 with: @@ -17,11 +39,20 @@ jobs: tools: composer:v2 coverage: xdebug + - name: Cache composer dependencies + uses: actions/cache@v4 + with: + path: vendor + key: composer-${{ hashFiles('composer.lock') }} + - name: Install run: composer install --no-interaction --prefer-dist --optimize-autoloader - - name: Run Tests - run: | - php tests/patch.php - ./vendor/bin/pest --group=SetupPagesInSeparatePHPUnitRun - ./vendor/bin/pest + - name: Test & publish code coverage + uses: paambaati/codeclimate-action@v8.0.0 + with: + coverageCommand: composer coverage + coverageLocations: ${{github.workspace}}/tests/clover.xml:clover + env: + CC_TEST_REPORTER_ID: ${{ secrets.CC_TEST_REPORTER_ID }} + diff --git a/.github/workflows/phpstan.yml b/.github/workflows/phpstan.yml index f0a8f9c..fbbcc31 100644 --- a/.github/workflows/phpstan.yml +++ b/.github/workflows/phpstan.yml @@ -21,9 +21,17 @@ jobs: tools: composer:v2 coverage: none + - name: Cache composer dependencies + uses: actions/cache@v4 + with: + path: vendor + key: composer-${{ hashFiles('composer.lock') }} + - name: Install run: | composer install --no-interaction --prefer-dist --optimize-autoloader - name: Run PHPStan - run: ./vendor/bin/phpstan --error-format=github + run: | + php tests/patch.php + ./vendor/bin/phpstan --error-format=github diff --git a/.gitignore b/.gitignore index 2b9727d..40c7237 100644 --- a/.gitignore +++ b/.gitignore @@ -5,6 +5,7 @@ /build +/tests/clover.xml /tests/kirby /tests/logs /tests/media @@ -12,9 +13,6 @@ /tests/site/accounts /tests/site/cache /tests/site/sessions -/tests/site/plugins/kirby3-sqlite-cachedriver -/tests/site/plugins/kirby3-redis-cachedriver -/tests/site/plugins/kql # files of Composer dependencies that are not needed for the plugin /vendor/**/.* diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 84a21da..0000000 --- a/.travis.yml +++ /dev/null @@ -1,14 +0,0 @@ -language: php -php: 8.2 -matrix: - fast_finish: true -install: composer install --no-interaction -script: composer test -after_success: travis_retry php vendor/bin/php-coveralls -v -notifications: - webhooks: - on_success: change - on_failure: always - on_start: never - urls: - - https://webhooks.gitter.im/e/77d9949056dc0462d25d diff --git a/README.md b/README.md index 8435ef3..16139ab 100644 --- a/README.md +++ b/README.md @@ -2,9 +2,9 @@ ![Release](https://flat.badgen.net/packagist/v/bnomei/kirby-mongodb?color=ae81ff) ![Downloads](https://flat.badgen.net/packagist/dt/bnomei/kirby-mongodb?color=272822) -[![Build Status](https://flat.badgen.net/travis/bnomei/kirby-mongodb)](https://travis-ci.com/bnomei/kirby-mongodb) +[![Coverage](https://flat.badgen.net/codeclimate/coverage/bnomei/kirby-mongodb)](https://codeclimate.com/github/bnomei/kirby-mongodb) [![Maintainability](https://flat.badgen.net/codeclimate/maintainability/bnomei/kirby-mongodb)](https://codeclimate.com/github/bnomei/kirby-mongodb) -[![Twitter](https://flat.badgen.net/badge/twitter/bnomei?color=66d9ef)](https://twitter.com/bnomei) +[![Discord](https://flat.badgen.net/badge/discord/bnomei?color=7289da)](https://discordapp.com/users/bnomei) Khulan is a cache driver and content cache with NoSQL interface for Kirby using MongoDB. diff --git a/classes/Mongodb.php b/classes/Mongodb.php index f5267eb..cc1c534 100644 --- a/classes/Mongodb.php +++ b/classes/Mongodb.php @@ -5,6 +5,7 @@ namespace Bnomei; use Kirby\Cache\Cache; +use Kirby\Cache\FileCache; use Kirby\Cache\Value; use Kirby\Toolkit\A; use Kirby\Toolkit\Str; @@ -151,7 +152,10 @@ public function flush(): bool return $this->cacheCollection()->deleteMany([])->isAcknowledged(); } - public function benchmark(int $count = 10) + /** + * @codeCoverageIgnore + */ + public function benchmark(int $count = 10): void { $prefix = 'mongodb-benchmark-'; $mongodb = $this; @@ -188,7 +192,10 @@ public function benchmark(int $count = 10) */ public function root(): string { - return kirby()->cache('bnomei.mongodb')->root(); + /** @var FileCache $cache */ + $cache = kirby()->cache('bnomei.mongodb'); + + return $cache->root(); } public function clean(?int $time = null): ?int diff --git a/composer.json b/composer.json index 526973f..c3c3d20 100644 --- a/composer.json +++ b/composer.json @@ -1,7 +1,7 @@ { "name": "bnomei/kirby-mongodb", "type": "kirby-plugin", - "version": "1.4.3", + "version": "1.4.4", "description": "Khulan is a cache driver and content cache with NoSQL interface for Kirby using MongoDB", "license": "MIT", "authors": [ @@ -56,7 +56,11 @@ "scripts": { "analyze": "./vendor/bin/phpstan", "fix": "./vendor/bin/pint", - "test": "./vendor/bin/pest --coverage", + "test": "./vendor/bin/pest", + "coverage": [ + "php tests/patch.php", + "./vendor/bin/pest --coverage" + ], "dist": [ "composer install --no-dev --optimize-autoloader", "git rm -rf --cached .; git add .;" @@ -71,5 +75,10 @@ }, "extra": { "kirby-cms-path": "tests/kirby" + }, + "suggest": { + "bnomei/kirby-blueprints": "PHP Class-based Blueprints for Kirby CMS for better type safety and code completion.", + "bnomei/kirby3-lapse": "Cache any data until set expiration time (with automatic keys).", + "getkirby/staticache": "Static site performance on demand!" } } diff --git a/composer.lock b/composer.lock index 79ce35c..4a13910 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "2acb6bf396ddb610a0869853263d09a4", + "content-hash": "3cfb4716ea326a65795bf69e2fe1a4ec", "packages": [ { "name": "getkirby/composer-installer", @@ -1200,22 +1200,22 @@ }, { "name": "guzzlehttp/guzzle", - "version": "7.8.1", + "version": "7.9.1", "source": { "type": "git", "url": "https://github.com/guzzle/guzzle.git", - "reference": "41042bc7ab002487b876a0683fc8dce04ddce104" + "reference": "a629e5b69db96eb4939c1b34114130077dd4c6fc" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/guzzle/guzzle/zipball/41042bc7ab002487b876a0683fc8dce04ddce104", - "reference": "41042bc7ab002487b876a0683fc8dce04ddce104", + "url": "https://api.github.com/repos/guzzle/guzzle/zipball/a629e5b69db96eb4939c1b34114130077dd4c6fc", + "reference": "a629e5b69db96eb4939c1b34114130077dd4c6fc", "shasum": "" }, "require": { "ext-json": "*", - "guzzlehttp/promises": "^1.5.3 || ^2.0.1", - "guzzlehttp/psr7": "^1.9.1 || ^2.5.1", + "guzzlehttp/promises": "^1.5.3 || ^2.0.3", + "guzzlehttp/psr7": "^2.7.0", "php": "^7.2.5 || ^8.0", "psr/http-client": "^1.0", "symfony/deprecation-contracts": "^2.2 || ^3.0" @@ -1226,9 +1226,9 @@ "require-dev": { "bamarni/composer-bin-plugin": "^1.8.2", "ext-curl": "*", - "php-http/client-integration-tests": "dev-master#2c025848417c1135031fdf9c728ee53d0a7ceaee as 3.0.999", + "guzzle/client-integration-tests": "3.0.2", "php-http/message-factory": "^1.1", - "phpunit/phpunit": "^8.5.36 || ^9.6.15", + "phpunit/phpunit": "^8.5.39 || ^9.6.20", "psr/log": "^1.1 || ^2.0 || ^3.0" }, "suggest": { @@ -1306,7 +1306,7 @@ ], "support": { "issues": "https://github.com/guzzle/guzzle/issues", - "source": "https://github.com/guzzle/guzzle/tree/7.8.1" + "source": "https://github.com/guzzle/guzzle/tree/7.9.1" }, "funding": [ { @@ -1322,20 +1322,20 @@ "type": "tidelift" } ], - "time": "2023-12-03T20:35:24+00:00" + "time": "2024-07-19T16:19:57+00:00" }, { "name": "guzzlehttp/promises", - "version": "2.0.2", + "version": "2.0.3", "source": { "type": "git", "url": "https://github.com/guzzle/promises.git", - "reference": "bbff78d96034045e58e13dedd6ad91b5d1253223" + "reference": "6ea8dd08867a2a42619d65c3deb2c0fcbf81c8f8" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/guzzle/promises/zipball/bbff78d96034045e58e13dedd6ad91b5d1253223", - "reference": "bbff78d96034045e58e13dedd6ad91b5d1253223", + "url": "https://api.github.com/repos/guzzle/promises/zipball/6ea8dd08867a2a42619d65c3deb2c0fcbf81c8f8", + "reference": "6ea8dd08867a2a42619d65c3deb2c0fcbf81c8f8", "shasum": "" }, "require": { @@ -1343,7 +1343,7 @@ }, "require-dev": { "bamarni/composer-bin-plugin": "^1.8.2", - "phpunit/phpunit": "^8.5.36 || ^9.6.15" + "phpunit/phpunit": "^8.5.39 || ^9.6.20" }, "type": "library", "extra": { @@ -1389,7 +1389,7 @@ ], "support": { "issues": "https://github.com/guzzle/promises/issues", - "source": "https://github.com/guzzle/promises/tree/2.0.2" + "source": "https://github.com/guzzle/promises/tree/2.0.3" }, "funding": [ { @@ -1405,20 +1405,20 @@ "type": "tidelift" } ], - "time": "2023-12-03T20:19:20+00:00" + "time": "2024-07-18T10:29:17+00:00" }, { "name": "guzzlehttp/psr7", - "version": "2.6.2", + "version": "2.7.0", "source": { "type": "git", "url": "https://github.com/guzzle/psr7.git", - "reference": "45b30f99ac27b5ca93cb4831afe16285f57b8221" + "reference": "a70f5c95fb43bc83f07c9c948baa0dc1829bf201" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/guzzle/psr7/zipball/45b30f99ac27b5ca93cb4831afe16285f57b8221", - "reference": "45b30f99ac27b5ca93cb4831afe16285f57b8221", + "url": "https://api.github.com/repos/guzzle/psr7/zipball/a70f5c95fb43bc83f07c9c948baa0dc1829bf201", + "reference": "a70f5c95fb43bc83f07c9c948baa0dc1829bf201", "shasum": "" }, "require": { @@ -1433,8 +1433,8 @@ }, "require-dev": { "bamarni/composer-bin-plugin": "^1.8.2", - "http-interop/http-factory-tests": "^0.9", - "phpunit/phpunit": "^8.5.36 || ^9.6.15" + "http-interop/http-factory-tests": "0.9.0", + "phpunit/phpunit": "^8.5.39 || ^9.6.20" }, "suggest": { "laminas/laminas-httphandlerrunner": "Emit PSR-7 responses" @@ -1505,7 +1505,7 @@ ], "support": { "issues": "https://github.com/guzzle/psr7/issues", - "source": "https://github.com/guzzle/psr7/tree/2.6.2" + "source": "https://github.com/guzzle/psr7/tree/2.7.0" }, "funding": [ { @@ -1521,7 +1521,7 @@ "type": "tidelift" } ], - "time": "2023-12-03T20:05:35+00:00" + "time": "2024-07-18T11:15:46+00:00" }, { "name": "guzzlehttp/uri-template", @@ -1611,7 +1611,7 @@ }, { "name": "illuminate/bus", - "version": "v11.15.0", + "version": "v11.16.0", "source": { "type": "git", "url": "https://github.com/illuminate/bus.git", @@ -1664,16 +1664,16 @@ }, { "name": "illuminate/collections", - "version": "v11.15.0", + "version": "v11.16.0", "source": { "type": "git", "url": "https://github.com/illuminate/collections.git", - "reference": "9bf68f03bbe05d38c9bd99bac8798c0de61f8478" + "reference": "ba2cf689f7d75315f483334b4efc8c6af1d5159c" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/illuminate/collections/zipball/9bf68f03bbe05d38c9bd99bac8798c0de61f8478", - "reference": "9bf68f03bbe05d38c9bd99bac8798c0de61f8478", + "url": "https://api.github.com/repos/illuminate/collections/zipball/ba2cf689f7d75315f483334b4efc8c6af1d5159c", + "reference": "ba2cf689f7d75315f483334b4efc8c6af1d5159c", "shasum": "" }, "require": { @@ -1715,11 +1715,11 @@ "issues": "https://github.com/laravel/framework/issues", "source": "https://github.com/laravel/framework" }, - "time": "2024-07-02T20:54:37+00:00" + "time": "2024-07-15T21:44:45+00:00" }, { "name": "illuminate/conditionable", - "version": "v11.15.0", + "version": "v11.16.0", "source": { "type": "git", "url": "https://github.com/illuminate/conditionable.git", @@ -1765,16 +1765,16 @@ }, { "name": "illuminate/console", - "version": "v11.15.0", + "version": "v11.16.0", "source": { "type": "git", "url": "https://github.com/illuminate/console.git", - "reference": "4015055694406a0c41788d2d1ea7f34be3ec2080" + "reference": "896cc74364c8bc8ecd8adba98278a482c9626b73" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/illuminate/console/zipball/4015055694406a0c41788d2d1ea7f34be3ec2080", - "reference": "4015055694406a0c41788d2d1ea7f34be3ec2080", + "url": "https://api.github.com/repos/illuminate/console/zipball/896cc74364c8bc8ecd8adba98278a482c9626b73", + "reference": "896cc74364c8bc8ecd8adba98278a482c9626b73", "shasum": "" }, "require": { @@ -1827,11 +1827,11 @@ "issues": "https://github.com/laravel/framework/issues", "source": "https://github.com/laravel/framework" }, - "time": "2024-07-04T06:39:48+00:00" + "time": "2024-07-15T21:52:09+00:00" }, { "name": "illuminate/container", - "version": "v11.15.0", + "version": "v11.16.0", "source": { "type": "git", "url": "https://github.com/illuminate/container.git", @@ -1882,7 +1882,7 @@ }, { "name": "illuminate/contracts", - "version": "v11.15.0", + "version": "v11.16.0", "source": { "type": "git", "url": "https://github.com/illuminate/contracts.git", @@ -1930,16 +1930,16 @@ }, { "name": "illuminate/database", - "version": "v11.15.0", + "version": "v11.16.0", "source": { "type": "git", "url": "https://github.com/illuminate/database.git", - "reference": "9b7b13d2d9175ae9c07d4744d8f7d5b07e7264a7" + "reference": "cf816e7e0d08e2a75b233ad061eed85dd8b6b37f" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/illuminate/database/zipball/9b7b13d2d9175ae9c07d4744d8f7d5b07e7264a7", - "reference": "9b7b13d2d9175ae9c07d4744d8f7d5b07e7264a7", + "url": "https://api.github.com/repos/illuminate/database/zipball/cf816e7e0d08e2a75b233ad061eed85dd8b6b37f", + "reference": "cf816e7e0d08e2a75b233ad061eed85dd8b6b37f", "shasum": "" }, "require": { @@ -1994,11 +1994,11 @@ "issues": "https://github.com/laravel/framework/issues", "source": "https://github.com/laravel/framework" }, - "time": "2024-07-08T15:08:27+00:00" + "time": "2024-07-15T22:28:28+00:00" }, { "name": "illuminate/events", - "version": "v11.15.0", + "version": "v11.16.0", "source": { "type": "git", "url": "https://github.com/illuminate/events.git", @@ -2053,7 +2053,7 @@ }, { "name": "illuminate/filesystem", - "version": "v11.15.0", + "version": "v11.16.0", "source": { "type": "git", "url": "https://github.com/illuminate/filesystem.git", @@ -2120,16 +2120,16 @@ }, { "name": "illuminate/http", - "version": "v11.15.0", + "version": "v11.16.0", "source": { "type": "git", "url": "https://github.com/illuminate/http.git", - "reference": "bbeda8564171e44c202688f5cacb6eb67ea6ec3b" + "reference": "63072ea6bcbd75b75655e0bb2854150a0ed886d3" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/illuminate/http/zipball/bbeda8564171e44c202688f5cacb6eb67ea6ec3b", - "reference": "bbeda8564171e44c202688f5cacb6eb67ea6ec3b", + "url": "https://api.github.com/repos/illuminate/http/zipball/63072ea6bcbd75b75655e0bb2854150a0ed886d3", + "reference": "63072ea6bcbd75b75655e0bb2854150a0ed886d3", "shasum": "" }, "require": { @@ -2177,11 +2177,11 @@ "issues": "https://github.com/laravel/framework/issues", "source": "https://github.com/laravel/framework" }, - "time": "2024-07-01T20:51:35+00:00" + "time": "2024-07-10T19:27:29+00:00" }, { "name": "illuminate/macroable", - "version": "v11.15.0", + "version": "v11.16.0", "source": { "type": "git", "url": "https://github.com/illuminate/macroable.git", @@ -2227,7 +2227,7 @@ }, { "name": "illuminate/pipeline", - "version": "v11.15.0", + "version": "v11.16.0", "source": { "type": "git", "url": "https://github.com/illuminate/pipeline.git", @@ -2275,7 +2275,7 @@ }, { "name": "illuminate/session", - "version": "v11.15.0", + "version": "v11.16.0", "source": { "type": "git", "url": "https://github.com/illuminate/session.git", @@ -2332,16 +2332,16 @@ }, { "name": "illuminate/support", - "version": "v11.15.0", + "version": "v11.16.0", "source": { "type": "git", "url": "https://github.com/illuminate/support.git", - "reference": "b551f6cbecc607bcaf520eb3fc1933db9b1398f2" + "reference": "4fd85fffd9a4812386b6e10b2a18272ff9040dbe" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/illuminate/support/zipball/b551f6cbecc607bcaf520eb3fc1933db9b1398f2", - "reference": "b551f6cbecc607bcaf520eb3fc1933db9b1398f2", + "url": "https://api.github.com/repos/illuminate/support/zipball/4fd85fffd9a4812386b6e10b2a18272ff9040dbe", + "reference": "4fd85fffd9a4812386b6e10b2a18272ff9040dbe", "shasum": "" }, "require": { @@ -2402,11 +2402,11 @@ "issues": "https://github.com/laravel/framework/issues", "source": "https://github.com/laravel/framework" }, - "time": "2024-07-08T14:46:56+00:00" + "time": "2024-07-16T13:48:58+00:00" }, { "name": "illuminate/view", - "version": "v11.15.0", + "version": "v11.16.0", "source": { "type": "git", "url": "https://github.com/illuminate/view.git", @@ -2982,16 +2982,16 @@ }, { "name": "nesbot/carbon", - "version": "3.6.0", + "version": "3.7.0", "source": { "type": "git", "url": "https://github.com/briannesbitt/Carbon.git", - "reference": "39c8ef752db6865717cc3fba63970c16f057982c" + "reference": "cb4374784c87d0a0294e8513a52eb63c0aff3139" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/briannesbitt/Carbon/zipball/39c8ef752db6865717cc3fba63970c16f057982c", - "reference": "39c8ef752db6865717cc3fba63970c16f057982c", + "url": "https://api.github.com/repos/briannesbitt/Carbon/zipball/cb4374784c87d0a0294e8513a52eb63c0aff3139", + "reference": "cb4374784c87d0a0294e8513a52eb63c0aff3139", "shasum": "" }, "require": { @@ -3084,7 +3084,7 @@ "type": "tidelift" } ], - "time": "2024-06-20T15:52:59+00:00" + "time": "2024-07-16T22:29:20+00:00" }, { "name": "nette/utils", @@ -3232,38 +3232,38 @@ }, { "name": "nunomaduro/collision", - "version": "v8.1.1", + "version": "v8.3.0", "source": { "type": "git", "url": "https://github.com/nunomaduro/collision.git", - "reference": "13e5d538b95a744d85f447a321ce10adb28e9af9" + "reference": "b49f5b2891ce52726adfd162841c69d4e4c84229" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/nunomaduro/collision/zipball/13e5d538b95a744d85f447a321ce10adb28e9af9", - "reference": "13e5d538b95a744d85f447a321ce10adb28e9af9", + "url": "https://api.github.com/repos/nunomaduro/collision/zipball/b49f5b2891ce52726adfd162841c69d4e4c84229", + "reference": "b49f5b2891ce52726adfd162841c69d4e4c84229", "shasum": "" }, "require": { "filp/whoops": "^2.15.4", "nunomaduro/termwind": "^2.0.1", "php": "^8.2.0", - "symfony/console": "^7.0.4" + "symfony/console": "^7.1.2" }, "conflict": { "laravel/framework": "<11.0.0 || >=12.0.0", "phpunit/phpunit": "<10.5.1 || >=12.0.0" }, "require-dev": { - "larastan/larastan": "^2.9.2", - "laravel/framework": "^11.0.0", - "laravel/pint": "^1.14.0", - "laravel/sail": "^1.28.2", - "laravel/sanctum": "^4.0.0", + "larastan/larastan": "^2.9.8", + "laravel/framework": "^11.16.0", + "laravel/pint": "^1.16.2", + "laravel/sail": "^1.30.2", + "laravel/sanctum": "^4.0.2", "laravel/tinker": "^2.9.0", - "orchestra/testbench-core": "^9.0.0", - "pestphp/pest": "^2.34.1 || ^3.0.0", - "sebastian/environment": "^6.0.1 || ^7.0.0" + "orchestra/testbench-core": "^9.2.1", + "pestphp/pest": "^2.34.9 || ^3.0.0", + "sebastian/environment": "^6.1.0 || ^7.0.0" }, "type": "library", "extra": { @@ -3325,7 +3325,7 @@ "type": "patreon" } ], - "time": "2024-03-06T16:20:09+00:00" + "time": "2024-07-16T22:41:01+00:00" }, { "name": "nunomaduro/termwind", @@ -6231,16 +6231,16 @@ }, { "name": "spatie/backtrace", - "version": "1.6.1", + "version": "1.6.2", "source": { "type": "git", "url": "https://github.com/spatie/backtrace.git", - "reference": "8373b9d51638292e3bfd736a9c19a654111b4a23" + "reference": "1a9a145b044677ae3424693f7b06479fc8c137a9" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/spatie/backtrace/zipball/8373b9d51638292e3bfd736a9c19a654111b4a23", - "reference": "8373b9d51638292e3bfd736a9c19a654111b4a23", + "url": "https://api.github.com/repos/spatie/backtrace/zipball/1a9a145b044677ae3424693f7b06479fc8c137a9", + "reference": "1a9a145b044677ae3424693f7b06479fc8c137a9", "shasum": "" }, "require": { @@ -6278,7 +6278,7 @@ "spatie" ], "support": { - "source": "https://github.com/spatie/backtrace/tree/1.6.1" + "source": "https://github.com/spatie/backtrace/tree/1.6.2" }, "funding": [ { @@ -6290,7 +6290,7 @@ "type": "other" } ], - "time": "2024-04-24T13:22:11+00:00" + "time": "2024-07-22T08:21:24+00:00" }, { "name": "spatie/macroable", diff --git a/phpstan.neon.dist b/phpstan.neon.dist index 1574f4c..4e6570f 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -2,12 +2,11 @@ parameters: level: 5 paths: - classes - - collections - index.php excludePaths: - tests - - collections/example_*.php - checkMissingIterableValueType: false ignoreErrors: - - '#Undefined variable: \$this#' +# - '#Undefined variable: \$this#' + - + identifier: missingType.iterableValue diff --git a/tests/MongodbTest.php b/tests/MongodbTest.php index d82797e..29b954e 100644 --- a/tests/MongodbTest.php +++ b/tests/MongodbTest.php @@ -23,9 +23,11 @@ Mongodb::$singleton = null; $mongodb = Mongodb::singleton([ 'debug' => true, // default is false from config + 'uriOptions' => fn () => [], ]); - expect($mongodb->option('debug'))->toBe(true); + expect($mongodb->option('debug'))->toBe(true) + ->and($mongodb->option('uriOptions'))->toBeArray(); Mongodb::$singleton = null; }); @@ -67,7 +69,11 @@ $mongodb->set('test', 'value'); $value = $mongodb->get('test'); - expect($value)->toBe('value'); + expect($value)->toBe('value') + ->and($mongodb->root())->toBeDirectory() + ->and($mongodb->cache())->toBe($mongodb) + ->and($mongodb->remove('test'))->toBeTrue() + ->and($mongodb->get('test'))->toBeNull(); }); it('can use the cache for array based values', function () { @@ -107,7 +113,8 @@ 'debug' => true, ]); - expect($mongodb->option('debug'))->toBeTrue(); + expect($mongodb->option('debug'))->toBeTrue() + ->and($mongodb->option()['debug'])->toBeTrue(); $mongodb->set('test', 'value'); expect($mongodb->get('test'))->toBeNull(); @@ -260,6 +267,63 @@ expect($page)->not()->toBeNull(); }); +it('will remove the cache if a page gets deleted', function () { + Khulan::index(); + + kirby()->impersonate('kirby'); + + $page = page('home')->createChild([ + 'slug' => 'rainbow', + 'template' => 'default', + 'content' => [ + 'title' => 'Rainbow', + 'uuid' => 'rainbow', + ], + ]); + + $page = khulan('rainbow'); + expect($page)->not()->toBeNull(); + + $page->delete(); + $page = khulan('rainbow'); + expect($page)->toBeNull(); +}); + +it('can flush the content cache', function () { + Khulan::index(); + + $page = khulan('betterharder'); + expect($page)->not()->toBeNull(); + + Khulan::flush(); + $page = khulan('betterharder'); + expect($page)->toBeNull(); +}); + +it('can convert documents to models', function () { + Khulan::index(); + + $documents = khulan()->find([ + 'template' => 'default', + 'status' => 'listed', + 'language' => 'en', + 'category[,]' => 'books', + ]); + + $models = Khulan::documentsToModels($documents); + expect($models)->toBeInstanceOf(\Kirby\Cms\Pages::class); +}); + +it('can encode and decode data for mongodb', function () { + /** @var \Bnomei\KhulanPage $page */ + $page = page('betterharder'); + $data = $page->content()->toArray(); + $encoded = $page->encodeKhulan($data); + $decoded = $page->decodeKhulan($encoded); + + expect($decoded)->toBe($data); +}); + it('can run the benchmark', function () { mongo()->benchmark(); })->skip(); diff --git a/tests/site/config/config.php b/tests/site/config/config.php index 002f4c3..a16c5bb 100644 --- a/tests/site/config/config.php +++ b/tests/site/config/config.php @@ -10,4 +10,6 @@ ], 'bnomei.mongodb.khulan.patch-files-class' => true, // do the monkey patch + 'bnomei.mongodb.khulan.read' => true, // for unit-testing only + 'bnomei.mongodb.khulan.write' => true, // always write to mongodb ]; diff --git a/vendor/composer/installed.php b/vendor/composer/installed.php index 8138637..e5e6cfc 100644 --- a/vendor/composer/installed.php +++ b/vendor/composer/installed.php @@ -1,8 +1,8 @@ array( 'name' => 'bnomei/kirby-mongodb', - 'pretty_version' => '1.4.3', - 'version' => '1.4.3.0', + 'pretty_version' => '1.4.4', + 'version' => '1.4.4.0', 'reference' => null, 'type' => 'kirby-plugin', 'install_path' => __DIR__ . '/../../', @@ -11,8 +11,8 @@ ), 'versions' => array( 'bnomei/kirby-mongodb' => array( - 'pretty_version' => '1.4.3', - 'version' => '1.4.3.0', + 'pretty_version' => '1.4.4', + 'version' => '1.4.4.0', 'reference' => null, 'type' => 'kirby-plugin', 'install_path' => __DIR__ . '/../../',