Skip to content

Commit b628456

Browse files
authored
Support Laravel 12.x (#20)
* support testbench 10.x * wip * update * fix tests * apply cs fixer * apply cs fixer
1 parent bcc3c51 commit b628456

File tree

10 files changed

+76
-21
lines changed

10 files changed

+76
-21
lines changed

.github/workflows/test.yml

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ jobs:
88
fail-fast: true
99
matrix:
1010
php: [7.4, 8.0, 8.1, 8.2, 8.3]
11-
laravel: [8.*, 9.*, 10.*, 11.*]
11+
laravel: [8.*, 9.*, 10.*, 11.*, 12.*]
1212
statamic: [3.*, 4.*, 5.*]
1313
exclude:
1414
- laravel: 8.*
@@ -34,11 +34,21 @@ jobs:
3434
- laravel: 11.*
3535
php: 8.0
3636
- laravel: 11.*
37-
php: 8.1
37+
php: 8.1
3838
- laravel: 11.*
3939
statamic: 3.*
4040
- laravel: 11.*
4141
statamic: 4.*
42+
- laravel: 12.*
43+
php: 7.4
44+
- laravel: 12.*
45+
php: 8.0
46+
- laravel: 12.*
47+
php: 8.1
48+
- laravel: 12.*
49+
statamic: 3.*
50+
- laravel: 12.*
51+
statamic: 4.*
4252
dependency-version: [prefer-stable]
4353

4454
name: P${{ matrix.php }} - L${{ matrix.laravel }} - S${{ matrix.statamic }}

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ composer.lock
77

88
# PHP Unit
99
.phpunit.result.cache
10+
.phpunit.cache
1011

1112
# Assets
1213
/tmp

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
![Downloads](https://img.shields.io/packagist/dt/swiftmade/statamic-clear-assets?style=for-the-badge)
66

77

8+
89
> Supports Statamic 3, 4 and 5.
910
1011
Clean up unused images and assets from your Statamic site. Saves storage, keep things tidy.

composer.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@
1414
],
1515
"require": {
1616
"php": "^7.4|^8.0",
17-
"laravel/framework": "^7.30.3|^8.24|^9.0|^10.0|^11.0",
17+
"laravel/framework": "^7.30.3|^8.24|^9.0|^10.0|^11.0|^12.0",
1818
"statamic/cms": "^3.0.0|^4.0|^5.0"
1919
},
2020
"require-dev": {
2121
"friendsofphp/php-cs-fixer": "^3.8",
2222
"nunomaduro/collision": "^4.1|^5.0|^6.0|^8.1",
23-
"orchestra/testbench": "^5.0|^6.0|^7.0|^8.0|^9.0",
24-
"phpunit/phpunit": "^9.5|^10.0"
23+
"orchestra/testbench": "^5.0|^6.0|^7.0|^8.0|^9.0|^10.0|^11.0",
24+
"phpunit/phpunit": "^9.5|^10.0|^11.0"
2525
},
2626
"autoload": {
2727
"psr-4": {

phpunit.xml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<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">
3-
<coverage>
4-
<include>
5-
<directory suffix=".php">src/</directory>
6-
</include>
7-
</coverage>
2+
<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">
83
<testsuites>
94
<testsuite name="Swiftmade Test Suite">
105
<directory>tests</directory>
116
</testsuite>
127
</testsuites>
138
<php>
149
<env name="APP_ENV" value="testing"/>
15-
<env name="DB_CONNECTION" value="sqlite" />
16-
<env name="DB_DATABASE" value=":memory:" />
10+
<env name="DB_CONNECTION" value="sqlite"/>
11+
<env name="DB_DATABASE" value=":memory:"/>
1712
<env name="BCRYPT_ROUNDS" value="4"/>
1813
<env name="CACHE_DRIVER" value="array"/>
1914
<env name="SESSION_DRIVER" value="array"/>
2015
<env name="QUEUE_DRIVER" value="sync"/>
2116
<env name="MAIL_DRIVER" value="array"/>
2217
</php>
23-
</phpunit>
18+
<source>
19+
<include>
20+
<directory suffix=".php">src/</directory>
21+
</include>
22+
</source>
23+
</phpunit>

phpunit.xml.old

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<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">
3+
<coverage>
4+
<include>
5+
<directory suffix=".php">src/</directory>
6+
</include>
7+
</coverage>
8+
<testsuites>
9+
<testsuite name="Swiftmade Test Suite">
10+
<directory>tests</directory>
11+
</testsuite>
12+
</testsuites>
13+
<php>
14+
<env name="APP_ENV" value="testing"/>
15+
<env name="DB_CONNECTION" value="sqlite" />
16+
<env name="DB_DATABASE" value=":memory:" />
17+
<env name="BCRYPT_ROUNDS" value="4"/>
18+
<env name="CACHE_DRIVER" value="array"/>
19+
<env name="SESSION_DRIVER" value="array"/>
20+
<env name="QUEUE_DRIVER" value="sync"/>
21+
<env name="MAIL_DRIVER" value="array"/>
22+
</php>
23+
</phpunit>

src/ClearAssets.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,15 +87,15 @@ private function filterUnused(AssetCollection $assets)
8787
// Skip assets that are in the ignored containers.
8888
$shouldIgnore = in_array(
8989
$asset->container()->handle(),
90-
config('statamic-clear-assets.ignore_containers')
90+
config('statamic-clear-assets.ignore_containers', [])
9191
);
9292

9393
if ($shouldIgnore) {
9494
return false;
9595
}
9696

9797
// Skip assets that match the ignore_filenames.
98-
foreach (config('statamic-clear-assets.ignore_filenames') as $pattern) {
98+
foreach (config('statamic-clear-assets.ignore_filenames', []) as $pattern) {
9999
if (Str::is($pattern, $asset->path())) {
100100
return false;
101101
}
@@ -138,6 +138,7 @@ private function presentChoices()
138138
{
139139
if ($this->isForced) {
140140
$this->choice = self::CMD_DELETE_ALL;
141+
141142
return;
142143
}
143144

src/ServiceProvider.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,17 @@ class ServiceProvider extends AddonServiceProvider
88
{
99
public function bootAddon()
1010
{
11+
/**
12+
* bootConfig() does not get called during unit tests,
13+
* so we manually merge the config here.
14+
*/
15+
if (app()->runningUnitTests()) {
16+
$this->mergeConfigFrom(
17+
__DIR__ . '/../config/statamic-clear-assets.php',
18+
'statamic-clear-assets'
19+
);
20+
}
21+
1122
$this->commands([
1223
ClearAssets::class,
1324
]);

tests/ClearAssetsTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ public function it_can_list_unused_assets()
5656
*/
5757
public function it_ignores_containers()
5858
{
59+
// These two assets are in ignored containers by default
5960
$this->createAsset('ankara.jpg', 'social_images');
6061
$this->createAsset('tallinn.jpg', 'favicons');
6162

@@ -127,7 +128,7 @@ public function it_skips_confirmation_in_no_interaction_mode()
127128

128129
private function createAsset($filename, $container = 'assets')
129130
{
130-
$tmpFile = tempnam(sys_get_temp_dir(), 'test_' . $filename);
131+
$tmpFile = tempnam(sys_get_temp_dir(), $filename);
131132
copy(__DIR__ . '/fixtures/' . $filename, $tmpFile);
132133

133134
$file = new UploadedFile(

tests/TestCase.php

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,15 +95,22 @@ protected function resolveApplicationConfiguration($app)
9595
parent::resolveApplicationConfiguration($app);
9696

9797
$configs = [
98-
'assets', 'cp', 'forms', 'routes', 'static_caching',
99-
'sites', 'stache', 'system', 'users',
98+
'assets',
99+
'cp',
100+
'forms',
101+
'routes',
102+
'static_caching',
103+
'sites',
104+
'stache',
105+
'system',
106+
'users',
100107
];
101108

102109
foreach ($configs as $config) {
103110

104111
$path = __DIR__ . "/../vendor/statamic/cms/config/{$config}.php";
105112

106-
if (!file_exists($path)) {
113+
if (! file_exists($path)) {
107114
continue;
108115
}
109116

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

119126
protected function initializeDirectory($directory)
120127
{
121-
if (!file_exists($directory)) {
128+
if (! file_exists($directory)) {
122129
mkdir($directory);
123130
}
124131
}

0 commit comments

Comments
 (0)