|
1 | 1 | <?php |
2 | 2 |
|
3 | | -test('it will throw an exception if the base directory does not exist', function () { |
| 3 | +use League\Flysystem\Filesystem; |
| 4 | +use League\Flysystem\Local\LocalFilesystemAdapter; |
| 5 | +use Sammyjo20\Saloon\Exceptions\DirectoryNotFoundException; |
| 6 | +use Sammyjo20\Saloon\Helpers\Storage; |
4 | 7 |
|
5 | | -}); |
| 8 | +test('it will throw an exception if the base directory does not exist', function () { |
| 9 | + new Storage('example'); |
| 10 | +})->throws(DirectoryNotFoundException::class, 'The directory "example" does not exist or is not a valid directory.'); |
6 | 11 |
|
7 | 12 | test('you can check if a file exists', function () { |
| 13 | + $storage = new Storage('tests'); |
8 | 14 |
|
| 15 | + expect($storage->exists('Pest.php'))->toBeTrue(); |
| 16 | + expect($storage->missing('Pest.php'))->toBeFalse(); |
9 | 17 | }); |
10 | 18 |
|
11 | 19 | test('you can check if a file is missing', function () { |
| 20 | + $storage = new Storage('tests'); |
12 | 21 |
|
| 22 | + expect($storage->exists('HelloWorld.php'))->toBeFalse(); |
| 23 | + expect($storage->missing('HelloWorld.php'))->toBeTrue(); |
13 | 24 | }); |
14 | 25 |
|
15 | 26 | test('you can retrieve a file from storage', function () { |
| 27 | + $storage = new Storage('tests'); |
16 | 28 |
|
| 29 | + $file = $storage->get('Pest.php'); |
| 30 | + |
| 31 | + expect($file)->toEqual(file_get_contents('tests/Pest.php')); |
17 | 32 | }); |
18 | 33 |
|
19 | 34 | test('you can put a file in storage', function () { |
| 35 | + $filesystem = new Filesystem(new LocalFilesystemAdapter('tests/Fixtures/Saloon')); |
| 36 | + $filesystem->deleteDirectory('/'); |
| 37 | + $filesystem->createDirectory('/'); |
| 38 | + |
| 39 | + $storage = new Storage('tests/Fixtures/Saloon'); |
| 40 | + |
| 41 | + expect($storage->exists('example.txt'))->toBeFalse(); |
20 | 42 |
|
| 43 | + $storage->put('example.txt', 'Hello World'); |
| 44 | + |
| 45 | + expect($storage->exists('example.txt'))->toBeTrue(); |
| 46 | + |
| 47 | + expect($storage->get('example.txt'))->toEqual('Hello World'); |
21 | 48 | }); |
22 | 49 |
|
23 | 50 | test('it will create a file with nested folders', function () { |
| 51 | + $filesystem = new Filesystem(new LocalFilesystemAdapter('tests/Fixtures/Saloon')); |
| 52 | + $filesystem->deleteDirectory('/'); |
| 53 | + $filesystem->createDirectory('/'); |
| 54 | + |
| 55 | + $storage = new Storage('tests/Fixtures/Saloon'); |
| 56 | + |
| 57 | + expect($storage->exists('some/other/directories/example.txt'))->toBeFalse(); |
| 58 | + |
| 59 | + $storage->put('some/other/directories/example.txt', 'Hello World'); |
| 60 | + |
| 61 | + expect($storage->exists('some/other/directories/example.txt'))->toBeTrue(); |
24 | 62 |
|
| 63 | + expect($storage->get('some/other/directories/example.txt'))->toEqual('Hello World'); |
25 | 64 | }); |
0 commit comments