|  | 
| 3 | 3 | namespace Swis\Laravel\Encrypted\Tests\Unit; | 
| 4 | 4 | 
 | 
| 5 | 5 | use Illuminate\Support\Facades\Storage; | 
|  | 6 | +use League\Flysystem\Ftp\FtpAdapter; | 
| 6 | 7 | use Orchestra\Testbench\Attributes\DefineEnvironment; | 
| 7 | 8 | use PHPUnit\Framework\Attributes\Test; | 
| 8 | 9 | use Swis\Laravel\Encrypted\Tests\TestCase; | 
| 9 | 10 | 
 | 
| 10 | 11 | final class FilesystemTest extends TestCase | 
| 11 | 12 | { | 
| 12 |  | -    protected function usesEncryptedDisk($app): void | 
|  | 13 | +    protected function hasEncryptedInlineDisk($app): void | 
| 13 | 14 |     { | 
| 14 | 15 |         $app['config']->set('filesystems.default', 'local'); | 
| 15 | 16 |         $app['config']->set('filesystems.disks.local', ['driver' => 'encrypted', 'disk' => ['driver' => 'local', 'root' => dirname(__DIR__).'/_files/']]); | 
| 16 | 17 |     } | 
| 17 | 18 | 
 | 
|  | 19 | +    protected function hasEncryptedReferencedDisk($app): void | 
|  | 20 | +    { | 
|  | 21 | +        $app['config']->set('filesystems.default', 'local'); | 
|  | 22 | +        $app['config']->set('filesystems.disks.other', ['driver' => 'local', 'root' => dirname(__DIR__).'/_files/']); | 
|  | 23 | +        $app['config']->set('filesystems.disks.local', ['driver' => 'encrypted', 'disk' => 'other']); | 
|  | 24 | +    } | 
|  | 25 | + | 
|  | 26 | +    protected function hasEncryptedFtpDisk($app): void | 
|  | 27 | +    { | 
|  | 28 | +        $app['config']->set('filesystems.default', 'ftp'); | 
|  | 29 | +        $app['config']->set('filesystems.disks.ftp', ['driver' => 'encrypted', 'disk' => ['driver' => 'ftp', 'host' => 'localhost']]); | 
|  | 30 | +    } | 
|  | 31 | + | 
|  | 32 | +    protected function hasEncryptedDiskWithPrefix($app): void | 
|  | 33 | +    { | 
|  | 34 | +        $app['config']->set('filesystems.default', 'local'); | 
|  | 35 | +        $app['config']->set('filesystems.disks.local', ['driver' => 'encrypted', 'disk' => ['driver' => 'local', 'root' => dirname(__DIR__).'/_files/', 'prefix' => 'prefix']]); | 
|  | 36 | +    } | 
|  | 37 | + | 
|  | 38 | +    protected function hasIncorrectEncryptedDisk($app): void | 
|  | 39 | +    { | 
|  | 40 | +        $app['config']->set('filesystems.default', 'local'); | 
|  | 41 | +        $app['config']->set('filesystems.disks.local', ['driver' => 'encrypted']); | 
|  | 42 | +    } | 
|  | 43 | + | 
|  | 44 | +    #[Test] | 
|  | 45 | +    #[DefineEnvironment('hasEncryptedInlineDisk')] | 
|  | 46 | +    public function itRegistersTheFilesystemDriverWithInlineDisk(): void | 
|  | 47 | +    { | 
|  | 48 | +        $contents = Storage::get('read.txt'); | 
|  | 49 | + | 
|  | 50 | +        $this->assertSame('YSvdOxSZ8pyTdDWeN8qI', $contents); | 
|  | 51 | +    } | 
|  | 52 | + | 
| 18 | 53 |     #[Test] | 
| 19 |  | -    #[DefineEnvironment('usesEncryptedDisk')] | 
| 20 |  | -    public function itRegistersTheFilesystemDriver(): void | 
|  | 54 | +    #[DefineEnvironment('hasEncryptedReferencedDisk')] | 
|  | 55 | +    public function itRegistersTheFilesystemDriverWithReferencedDisk(): void | 
| 21 | 56 |     { | 
| 22 | 57 |         $contents = Storage::get('read.txt'); | 
| 23 | 58 | 
 | 
| 24 | 59 |         $this->assertSame('YSvdOxSZ8pyTdDWeN8qI', $contents); | 
| 25 | 60 |     } | 
|  | 61 | + | 
|  | 62 | +    #[Test] | 
|  | 63 | +    #[DefineEnvironment('hasEncryptedFtpDisk')] | 
|  | 64 | +    public function itRegistersTheFilesystemDriverWithFtpDisk(): void | 
|  | 65 | +    { | 
|  | 66 | +        $filesystem = Storage::disk(); | 
|  | 67 | + | 
|  | 68 | +        $this->assertInstanceOf(FtpAdapter::class, $filesystem->getAdapter()); | 
|  | 69 | +    } | 
|  | 70 | + | 
|  | 71 | +    #[Test] | 
|  | 72 | +    #[DefineEnvironment('hasEncryptedDiskWithPrefix')] | 
|  | 73 | +    public function itRegistersTheFilesystemDriverWithPrefixedDisk(): void | 
|  | 74 | +    { | 
|  | 75 | +        $contents = Storage::get('read.txt'); | 
|  | 76 | + | 
|  | 77 | +        $this->assertSame('hi7OJgUQlfk00nd3jmM1', $contents); | 
|  | 78 | +    } | 
|  | 79 | + | 
|  | 80 | +    #[Test] | 
|  | 81 | +    #[DefineEnvironment('hasIncorrectEncryptedDisk')] | 
|  | 82 | +    public function itFailsWhenDiskIsMissing(): void | 
|  | 83 | +    { | 
|  | 84 | +        $this->expectException(\InvalidArgumentException::class); | 
|  | 85 | +        $this->expectExceptionMessage('Encrypted disk is missing "disk" configuration option.'); | 
|  | 86 | + | 
|  | 87 | +        Storage::get('read.txt'); | 
|  | 88 | +    } | 
| 26 | 89 | } | 
0 commit comments