Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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.*
Expand All @@ -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 }}
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ composer.lock

# PHP Unit
.phpunit.result.cache
.phpunit.cache

# Assets
/tmp
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
![Downloads](https://img.shields.io/packagist/dt/swiftmade/statamic-clear-assets?style=for-the-badge)



> Supports Statamic 3, 4 and 5.

Clean up unused images and assets from your Statamic site. Saves storage, keep things tidy.
Expand Down
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
18 changes: 9 additions & 9 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" bootstrap="vendor/autoload.php" backupGlobals="false" backupStaticAttributes="false" cacheResult="true" colors="true" verbose="true" convertErrorsToExceptions="true" convertNoticesToExceptions="true" convertWarningsToExceptions="true" processIsolation="false" stopOnFailure="false" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
<coverage>
<include>
<directory suffix=".php">src/</directory>
</include>
</coverage>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" bootstrap="vendor/autoload.php" backupGlobals="false" cacheResult="true" colors="true" processIsolation="false" stopOnFailure="false" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/11.5/phpunit.xsd" cacheDirectory=".phpunit.cache" backupStaticProperties="false">
<testsuites>
<testsuite name="Swiftmade Test Suite">
<directory>tests</directory>
</testsuite>
</testsuites>
<php>
<env name="APP_ENV" value="testing"/>
<env name="DB_CONNECTION" value="sqlite" />
<env name="DB_DATABASE" value=":memory:" />
<env name="DB_CONNECTION" value="sqlite"/>
<env name="DB_DATABASE" value=":memory:"/>
<env name="BCRYPT_ROUNDS" value="4"/>
<env name="CACHE_DRIVER" value="array"/>
<env name="SESSION_DRIVER" value="array"/>
<env name="QUEUE_DRIVER" value="sync"/>
<env name="MAIL_DRIVER" value="array"/>
</php>
</phpunit>
<source>
<include>
<directory suffix=".php">src/</directory>
</include>
</source>
</phpunit>
23 changes: 23 additions & 0 deletions phpunit.xml.old
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" bootstrap="vendor/autoload.php" backupGlobals="false" backupStaticAttributes="false" cacheResult="true" colors="true" verbose="true" convertErrorsToExceptions="true" convertNoticesToExceptions="true" convertWarningsToExceptions="true" processIsolation="false" stopOnFailure="false" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
<coverage>
<include>
<directory suffix=".php">src/</directory>
</include>
</coverage>
<testsuites>
<testsuite name="Swiftmade Test Suite">
<directory>tests</directory>
</testsuite>
</testsuites>
<php>
<env name="APP_ENV" value="testing"/>
<env name="DB_CONNECTION" value="sqlite" />
<env name="DB_DATABASE" value=":memory:" />
<env name="BCRYPT_ROUNDS" value="4"/>
<env name="CACHE_DRIVER" value="array"/>
<env name="SESSION_DRIVER" value="array"/>
<env name="QUEUE_DRIVER" value="sync"/>
<env name="MAIL_DRIVER" value="array"/>
</php>
</phpunit>
5 changes: 3 additions & 2 deletions src/ClearAssets.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,15 +87,15 @@ 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) {
return false;
}

// 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;
}
Expand Down Expand Up @@ -138,6 +138,7 @@ private function presentChoices()
{
if ($this->isForced) {
$this->choice = self::CMD_DELETE_ALL;

return;
}

Expand Down
11 changes: 11 additions & 0 deletions src/ServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
]);
Expand Down
3 changes: 2 additions & 1 deletion tests/ClearAssetsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand Down Expand Up @@ -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(
Expand Down
15 changes: 11 additions & 4 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -118,7 +125,7 @@ protected function resolveApplicationConfiguration($app)

protected function initializeDirectory($directory)
{
if (!file_exists($directory)) {
if (! file_exists($directory)) {
mkdir($directory);
}
}
Expand Down