diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml
index e2eb987..54f6d85 100644
--- a/.github/workflows/test.yml
+++ b/.github/workflows/test.yml
@@ -8,7 +8,7 @@ jobs:
fail-fast: true
matrix:
php: [7.4, 8.0, 8.1, 8.2, 8.3]
- laravel: [8.*, 9.*, 10.*, 11.*]
+ laravel: [8.*, 9.*, 10.*, 11.*, 12.*]
statamic: [3.*, 4.*, 5.*]
exclude:
- laravel: 8.*
@@ -34,11 +34,21 @@ jobs:
- laravel: 11.*
php: 8.0
- laravel: 11.*
- php: 8.1
+ php: 8.1
- laravel: 11.*
statamic: 3.*
- laravel: 11.*
statamic: 4.*
+ - laravel: 12.*
+ php: 7.4
+ - laravel: 12.*
+ php: 8.0
+ - laravel: 12.*
+ php: 8.1
+ - laravel: 12.*
+ statamic: 3.*
+ - laravel: 12.*
+ statamic: 4.*
dependency-version: [prefer-stable]
name: P${{ matrix.php }} - L${{ matrix.laravel }} - S${{ matrix.statamic }}
diff --git a/.gitignore b/.gitignore
index 6e91928..8966d1b 100644
--- a/.gitignore
+++ b/.gitignore
@@ -7,6 +7,7 @@ composer.lock
# PHP Unit
.phpunit.result.cache
+.phpunit.cache
# Assets
/tmp
\ No newline at end of file
diff --git a/README.md b/README.md
index 13ffad7..08bde4d 100644
--- a/README.md
+++ b/README.md
@@ -5,6 +5,7 @@

+
> Supports Statamic 3, 4 and 5.
Clean up unused images and assets from your Statamic site. Saves storage, keep things tidy.
diff --git a/composer.json b/composer.json
index e3f1faa..93c6445 100644
--- a/composer.json
+++ b/composer.json
@@ -14,14 +14,14 @@
],
"require": {
"php": "^7.4|^8.0",
- "laravel/framework": "^7.30.3|^8.24|^9.0|^10.0|^11.0",
+ "laravel/framework": "^7.30.3|^8.24|^9.0|^10.0|^11.0|^12.0",
"statamic/cms": "^3.0.0|^4.0|^5.0"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^3.8",
"nunomaduro/collision": "^4.1|^5.0|^6.0|^8.1",
- "orchestra/testbench": "^5.0|^6.0|^7.0|^8.0|^9.0",
- "phpunit/phpunit": "^9.5|^10.0"
+ "orchestra/testbench": "^5.0|^6.0|^7.0|^8.0|^9.0|^10.0|^11.0",
+ "phpunit/phpunit": "^9.5|^10.0|^11.0"
},
"autoload": {
"psr-4": {
diff --git a/phpunit.xml b/phpunit.xml
index f0f7340..118b090 100644
--- a/phpunit.xml
+++ b/phpunit.xml
@@ -1,10 +1,5 @@
-
-
-
- src/
-
-
+
tests
@@ -12,12 +7,17 @@
-
-
+
+
-
\ No newline at end of file
+
+
+ src/
+
+
+
diff --git a/phpunit.xml.old b/phpunit.xml.old
new file mode 100644
index 0000000..f0f7340
--- /dev/null
+++ b/phpunit.xml.old
@@ -0,0 +1,23 @@
+
+
+
+
+ src/
+
+
+
+
+ tests
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/ClearAssets.php b/src/ClearAssets.php
index bf31b9e..808ed5d 100644
--- a/src/ClearAssets.php
+++ b/src/ClearAssets.php
@@ -87,7 +87,7 @@ private function filterUnused(AssetCollection $assets)
// Skip assets that are in the ignored containers.
$shouldIgnore = in_array(
$asset->container()->handle(),
- config('statamic-clear-assets.ignore_containers')
+ config('statamic-clear-assets.ignore_containers', [])
);
if ($shouldIgnore) {
@@ -95,7 +95,7 @@ private function filterUnused(AssetCollection $assets)
}
// Skip assets that match the ignore_filenames.
- foreach (config('statamic-clear-assets.ignore_filenames') as $pattern) {
+ foreach (config('statamic-clear-assets.ignore_filenames', []) as $pattern) {
if (Str::is($pattern, $asset->path())) {
return false;
}
@@ -138,6 +138,7 @@ private function presentChoices()
{
if ($this->isForced) {
$this->choice = self::CMD_DELETE_ALL;
+
return;
}
diff --git a/src/ServiceProvider.php b/src/ServiceProvider.php
index 42e8186..6f494ce 100644
--- a/src/ServiceProvider.php
+++ b/src/ServiceProvider.php
@@ -8,6 +8,17 @@ class ServiceProvider extends AddonServiceProvider
{
public function bootAddon()
{
+ /**
+ * bootConfig() does not get called during unit tests,
+ * so we manually merge the config here.
+ */
+ if (app()->runningUnitTests()) {
+ $this->mergeConfigFrom(
+ __DIR__ . '/../config/statamic-clear-assets.php',
+ 'statamic-clear-assets'
+ );
+ }
+
$this->commands([
ClearAssets::class,
]);
diff --git a/tests/ClearAssetsTest.php b/tests/ClearAssetsTest.php
index 5f7a169..5884dd8 100644
--- a/tests/ClearAssetsTest.php
+++ b/tests/ClearAssetsTest.php
@@ -56,6 +56,7 @@ public function it_can_list_unused_assets()
*/
public function it_ignores_containers()
{
+ // These two assets are in ignored containers by default
$this->createAsset('ankara.jpg', 'social_images');
$this->createAsset('tallinn.jpg', 'favicons');
@@ -127,7 +128,7 @@ public function it_skips_confirmation_in_no_interaction_mode()
private function createAsset($filename, $container = 'assets')
{
- $tmpFile = tempnam(sys_get_temp_dir(), 'test_' . $filename);
+ $tmpFile = tempnam(sys_get_temp_dir(), $filename);
copy(__DIR__ . '/fixtures/' . $filename, $tmpFile);
$file = new UploadedFile(
diff --git a/tests/TestCase.php b/tests/TestCase.php
index 59f49cb..2514d7f 100644
--- a/tests/TestCase.php
+++ b/tests/TestCase.php
@@ -95,15 +95,22 @@ protected function resolveApplicationConfiguration($app)
parent::resolveApplicationConfiguration($app);
$configs = [
- 'assets', 'cp', 'forms', 'routes', 'static_caching',
- 'sites', 'stache', 'system', 'users',
+ 'assets',
+ 'cp',
+ 'forms',
+ 'routes',
+ 'static_caching',
+ 'sites',
+ 'stache',
+ 'system',
+ 'users',
];
foreach ($configs as $config) {
$path = __DIR__ . "/../vendor/statamic/cms/config/{$config}.php";
- if (!file_exists($path)) {
+ if (! file_exists($path)) {
continue;
}
@@ -118,7 +125,7 @@ protected function resolveApplicationConfiguration($app)
protected function initializeDirectory($directory)
{
- if (!file_exists($directory)) {
+ if (! file_exists($directory)) {
mkdir($directory);
}
}