Skip to content

Commit 7b2ac14

Browse files
committed
Add coverage
1 parent 1af0c62 commit 7b2ac14

7 files changed

Lines changed: 137 additions & 13 deletions

File tree

.github/workflows/run-tests.yml

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,23 +52,26 @@ jobs:
5252
uses: actions/cache@v4
5353
with:
5454
path: vendor
55-
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
55+
key: ${{ runner.os }}-composer-${{ matrix.php }}-${{ matrix.laravel }}-${{ matrix.filament }}-${{ matrix.testbench }}-${{ matrix.livewire }}-${{ hashFiles('**/composer.lock') }}
5656
restore-keys: |
57+
${{ runner.os }}-composer-${{ matrix.php }}-${{ matrix.laravel }}-${{ matrix.filament }}-${{ matrix.testbench }}-${{ matrix.livewire }}-
5758
${{ runner.os }}-composer-
5859
5960
- name: Setup PHP
6061
uses: shivammathur/setup-php@v2
6162
with:
6263
php-version: ${{ matrix.php }}
63-
extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv, imagick, fileinfo
64-
coverage: none
64+
extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv, imagick, fileinfo, pcov
65+
coverage: pcov
6566

6667
- name: Setup problem matchers
6768
run: |
6869
echo "::add-matcher::${{ runner.tool_cache }}/php.json"
6970
echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"
7071
7172
- name: Install dependencies
73+
env:
74+
XDEBUG_MODE: off
7275
run: |
7376
composer require \
7477
"laravel/framework:${{ matrix.laravel }}" \
@@ -78,5 +81,15 @@ jobs:
7881
--no-interaction --no-update --no-progress --ansi
7982
composer update --prefer-stable --prefer-dist --no-interaction --no-progress --ansi
8083
81-
- name: Execute tests
82-
run: vendor/bin/pest
84+
- name: Prepare coverage directory
85+
run: mkdir -p build/logs
86+
87+
- name: Execute tests with coverage
88+
run: vendor/bin/pest --coverage --coverage-clover build/logs/clover.xml
89+
90+
- name: Upload coverage artifact
91+
uses: actions/upload-artifact@v4
92+
with:
93+
name: coverage-${{ matrix.php }}-${{ matrix.laravel }}-${{ matrix.filament }}
94+
path: build/logs/clover.xml
95+
if-no-files-found: error

composer.json

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,14 @@
2929
"require-dev": {
3030
"larastan/larastan": "^3.0",
3131
"laravel/pint": "^1.0",
32-
"orchestra/testbench": "*",
32+
"orchestra/testbench": "^9.0 || ^10.0",
3333
"pestphp/pest": "^3.7 || ^4.0",
34-
"pestphp/pest-plugin-arch": "*",
35-
"pestphp/pest-plugin-laravel": "*",
36-
"pestphp/pest-plugin-livewire": "*",
37-
"phpstan/extension-installer": "*",
38-
"phpstan/phpstan-deprecation-rules": "*",
39-
"phpstan/phpstan-phpunit": "*"
34+
"pestphp/pest-plugin-arch": "^1.0",
35+
"pestphp/pest-plugin-laravel": "^3.0 || ^4.0",
36+
"pestphp/pest-plugin-livewire": "^3.0 || ^4.0",
37+
"phpstan/extension-installer": "^1.3",
38+
"phpstan/phpstan-deprecation-rules": "^1.1",
39+
"phpstan/phpstan-phpunit": "^1.4"
4040
},
4141
"autoload": {
4242
"psr-4": {
@@ -53,6 +53,7 @@
5353
"analyse": "phpstan analyse",
5454
"lint": "pint",
5555
"test": "pest",
56+
"test:coverage": "pest --coverage",
5657
"test:lint": "pint --test"
5758
},
5859
"config": {

tests/Integration/CommandTest.php

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<?php
2+
3+
use CmsMulti\FilamentClearCache\Facades\FilamentClearCache;
4+
use CmsMulti\FilamentClearCache\Commands\FilamentClearCacheCommand;
5+
use Illuminate\Support\Facades\Artisan;
6+
use Illuminate\Support\Facades\Cache;
7+
8+
it('runs default commands from config', function () {
9+
config()->set('filament-clear-cache.default_commands', [
10+
'config:clear',
11+
'cache:clear',
12+
]);
13+
14+
$exitCode = Artisan::call(FilamentClearCacheCommand::class);
15+
16+
expect($exitCode)->toBe(0);
17+
});
18+
19+
it('runs custom string commands added via facade', function () {
20+
FilamentClearCache::addCommand('route:clear');
21+
22+
$exitCode = Artisan::call(FilamentClearCacheCommand::class);
23+
24+
expect($exitCode)->toBe(0);
25+
});
26+
27+
it('runs custom array command with parameters', function () {
28+
FilamentClearCache::addCommand('config:cache', ['--no-ansi' => true]);
29+
30+
$exitCode = Artisan::call(FilamentClearCacheCommand::class);
31+
32+
expect($exitCode)->toBe(0);
33+
});
34+
35+
it('runs custom closure command', function () {
36+
$ran = false;
37+
FilamentClearCache::addCommand(function () use (&$ran) {
38+
$ran = true;
39+
});
40+
41+
$exitCode = Artisan::call(FilamentClearCacheCommand::class);
42+
43+
expect($exitCode)->toBe(0);
44+
expect($ran)->toBeTrue();
45+
});
46+
47+
it('resets changes_count cache key when configured', function () {
48+
$key = 'filament_clear_cache_changes';
49+
config()->set('filament-clear-cache.changes_count', $key);
50+
Cache::put($key, 5);
51+
52+
Artisan::call(FilamentClearCacheCommand::class);
53+
54+
expect(Cache::get($key))->toBe(0);
55+
});

tests/TestCase.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,11 @@ protected function getPackageProviders($app)
2828
return [
2929
BladeHeroiconsServiceProvider::class,
3030
BladeIconsServiceProvider::class,
31-
LivewireServiceProvider::class,
3231
FilamentServiceProvider::class,
3332
NotificationsServiceProvider::class,
3433
SupportServiceProvider::class,
3534
FilamentClearCacheServiceProvider::class,
35+
LivewireServiceProvider::class,
3636
AdminPanelProvider::class,
3737
];
3838
}
@@ -52,6 +52,9 @@ protected function setUpDatabase($app)
5252
$table->string('name');
5353
});
5454

55+
// Cache array
56+
$app['cache']->set('cache.default', 'array');
57+
5558
// self::$migration->up();
5659
}
5760
}

tests/Unit/FacadeTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
use CmsMulti\FilamentClearCache\Facades\FilamentClearCache;
4+
5+
it('facade adds commands and exposes them', function () {
6+
FilamentClearCache::addCommand('view:clear');
7+
FilamentClearCache::addCommand('config:cache', ['--force' => true]);
8+
9+
$commands = FilamentClearCache::getCommands();
10+
11+
expect($commands)
12+
->toHaveCount(2)
13+
->toContain('view:clear');
14+
expect($commands[1])
15+
->toBe(['config:cache', ['--force' => true]]);
16+
});
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
3+
use CmsMulti\FilamentClearCache\FilamentClearCacheManager;
4+
5+
it('adds string command', function () {
6+
$manager = new FilamentClearCacheManager();
7+
$manager->addCommand('cache:clear');
8+
9+
expect($manager->getCommands())
10+
->toHaveCount(1)
11+
->toContain('cache:clear');
12+
});
13+
14+
it('adds array command with params', function () {
15+
$manager = new FilamentClearCacheManager();
16+
$manager->addCommand('config:cache', ['--force' => true]);
17+
18+
expect($manager->getCommands()[0])
19+
->toBe(['config:cache', ['--force' => true]]);
20+
});
21+
22+
it('adds closure command', function () {
23+
$manager = new FilamentClearCacheManager();
24+
$ran = false;
25+
$manager->addCommand(function () use (&$ran) {
26+
$ran = true;
27+
});
28+
29+
$commands = $manager->getCommands();
30+
expect($commands)->toHaveCount(1);
31+
// Invoke the closure to ensure it's callable
32+
$closure = $commands[0];
33+
expect(is_callable($closure))->toBeTrue();
34+
$closure();
35+
expect($ran)->toBeTrue();
36+
});

0 commit comments

Comments
 (0)