Skip to content

Commit

Permalink
Add conditionable traits to Filesystem adapters (#43450)
Browse files Browse the repository at this point in the history
  • Loading branch information
ralphjsmit committed Jul 29, 2022
1 parent 83c425b commit cb3ec66
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/Illuminate/Filesystem/AwsS3V3Adapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@
namespace Illuminate\Filesystem;

use Aws\S3\S3Client;
use Illuminate\Support\Traits\Conditionable;
use League\Flysystem\AwsS3V3\AwsS3V3Adapter as S3Adapter;
use League\Flysystem\FilesystemOperator;

class AwsS3V3Adapter extends FilesystemAdapter
{
use Conditionable;

/**
* The AWS S3 client.
*
Expand Down
2 changes: 2 additions & 0 deletions src/Illuminate/Filesystem/Filesystem.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use FilesystemIterator;
use Illuminate\Contracts\Filesystem\FileNotFoundException;
use Illuminate\Support\LazyCollection;
use Illuminate\Support\Traits\Conditionable;
use Illuminate\Support\Traits\Macroable;
use RuntimeException;
use SplFileObject;
Expand All @@ -15,6 +16,7 @@

class Filesystem
{
use Conditionable;
use Macroable;

/**
Expand Down
2 changes: 2 additions & 0 deletions src/Illuminate/Filesystem/FilesystemAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Illuminate\Http\UploadedFile;
use Illuminate\Support\Arr;
use Illuminate\Support\Str;
use Illuminate\Support\Traits\Conditionable;
use Illuminate\Support\Traits\Macroable;
use InvalidArgumentException;
use League\Flysystem\FilesystemAdapter as FlysystemAdapter;
Expand Down Expand Up @@ -38,6 +39,7 @@
*/
class FilesystemAdapter implements CloudFilesystemContract
{
use Conditionable;
use Macroable {
__call as macroCall;
}
Expand Down
16 changes: 16 additions & 0 deletions tests/Integration/Filesystem/StorageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,20 @@ public function testItCanDeleteViaFilesystemRequiresManualClearStatCacheOnStorag
Storage::disk('public')->assertMissing('StardewTaylor.png');
$this->assertFalse(Storage::disk('public')->exists('StardewTaylor.png'));
}

public function testConditionable()
{
Storage::disk('public')->assertExists('StardewTaylor.png');
$this->assertTrue(Storage::disk('public')->exists('StardewTaylor.png'));

Storage::disk('public')->when(false)->delete('StardewTaylor.png');

Storage::disk('public')->assertExists('StardewTaylor.png');
$this->assertTrue(Storage::disk('public')->exists('StardewTaylor.png'));

Storage::disk('public')->when(true)->delete('StardewTaylor.png');

Storage::disk('public')->assertMissing('StardewTaylor.png');
$this->assertFalse(Storage::disk('public')->exists('StardewTaylor.png'));
}
}

0 comments on commit cb3ec66

Please sign in to comment.