1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Yiisoft\Yii\Debug\Tests\Unit\Storage; |
6
|
|
|
|
7
|
|
|
use Yiisoft\Aliases\Aliases; |
8
|
|
|
use Yiisoft\Files\FileHelper; |
9
|
|
|
use Yiisoft\Yii\Debug\DebuggerIdGenerator; |
10
|
|
|
use Yiisoft\Yii\Debug\Storage\FileStorage; |
11
|
|
|
use Yiisoft\Yii\Debug\Storage\StorageInterface; |
12
|
|
|
|
13
|
|
|
final class FileStorageTest extends AbstractStorageTest |
14
|
|
|
{ |
15
|
|
|
private string $path = __DIR__ . '/runtime'; |
16
|
|
|
|
17
|
|
|
protected function tearDown(): void |
18
|
|
|
{ |
19
|
|
|
parent::tearDown(); |
20
|
|
|
FileHelper::removeDirectory($this->path); |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @dataProvider dataProvider() |
25
|
|
|
*/ |
26
|
|
|
public function testFlushWithGC(array $data): void |
27
|
|
|
{ |
28
|
|
|
$idGenerator = new DebuggerIdGenerator(); |
29
|
|
|
$storage = $this->getStorage($idGenerator); |
30
|
|
|
$storage->setHistorySize(5); |
31
|
|
|
$collector = $this->createFakeCollector($data); |
32
|
|
|
|
33
|
|
|
$storage->addCollector($collector); |
34
|
|
|
$storage->flush(); |
35
|
|
|
$this->assertLessThanOrEqual(5, count($storage->read(StorageInterface::TYPE_SUMMARY, null))); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @dataProvider dataProvider() |
40
|
|
|
*/ |
41
|
|
|
public function testHistorySize(array $data): void |
42
|
|
|
{ |
43
|
|
|
$idGenerator = new DebuggerIdGenerator(); |
44
|
|
|
$idGenerator->reset(); |
45
|
|
|
$storage = $this->getStorage($idGenerator); |
46
|
|
|
$storage->setHistorySize(2); |
47
|
|
|
$collector = $this->createFakeCollector($data); |
48
|
|
|
|
49
|
|
|
$storage->addCollector($collector); |
50
|
|
|
$storage->flush(); |
51
|
|
|
$idGenerator->reset(); |
52
|
|
|
|
53
|
|
|
$storage->addCollector($collector); |
54
|
|
|
$storage->flush(); |
55
|
|
|
$idGenerator->reset(); |
56
|
|
|
|
57
|
|
|
$storage->addCollector($collector); |
58
|
|
|
$storage->flush(); |
59
|
|
|
$idGenerator->reset(); |
60
|
|
|
|
61
|
|
|
$read = $storage->read(StorageInterface::TYPE_SUMMARY, null); |
62
|
|
|
$this->assertCount(2, $read); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @dataProvider dataProvider() |
67
|
|
|
*/ |
68
|
|
|
public function testClear(array $data): void |
69
|
|
|
{ |
70
|
|
|
$idGenerator = new DebuggerIdGenerator(); |
71
|
|
|
$storage = $this->getStorage($idGenerator); |
72
|
|
|
$collector = $this->createFakeCollector($data); |
73
|
|
|
|
74
|
|
|
$storage->addCollector($collector); |
75
|
|
|
$storage->flush(); |
76
|
|
|
$storage->clear(); |
77
|
|
|
$this->assertDirectoryDoesNotExist($this->path); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
public function getStorage(DebuggerIdGenerator $idGenerator): FileStorage |
81
|
|
|
{ |
82
|
|
|
return new FileStorage( |
83
|
|
|
$this->path, |
84
|
|
|
$idGenerator, |
85
|
|
|
new Aliases() |
86
|
|
|
); |
87
|
|
|
} |
88
|
|
|
} |
89
|
|
|
|