Passed
Pull Request — master (#182)
by Rustam
02:20
created

FileStorageTest::setUp()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 2
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
nc 1
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Yii\Debug\Tests\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()));
36
    }
37
38
    /**
39
     * @dataProvider dataProvider()
40
     */
41
    public function testClear(array $data): void
42
    {
43
        $idGenerator = new DebuggerIdGenerator();
44
        $storage = $this->getStorage($idGenerator);
45
        $collector = $this->createFakeCollector($data);
46
47
        $storage->addCollector($collector);
48
        $storage->flush();
49
        $storage->clear();
50
        $this->assertDirectoryDoesNotExist($this->path);
51
    }
52
53
    public function getStorage(DebuggerIdGenerator $idGenerator): StorageInterface
54
    {
55
        return new FileStorage(
56
            $this->path,
57
            $idGenerator,
58
            new Aliases()
59
        );
60
    }
61
}
62