From 2afb4f53c56019c5bccccf280418cb707c87a406 Mon Sep 17 00:00:00 2001 From: Ben Date: Tue, 27 Jan 2026 07:00:30 +0000 Subject: [PATCH 1/7] Update .gitignore to include .phpunit.cache and adjust .DS_Store entry --- .gitignore | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 8271e65..12d978a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ -.DS_Store +**/.DS_Store .idea .phpunit.result.cache +.phpunit.cache .vscode build composer.lock From 8ee616d22b7e46d39f46ede7782eb4a48f3a7d9f Mon Sep 17 00:00:00 2001 From: Ben Date: Tue, 27 Jan 2026 07:00:36 +0000 Subject: [PATCH 2/7] Refactor clear cache button and update dependencies for compatibility with Filament 4.x --- README.md | 12 ++-- composer.json | 43 ++++++------- phpstan-baseline.neon | 0 phpstan.neon.dist | 4 +- .../livewire/clear-cache-button.blade.php | 64 +++++++++++-------- src/FilamentClearCachePlugin.php | 2 +- tests/ExampleTest.php | 6 +- tests/TestCase.php | 13 +--- 8 files changed, 72 insertions(+), 72 deletions(-) delete mode 100644 phpstan-baseline.neon diff --git a/README.md b/README.md index c81d6ae..5756e70 100644 --- a/README.md +++ b/README.md @@ -12,10 +12,12 @@ Add a button to easily clear the cache from your filament admin. #### Compatibility -| Plugin Version | Filament Version | PHP Version | -|----------------|-----------------|-------------| -| [1.x](https://github.com/cms-multi/filament-clear-cache/tree/1.x) | 2.x | \> 8.0 | -| [2.x](https://github.com/cms-multi/filament-clear-cache/tree/2.x) | 3.x | \> 8.1 | +| Plugin Version | Filament Version | PHP Version | +|-------------------------------------------------------------------|------------------|-------------| +| [1.x](https://github.com/cms-multi/filament-clear-cache/tree/1.x) | 2.x | \> 8.0 | +| [2.x](https://github.com/cms-multi/filament-clear-cache/tree/2.x) | 3.x | \> 8.1 | +| [3.x](https://github.com/cms-multi/filament-clear-cache/tree/3.x) | 4.x + 5.x | \> 8.2 | + ## Installation @@ -67,7 +69,7 @@ To increment the button count call Livewire event `clearCacheIncrement`. // Livewire v2 $this->emit('clearCacheIncrement'); -// Livewire v3 +// Livewire v3+ $this->dispatch('clearCacheIncrement')->to(\CmsMulti\FilamentClearCache\Http\Livewire\ClearCache::class); ``` diff --git a/composer.json b/composer.json index 5af8bd3..7511fac 100644 --- a/composer.json +++ b/composer.json @@ -2,9 +2,9 @@ "name": "cms-multi/filament-clear-cache", "description": "Clear your cache easily from within filament", "keywords": [ - "filament", - "laravel", - "filament-clear-cache" + "filament-clear-cache", + "filamentphp", + "laravel" ], "homepage": "https://github.com/cms-multi/filament-clear-cache", "support": { @@ -20,25 +20,23 @@ } ], "require": { - "php": "^8.1", - "filament/filament": "^3.0", - "filament/notifications": "^3.0", - "spatie/laravel-package-tools": "^1.15.0", - "illuminate/contracts": "^10.0|^11.0|^12.0" + "php": "^8.2", + "filament/filament": "^4.0", + "filament/notifications": "^4.0", + "spatie/laravel-package-tools": "^1.15", + "illuminate/contracts": "^11.0 || ^12.0" }, "require-dev": { + "larastan/larastan": "^2.0 || ^3.0", "laravel/pint": "^1.0", - "nunomaduro/collision": "^7.9", - "nunomaduro/larastan": "^2.0.1", - "orchestra/testbench": "^8.0", - "pestphp/pest": "^2.0", - "pestphp/pest-plugin-arch": "^2.0", - "pestphp/pest-plugin-laravel": "^2.0", - "pestphp/pest-plugin-livewire": "^2.1", + "orchestra/testbench": "^8.0 || ^9.0 || ^10.0", + "pestphp/pest": "^2.0 || ^3.7 || ^4.0", + "pestphp/pest-plugin-arch": "^2.0 || ^3.0 || ^4.0", + "pestphp/pest-plugin-laravel": "^2.0 || ^3.1 || ^4.0", + "pestphp/pest-plugin-livewire": "^3.0 || ^4.0", "phpstan/extension-installer": "^1.1", - "phpstan/phpstan-deprecation-rules": "^1.0", - "phpstan/phpstan-phpunit": "^1.0", - "spatie/laravel-ray": "^1.26" + "phpstan/phpstan-deprecation-rules": "^1.0 || ^2.0", + "phpstan/phpstan-phpunit": "^1.0 || ^2.0" }, "autoload": { "psr-4": { @@ -52,14 +50,15 @@ }, "scripts": { "post-autoload-dump": "@php ./vendor/bin/testbench package:discover --ansi", - "analyse": "vendor/bin/phpstan analyse", - "test": "vendor/bin/pest", - "test-coverage": "vendor/bin/pest --coverage", - "format": "vendor/bin/pint" + "analyse": "phpstan analyse", + "lint": "pint", + "test": "pest", + "test:lint": "pint --test" }, "config": { "sort-packages": true, "allow-plugins": { + "composer/package-versions-deprecated": true, "pestphp/pest-plugin": true, "phpstan/extension-installer": true } diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon deleted file mode 100644 index e69de29..0000000 diff --git a/phpstan.neon.dist b/phpstan.neon.dist index 9914a5e..ee9af8a 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -1,10 +1,8 @@ -includes: - - phpstan-baseline.neon - parameters: level: 4 paths: - src + - config tmpDir: build/phpstan checkOctaneCompatibility: true checkModelProperties: true diff --git a/resources/views/livewire/clear-cache-button.blade.php b/resources/views/livewire/clear-cache-button.blade.php index 155492c..aa54184 100644 --- a/resources/views/livewire/clear-cache-button.blade.php +++ b/resources/views/livewire/clear-cache-button.blade.php @@ -1,31 +1,39 @@ - + diff --git a/src/FilamentClearCachePlugin.php b/src/FilamentClearCachePlugin.php index bb33671..7460b46 100644 --- a/src/FilamentClearCachePlugin.php +++ b/src/FilamentClearCachePlugin.php @@ -14,7 +14,7 @@ class FilamentClearCachePlugin implements Plugin const ID = 'filament-clear-cache'; - const VERSION = '2.0.8'; + const VERSION = '3.0.0'; public static function make(): static { diff --git a/tests/ExampleTest.php b/tests/ExampleTest.php index 1037663..e641e51 100644 --- a/tests/ExampleTest.php +++ b/tests/ExampleTest.php @@ -2,6 +2,7 @@ use CmsMulti\FilamentClearCache\Http\Livewire\ClearCache; +use CmsMulti\FilamentClearCache\Tests\Models\User; use function Pest\Livewire\livewire; it('throws exception clearing cache without auth', function () { @@ -10,7 +11,10 @@ })->throws(Exception::class); it('can clear cache with auth', function () { - $this->actingAs($this->adminUser); + $this->actingAs(User::create([ + 'name' => 'John', + 'email' => 'test@test.com', + ])); livewire(ClearCache::class) ->call('clear') diff --git a/tests/TestCase.php b/tests/TestCase.php index 23ce2a6..864ef3d 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -16,25 +16,16 @@ class TestCase extends Orchestra { - protected User $adminUser; - protected function setUp(): void { parent::setUp(); $this->setUpDatabase($this->app); - - $this->adminUser = User::create([ - 'name' => 'John', - 'email' => 'test@test.com', - ]); - - $this->actingAs($this->adminUser); } protected function getPackageProviders($app) { - $packageProviders = [ + return [ BladeHeroiconsServiceProvider::class, BladeIconsServiceProvider::class, LivewireServiceProvider::class, @@ -44,8 +35,6 @@ protected function getPackageProviders($app) FilamentClearCacheServiceProvider::class, AdminPanelProvider::class, ]; - - return $packageProviders; } /** From 44fe41f37595b791aefe02db4fa3e1ecb0c9ba66 Mon Sep 17 00:00:00 2001 From: Ben Date: Tue, 27 Jan 2026 07:11:20 +0000 Subject: [PATCH 3/7] Update composer.json for Filament 5.x compatibility and expand PHP version matrix in run-tests.yml --- .github/workflows/run-tests.yml | 33 ++++++++++++++++-- .github/workflows/run-tests.yml.bak | 54 +++++++++++++++++++++++++++++ composer.json | 4 +-- 3 files changed, 86 insertions(+), 5 deletions(-) create mode 100644 .github/workflows/run-tests.yml.bak diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index a9f101b..a40405c 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -13,19 +13,35 @@ jobs: fail-fast: true matrix: os: [ubuntu-latest] - php: [8.1, 8.2] + php: [8.1, 8.2, 8.3, 8.4, 8.5] laravel: [10.*, 11.*, 12.*] + filament: [4.*, 5.*] stability: [prefer-stable] include: - laravel: 10.* testbench: 8.* php: 8.1 + filament: 4.* - laravel: 11.* testbench: 9.* php: 8.2 + filament: 4.* - laravel: 12.* testbench: 10.* php: 8.2 + filament: 5.* + - laravel: 12.* + testbench: 10.* + php: 8.3 + filament: 5.* + - laravel: 12.* + testbench: 10.* + php: 8.4 + filament: 5.* + - laravel: 12.* + testbench: 10.* + php: 8.5 + filament: 5.* name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.stability }} - ${{ matrix.os }} @@ -33,6 +49,17 @@ jobs: - name: Checkout code uses: actions/checkout@v4 + - name: Validate composer.json and composer.lock + run: composer validate --strict + + - name: Cache Composer dependencies + uses: actions/cache@v4 + with: + path: vendor + key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }} + restore-keys: | + ${{ runner.os }}-composer- + - name: Setup PHP uses: shivammathur/setup-php@v2 with: @@ -47,8 +74,8 @@ jobs: - name: Install dependencies run: | - composer require "laravel/framework:${{ matrix.laravel }}" "orchestra/testbench:${{ matrix.testbench }}" --no-interaction --no-update - composer update --${{ matrix.stability }} --prefer-dist --no-interaction + composer require "laravel/framework:${{ matrix.laravel }}" "orchestra/testbench:${{ matrix.testbench }}" "filament/filament:${{ matrix.filament }}" --no-interaction --no-update --no-progress --ansi + composer update --${{ matrix.stability }} --prefer-dist --no-interaction --no-progress --ansi - name: Execute tests run: vendor/bin/pest diff --git a/.github/workflows/run-tests.yml.bak b/.github/workflows/run-tests.yml.bak new file mode 100644 index 0000000..a9f101b --- /dev/null +++ b/.github/workflows/run-tests.yml.bak @@ -0,0 +1,54 @@ +name: run-tests + +on: + push: + branches: [main] + pull_request: + branches: [main] + +jobs: + test: + runs-on: ${{ matrix.os }} + strategy: + fail-fast: true + matrix: + os: [ubuntu-latest] + php: [8.1, 8.2] + laravel: [10.*, 11.*, 12.*] + stability: [prefer-stable] + include: + - laravel: 10.* + testbench: 8.* + php: 8.1 + - laravel: 11.* + testbench: 9.* + php: 8.2 + - laravel: 12.* + testbench: 10.* + php: 8.2 + + name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.stability }} - ${{ matrix.os }} + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php }} + extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv, imagick, fileinfo + coverage: none + + - name: Setup problem matchers + run: | + echo "::add-matcher::${{ runner.tool_cache }}/php.json" + echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json" + + - name: Install dependencies + run: | + composer require "laravel/framework:${{ matrix.laravel }}" "orchestra/testbench:${{ matrix.testbench }}" --no-interaction --no-update + composer update --${{ matrix.stability }} --prefer-dist --no-interaction + + - name: Execute tests + run: vendor/bin/pest diff --git a/composer.json b/composer.json index 7511fac..6a79c46 100644 --- a/composer.json +++ b/composer.json @@ -21,8 +21,8 @@ ], "require": { "php": "^8.2", - "filament/filament": "^4.0", - "filament/notifications": "^4.0", + "filament/filament": "^4.0 || ^5.0", + "filament/notifications": "^4.0 || ^5.0", "spatie/laravel-package-tools": "^1.15", "illuminate/contracts": "^11.0 || ^12.0" }, From 0a1fe06c93c8b8aa86bc583bbafb85224a88902c Mon Sep 17 00:00:00 2001 From: Ben Date: Tue, 27 Jan 2026 07:54:46 +0000 Subject: [PATCH 4/7] Fix component registration for livewire v4 --- src/FilamentClearCachePlugin.php | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/src/FilamentClearCachePlugin.php b/src/FilamentClearCachePlugin.php index 7460b46..0132583 100644 --- a/src/FilamentClearCachePlugin.php +++ b/src/FilamentClearCachePlugin.php @@ -7,6 +7,8 @@ use Filament\Panel; use Illuminate\Support\Facades\Blade; use Livewire\Livewire; +use Composer\InstalledVersions; + class FilamentClearCachePlugin implements Plugin { @@ -28,19 +30,35 @@ public function getId(): string public function register(Panel $panel): void { - Livewire::component( - 'filament-clear-cache::clear-cache-button', - config('filament-clear-cache.livewireComponentClass', ClearCache::class) - ); + $component = config('filament-clear-cache.livewireComponentClass', ClearCache::class); + + if (self::isLivewireV3()) { + Livewire::component('filament-clear-cache::clear-cache-button', $component); + } $panel->renderHook( name: 'panels::user-menu.before', - hook: fn (): string => Blade::render('@livewire(\'filament-clear-cache::clear-cache-button\')'), + hook: fn (): string => Blade::render( + '@livewire($component)' + ,['component' => $component] + ), ); } public function boot(Panel $panel): void { - // + if (! self::isLivewireV3()) { + Livewire::addNamespace( + namespace: 'filament-clear-cache', + viewPath: __DIR__ . '/../resources/views/livewire', + ); + } + } + + private static function isLivewireV3(): bool + { + $version = InstalledVersions::getVersion('livewire/livewire'); + + return version_compare($version, '4.0.0', '<'); } } From 0541d3fd4be20ed2e6b5b051907736c4a05a0077 Mon Sep 17 00:00:00 2001 From: Ben Date: Tue, 27 Jan 2026 07:57:56 +0000 Subject: [PATCH 5/7] Fix missing orchestra/testbench --- .github/workflows/run-tests.yml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index a40405c..5ef3864 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -16,6 +16,7 @@ jobs: php: [8.1, 8.2, 8.3, 8.4, 8.5] laravel: [10.*, 11.*, 12.*] filament: [4.*, 5.*] + testbench: [none] stability: [prefer-stable] include: - laravel: 10.* @@ -74,7 +75,11 @@ jobs: - name: Install dependencies run: | - composer require "laravel/framework:${{ matrix.laravel }}" "orchestra/testbench:${{ matrix.testbench }}" "filament/filament:${{ matrix.filament }}" --no-interaction --no-update --no-progress --ansi + if [ "${{ matrix.testbench }}" != "none" ]; then \ + composer require "laravel/framework:${{ matrix.laravel }}" "orchestra/testbench:${{ matrix.testbench }}" "filament/filament:${{ matrix.filament }}" --no-interaction --no-update --no-progress --ansi; \ + else \ + composer require "laravel/framework:${{ matrix.laravel }}" "filament/filament:${{ matrix.filament }}" --no-interaction --no-update --no-progress --ansi; \ + fi composer update --${{ matrix.stability }} --prefer-dist --no-interaction --no-progress --ansi - name: Execute tests From b6c68e68d738f886cbe43c721258f7d1c98f5900 Mon Sep 17 00:00:00 2001 From: howdu <533658+howdu@users.noreply.github.com> Date: Tue, 27 Jan 2026 07:55:06 +0000 Subject: [PATCH 6/7] Fix styling Add coverage Simplify tests Fix phpstan --- .github/workflows/phpstan.yml | 20 +++- .github/workflows/run-tests.yml | 99 ++++++++++++------- .github/workflows/run-tests.yml.bak | 54 ---------- composer.json | 14 +-- src/FilamentClearCachePlugin.php | 7 +- .../ClearCacheTest.php} | 2 +- tests/Integration/CommandTest.php | 55 +++++++++++ tests/TestCase.php | 5 +- tests/Unit/FacadeTest.php | 16 +++ tests/Unit/FilamentClearCacheManagerTest.php | 36 +++++++ 10 files changed, 202 insertions(+), 106 deletions(-) delete mode 100644 .github/workflows/run-tests.yml.bak rename tests/{ExampleTest.php => Integration/ClearCacheTest.php} (100%) create mode 100644 tests/Integration/CommandTest.php create mode 100644 tests/Unit/FacadeTest.php create mode 100644 tests/Unit/FilamentClearCacheManagerTest.php diff --git a/.github/workflows/phpstan.yml b/.github/workflows/phpstan.yml index 3855a08..2aba7ad 100644 --- a/.github/workflows/phpstan.yml +++ b/.github/workflows/phpstan.yml @@ -8,19 +8,31 @@ on: jobs: phpstan: - name: phpstan runs-on: ubuntu-latest + name: PHPStan Latest steps: - uses: actions/checkout@v4 - name: Setup PHP uses: shivammathur/setup-php@v2 with: - php-version: '8.1' + php-version: 8.5 coverage: none - - name: Install composer dependencies - uses: ramsey/composer-install@v3 + - name: Install dependencies + env: + XDEBUG_MODE: off + run: | + composer require \ + "laravel/framework:12.*" \ + "orchestra/testbench:10.*" \ + "filament/filament:5.*" \ + "livewire/livewire:^4.0" \ + "pestphp/pest:^4.0" \ + "pestphp/pest-plugin-laravel:^4.0" \ + "pestphp/pest-plugin-livewire:^4.0" \ + --no-interaction --no-update --no-progress --ansi + composer update --prefer-stable --prefer-dist --no-interaction --no-progress --ansi - name: Run PHPStan run: ./vendor/bin/phpstan --error-format=github diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index 5ef3864..f6b1b85 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -8,43 +8,53 @@ on: jobs: test: - runs-on: ${{ matrix.os }} + runs-on: ubuntu-latest strategy: fail-fast: true matrix: - os: [ubuntu-latest] - php: [8.1, 8.2, 8.3, 8.4, 8.5] - laravel: [10.*, 11.*, 12.*] - filament: [4.*, 5.*] - testbench: [none] - stability: [prefer-stable] include: - - laravel: 10.* - testbench: 8.* - php: 8.1 + - php: 8.2 + laravel: 11.* filament: 4.* - - laravel: 11.* testbench: 9.* - php: 8.2 + livewire: ^3.0 + pest: ^3.8 + pest_plugin_laravel: ^3.1 + pest_plugin_livewire: ^3.1 + - php: 8.2 + laravel: 12.* filament: 4.* - - laravel: 12.* testbench: 10.* - php: 8.2 + livewire: ^3.0 + pest: ^3.8 + pest_plugin_laravel: ^3.1 + pest_plugin_livewire: ^3.1 + - php: 8.3 + laravel: 12.* filament: 5.* - - laravel: 12.* testbench: 10.* - php: 8.3 + livewire: ^4.0 + pest: ^4.0 + pest_plugin_laravel: ^4.0 + pest_plugin_livewire: ^4.0 + - php: 8.4 + laravel: 12.* filament: 5.* - - laravel: 12.* testbench: 10.* - php: 8.4 + livewire: ^4.0 + pest: ^4.0 + pest_plugin_laravel: ^4.0 + pest_plugin_livewire: ^4.0 + - php: 8.5 + laravel: 12.* filament: 5.* - - laravel: 12.* testbench: 10.* - php: 8.5 - filament: 5.* + livewire: ^4.0 + pest: ^4.0 + pest_plugin_laravel: ^4.0 + pest_plugin_livewire: ^4.0 - name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.stability }} - ${{ matrix.os }} + name: P${{ matrix.php }} - L${{ matrix.laravel }} steps: - name: Checkout code @@ -57,16 +67,17 @@ jobs: uses: actions/cache@v4 with: path: vendor - key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }} + key: ${{ runner.os }}-composer-${{ matrix.php }}-${{ matrix.laravel }}-${{ matrix.filament }}-${{ matrix.testbench }}-${{ matrix.livewire }}-${{ hashFiles('**/composer.lock') }} restore-keys: | + ${{ runner.os }}-composer-${{ matrix.php }}-${{ matrix.laravel }}-${{ matrix.filament }}-${{ matrix.testbench }}-${{ matrix.livewire }}- ${{ runner.os }}-composer- - name: Setup PHP uses: shivammathur/setup-php@v2 with: php-version: ${{ matrix.php }} - extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv, imagick, fileinfo - coverage: none + extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv, imagick, fileinfo, pcov + coverage: pcov - name: Setup problem matchers run: | @@ -74,13 +85,35 @@ jobs: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json" - name: Install dependencies + env: + XDEBUG_MODE: off + run: | + composer require \ + "laravel/framework:${{ matrix.laravel }}" \ + "orchestra/testbench:${{ matrix.testbench }}" \ + "filament/filament:${{ matrix.filament }}" \ + "livewire/livewire:${{ matrix.livewire }}" \ + "pestphp/pest:${{ matrix.pest }}" \ + "pestphp/pest-plugin-laravel:${{ matrix.pest_plugin_laravel }}" \ + "pestphp/pest-plugin-livewire:${{ matrix.pest_plugin_livewire }}" \ + --no-interaction --no-update --no-progress --ansi + composer update --prefer-stable --prefer-dist --no-interaction --no-progress --ansi + + - name: Prepare coverage directory + run: mkdir -p build/logs + + - name: Execute tests with coverage + run: vendor/bin/pest --coverage --coverage-clover build/logs/clover.xml + + - name: Sanitize artifact name run: | - if [ "${{ matrix.testbench }}" != "none" ]; then \ - composer require "laravel/framework:${{ matrix.laravel }}" "orchestra/testbench:${{ matrix.testbench }}" "filament/filament:${{ matrix.filament }}" --no-interaction --no-update --no-progress --ansi; \ - else \ - composer require "laravel/framework:${{ matrix.laravel }}" "filament/filament:${{ matrix.filament }}" --no-interaction --no-update --no-progress --ansi; \ - fi - composer update --${{ matrix.stability }} --prefer-dist --no-interaction --no-progress --ansi + LARAVEL_SAFE=$(echo "${{ matrix.laravel }}" | tr '*' 'x') + FILAMENT_SAFE=$(echo "${{ matrix.filament }}" | tr '*' 'x') + echo "ARTIFACT_NAME=coverage-${{ matrix.php }}-${LARAVEL_SAFE}-${FILAMENT_SAFE}" >> $GITHUB_ENV - - name: Execute tests - run: vendor/bin/pest + - name: Upload coverage artifact + uses: actions/upload-artifact@v4 + with: + name: ${{ env.ARTIFACT_NAME }} + path: build/logs/clover.xml + if-no-files-found: error diff --git a/.github/workflows/run-tests.yml.bak b/.github/workflows/run-tests.yml.bak deleted file mode 100644 index a9f101b..0000000 --- a/.github/workflows/run-tests.yml.bak +++ /dev/null @@ -1,54 +0,0 @@ -name: run-tests - -on: - push: - branches: [main] - pull_request: - branches: [main] - -jobs: - test: - runs-on: ${{ matrix.os }} - strategy: - fail-fast: true - matrix: - os: [ubuntu-latest] - php: [8.1, 8.2] - laravel: [10.*, 11.*, 12.*] - stability: [prefer-stable] - include: - - laravel: 10.* - testbench: 8.* - php: 8.1 - - laravel: 11.* - testbench: 9.* - php: 8.2 - - laravel: 12.* - testbench: 10.* - php: 8.2 - - name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.stability }} - ${{ matrix.os }} - - steps: - - name: Checkout code - uses: actions/checkout@v4 - - - name: Setup PHP - uses: shivammathur/setup-php@v2 - with: - php-version: ${{ matrix.php }} - extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv, imagick, fileinfo - coverage: none - - - name: Setup problem matchers - run: | - echo "::add-matcher::${{ runner.tool_cache }}/php.json" - echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json" - - - name: Install dependencies - run: | - composer require "laravel/framework:${{ matrix.laravel }}" "orchestra/testbench:${{ matrix.testbench }}" --no-interaction --no-update - composer update --${{ matrix.stability }} --prefer-dist --no-interaction - - - name: Execute tests - run: vendor/bin/pest diff --git a/composer.json b/composer.json index 6a79c46..9c0d071 100644 --- a/composer.json +++ b/composer.json @@ -27,16 +27,11 @@ "illuminate/contracts": "^11.0 || ^12.0" }, "require-dev": { - "larastan/larastan": "^2.0 || ^3.0", "laravel/pint": "^1.0", - "orchestra/testbench": "^8.0 || ^9.0 || ^10.0", - "pestphp/pest": "^2.0 || ^3.7 || ^4.0", - "pestphp/pest-plugin-arch": "^2.0 || ^3.0 || ^4.0", - "pestphp/pest-plugin-laravel": "^2.0 || ^3.1 || ^4.0", - "pestphp/pest-plugin-livewire": "^3.0 || ^4.0", - "phpstan/extension-installer": "^1.1", - "phpstan/phpstan-deprecation-rules": "^1.0 || ^2.0", - "phpstan/phpstan-phpunit": "^1.0 || ^2.0" + "orchestra/testbench": "^9.0 || ^10.0", + "pestphp/pest": "^3.8 || ^4.0", + "pestphp/pest-plugin-laravel": "^3.1 || ^4.0", + "pestphp/pest-plugin-livewire": "^3.1 || ^4.0" }, "autoload": { "psr-4": { @@ -53,6 +48,7 @@ "analyse": "phpstan analyse", "lint": "pint", "test": "pest", + "test:coverage": "pest --coverage", "test:lint": "pint --test" }, "config": { diff --git a/src/FilamentClearCachePlugin.php b/src/FilamentClearCachePlugin.php index 0132583..e7b9f0a 100644 --- a/src/FilamentClearCachePlugin.php +++ b/src/FilamentClearCachePlugin.php @@ -3,12 +3,11 @@ namespace CmsMulti\FilamentClearCache; use CmsMulti\FilamentClearCache\Http\Livewire\ClearCache; +use Composer\InstalledVersions; use Filament\Contracts\Plugin; use Filament\Panel; use Illuminate\Support\Facades\Blade; use Livewire\Livewire; -use Composer\InstalledVersions; - class FilamentClearCachePlugin implements Plugin { @@ -39,8 +38,8 @@ public function register(Panel $panel): void $panel->renderHook( name: 'panels::user-menu.before', hook: fn (): string => Blade::render( - '@livewire($component)' - ,['component' => $component] + '@livewire($component)', + ['component' => $component] ), ); } diff --git a/tests/ExampleTest.php b/tests/Integration/ClearCacheTest.php similarity index 100% rename from tests/ExampleTest.php rename to tests/Integration/ClearCacheTest.php index e641e51..ac667b8 100644 --- a/tests/ExampleTest.php +++ b/tests/Integration/ClearCacheTest.php @@ -1,8 +1,8 @@ set('filament-clear-cache.default_commands', [ + 'config:clear', + 'cache:clear', + ]); + + $exitCode = Artisan::call(FilamentClearCacheCommand::class); + + expect($exitCode)->toBe(0); +}); + +it('runs custom string commands added via facade', function () { + FilamentClearCache::addCommand('route:clear'); + + $exitCode = Artisan::call(FilamentClearCacheCommand::class); + + expect($exitCode)->toBe(0); +}); + +it('runs custom array command with parameters', function () { + FilamentClearCache::addCommand('config:cache', ['--no-ansi' => true]); + + $exitCode = Artisan::call(FilamentClearCacheCommand::class); + + expect($exitCode)->toBe(0); +}); + +it('runs custom closure command', function () { + $ran = false; + FilamentClearCache::addCommand(function () use (&$ran) { + $ran = true; + }); + + $exitCode = Artisan::call(FilamentClearCacheCommand::class); + + expect($exitCode)->toBe(0); + expect($ran)->toBeTrue(); +}); + +it('resets changes_count cache key when configured', function () { + $key = 'filament_clear_cache_changes'; + config()->set('filament-clear-cache.changes_count', $key); + Cache::put($key, 5); + + Artisan::call(FilamentClearCacheCommand::class); + + expect(Cache::get($key))->toBe(0); +}); diff --git a/tests/TestCase.php b/tests/TestCase.php index 864ef3d..af67986 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -28,11 +28,11 @@ protected function getPackageProviders($app) return [ BladeHeroiconsServiceProvider::class, BladeIconsServiceProvider::class, - LivewireServiceProvider::class, FilamentServiceProvider::class, NotificationsServiceProvider::class, SupportServiceProvider::class, FilamentClearCacheServiceProvider::class, + LivewireServiceProvider::class, AdminPanelProvider::class, ]; } @@ -52,6 +52,9 @@ protected function setUpDatabase($app) $table->string('name'); }); + // Cache array + $app['cache']->set('cache.default', 'array'); + // self::$migration->up(); } } diff --git a/tests/Unit/FacadeTest.php b/tests/Unit/FacadeTest.php new file mode 100644 index 0000000..89f1bd1 --- /dev/null +++ b/tests/Unit/FacadeTest.php @@ -0,0 +1,16 @@ + true]); + + $commands = FilamentClearCache::getCommands(); + + expect($commands) + ->toHaveCount(2) + ->toContain('view:clear'); + expect($commands[1]) + ->toBe(['config:cache', ['--force' => true]]); +}); diff --git a/tests/Unit/FilamentClearCacheManagerTest.php b/tests/Unit/FilamentClearCacheManagerTest.php new file mode 100644 index 0000000..fd83599 --- /dev/null +++ b/tests/Unit/FilamentClearCacheManagerTest.php @@ -0,0 +1,36 @@ +addCommand('cache:clear'); + + expect($manager->getCommands()) + ->toHaveCount(1) + ->toContain('cache:clear'); +}); + +it('adds array command with params', function () { + $manager = new FilamentClearCacheManager; + $manager->addCommand('config:cache', ['--force' => true]); + + expect($manager->getCommands()[0]) + ->toBe(['config:cache', ['--force' => true]]); +}); + +it('adds closure command', function () { + $manager = new FilamentClearCacheManager; + $ran = false; + $manager->addCommand(function () use (&$ran) { + $ran = true; + }); + + $commands = $manager->getCommands(); + expect($commands)->toHaveCount(1); + // Invoke the closure to ensure it's callable + $closure = $commands[0]; + expect(is_callable($closure))->toBeTrue(); + $closure(); + expect($ran)->toBeTrue(); +}); From c27be2c7c9c679649c08a8519b2c076a7b9818a0 Mon Sep 17 00:00:00 2001 From: Ben Date: Tue, 27 Jan 2026 19:14:40 +0000 Subject: [PATCH 7/7] Update TestCase.php --- .github/workflows/phpstan.yml | 14 ++------------ composer.json | 13 +++++++++---- phpstan.neon.dist | 1 - tests/TestCase.php | 4 ---- 4 files changed, 11 insertions(+), 21 deletions(-) diff --git a/.github/workflows/phpstan.yml b/.github/workflows/phpstan.yml index 2aba7ad..7963b38 100644 --- a/.github/workflows/phpstan.yml +++ b/.github/workflows/phpstan.yml @@ -22,17 +22,7 @@ jobs: - name: Install dependencies env: XDEBUG_MODE: off - run: | - composer require \ - "laravel/framework:12.*" \ - "orchestra/testbench:10.*" \ - "filament/filament:5.*" \ - "livewire/livewire:^4.0" \ - "pestphp/pest:^4.0" \ - "pestphp/pest-plugin-laravel:^4.0" \ - "pestphp/pest-plugin-livewire:^4.0" \ - --no-interaction --no-update --no-progress --ansi - composer update --prefer-stable --prefer-dist --no-interaction --no-progress --ansi + run: composer update --prefer-stable --prefer-dist --no-interaction --no-progress --ansi - name: Run PHPStan - run: ./vendor/bin/phpstan --error-format=github + run: ./vendor/bin/phpstan analyse -c phpstan.neon.dist --error-format=github diff --git a/composer.json b/composer.json index 9c0d071..5b3feea 100644 --- a/composer.json +++ b/composer.json @@ -28,10 +28,15 @@ }, "require-dev": { "laravel/pint": "^1.0", - "orchestra/testbench": "^9.0 || ^10.0", - "pestphp/pest": "^3.8 || ^4.0", - "pestphp/pest-plugin-laravel": "^3.1 || ^4.0", - "pestphp/pest-plugin-livewire": "^3.1 || ^4.0" + "larastan/larastan": "^3.0", + "orchestra/testbench": "^10.0", + "pestphp/pest": "^4.0", + "pestphp/pest-plugin-laravel": "^4.0", + "pestphp/pest-plugin-livewire": "^4.0", + "phpstan/phpstan": "^2.1", + "phpstan/extension-installer": "^1.4", + "phpstan/phpstan-deprecation-rules": "^2.0", + "phpstan/phpstan-phpunit": "^2.0" }, "autoload": { "psr-4": { diff --git a/phpstan.neon.dist b/phpstan.neon.dist index ee9af8a..6a9db1d 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -6,5 +6,4 @@ parameters: tmpDir: build/phpstan checkOctaneCompatibility: true checkModelProperties: true - checkMissingIterableValueType: false diff --git a/tests/TestCase.php b/tests/TestCase.php index af67986..553ce84 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -2,8 +2,6 @@ namespace CmsMulti\FilamentClearCache\Tests; -use BladeUI\Heroicons\BladeHeroiconsServiceProvider; -use BladeUI\Icons\BladeIconsServiceProvider; use CmsMulti\FilamentClearCache\FilamentClearCacheServiceProvider; use CmsMulti\FilamentClearCache\Tests\Models\User; use CmsMulti\FilamentClearCache\Tests\Provider\AdminPanelProvider; @@ -26,8 +24,6 @@ protected function setUp(): void protected function getPackageProviders($app) { return [ - BladeHeroiconsServiceProvider::class, - BladeIconsServiceProvider::class, FilamentServiceProvider::class, NotificationsServiceProvider::class, SupportServiceProvider::class,