1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Spiral\Tests\Storage; |
6
|
|
|
|
7
|
|
|
use League\Flysystem\Local\LocalFilesystemAdapter; |
8
|
|
|
use PHPUnit\Framework\TestCase as BaseTestCase; |
9
|
|
|
use Spiral\Storage\Bucket; |
10
|
|
|
use Spiral\Storage\BucketInterface; |
11
|
|
|
|
12
|
|
|
class TestCase extends BaseTestCase |
13
|
|
|
{ |
14
|
|
|
/** |
15
|
|
|
* @var string |
16
|
|
|
*/ |
17
|
|
|
protected const LOCAL_STORAGE_DIRECTORY = __DIR__ . '/storage'; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* @var BucketInterface |
21
|
|
|
*/ |
22
|
|
|
protected $local; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @var BucketInterface |
26
|
|
|
*/ |
27
|
|
|
protected $second; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @return void |
31
|
|
|
*/ |
32
|
|
|
public function setUp(): void |
33
|
|
|
{ |
34
|
|
|
parent::setUp(); |
35
|
|
|
|
36
|
|
|
$this->local = Bucket::fromAdapter( |
37
|
|
|
new LocalFilesystemAdapter(self::LOCAL_STORAGE_DIRECTORY) |
38
|
|
|
); |
39
|
|
|
|
40
|
|
|
$this->second = Bucket::fromAdapter( |
41
|
|
|
new LocalFilesystemAdapter(self::LOCAL_STORAGE_DIRECTORY . '/second') |
42
|
|
|
); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* @return void |
47
|
|
|
*/ |
48
|
|
|
public function tearDown(): void |
49
|
|
|
{ |
50
|
|
|
$this->cleanTempDirectory(); |
51
|
|
|
|
52
|
|
|
parent::tearDown(); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @return void |
57
|
|
|
*/ |
58
|
|
|
protected function cleanTempDirectory(): void |
59
|
|
|
{ |
60
|
|
|
$iterator = new \RecursiveIteratorIterator( |
61
|
|
|
new \RecursiveDirectoryIterator(self::LOCAL_STORAGE_DIRECTORY, \FilesystemIterator::SKIP_DOTS), |
62
|
|
|
\RecursiveIteratorIterator::CHILD_FIRST |
63
|
|
|
); |
64
|
|
|
|
65
|
|
|
/** @var \SplFileInfo $file */ |
66
|
|
|
foreach($iterator as $file) { |
67
|
|
|
if ($file->getFilename() === '.gitignore') { |
68
|
|
|
continue; |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
\error_clear_last(); |
72
|
|
|
|
73
|
|
|
if ($file->isDir()) { |
74
|
|
|
@\rmdir($file->getPathname()); |
|
|
|
|
75
|
|
|
} else { |
76
|
|
|
@\unlink($file->getPathname()); |
|
|
|
|
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
if ($error = \error_get_last()) { |
80
|
|
|
$prefix = 'An error occurred while clear temporary local storage directory: '; |
81
|
|
|
$this->addWarning($prefix . $error['message']); |
82
|
|
|
} |
83
|
|
|
} |
84
|
|
|
} |
85
|
|
|
} |
86
|
|
|
|
If you suppress an error, we recommend checking for the error condition explicitly: