Skip to content

Commit e00ca50

Browse files
committed
test: add tests for other types of parent disks
1 parent 435da50 commit e00ca50

File tree

3 files changed

+69
-3
lines changed

3 files changed

+69
-3
lines changed

composer.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
},
2727
"require-dev": {
2828
"friendsofphp/php-cs-fixer": "^3.0",
29+
"league/flysystem-ftp": "^3.0",
30+
"league/flysystem-path-prefixing": "^3.0",
2931
"orchestra/testbench": "^10.0",
3032
"phpunit/phpunit": "^11.5",
3133
"symfony/console": "^7.3.3"

tests/Unit/FilesystemTest.php

Lines changed: 66 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,87 @@
33
namespace Swis\Laravel\Encrypted\Tests\Unit;
44

55
use Illuminate\Support\Facades\Storage;
6+
use League\Flysystem\Ftp\FtpAdapter;
67
use Orchestra\Testbench\Attributes\DefineEnvironment;
78
use PHPUnit\Framework\Attributes\Test;
89
use Swis\Laravel\Encrypted\Tests\TestCase;
910

1011
final class FilesystemTest extends TestCase
1112
{
12-
protected function usesEncryptedDisk($app): void
13+
protected function hasEncryptedInlineDisk($app): void
1314
{
1415
$app['config']->set('filesystems.default', 'local');
1516
$app['config']->set('filesystems.disks.local', ['driver' => 'encrypted', 'disk' => ['driver' => 'local', 'root' => dirname(__DIR__).'/_files/']]);
1617
}
1718

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+
1853
#[Test]
19-
#[DefineEnvironment('usesEncryptedDisk')]
20-
public function itRegistersTheFilesystemDriver(): void
54+
#[DefineEnvironment('hasEncryptedReferencedDisk')]
55+
public function itRegistersTheFilesystemDriverWithReferencedDisk(): void
2156
{
2257
$contents = Storage::get('read.txt');
2358

2459
$this->assertSame('YSvdOxSZ8pyTdDWeN8qI', $contents);
2560
}
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+
}
2689
}

tests/_files/prefix/read.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
eyJpdiI6IllsYmJDQTdlaXBiaVc4K1NXQ0w4M0E9PSIsInZhbHVlIjoiS2k2YVJqcHZ5eEh5MEFoTmE2bXJ1TXlFeTE1dE1jb0psN2tTWU9LWW9VZz0iLCJtYWMiOiJlNWJkYzAwNTJkZjY0Y2M4MTMxNzg1OTcxNzU5YTM0MmI1YWIxNWZiZjA1OGRmZjQwOTVkNWY1OTNlMzdlZmEwIiwidGFnIjoiIn0=

0 commit comments

Comments
 (0)