Passed
Pull Request — master (#209)
by Alexander
26:16 queued 23:43
created

FileStorageTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 22
dl 0
loc 46
rs 10
c 0
b 0
f 0
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getStorage() 0 6 1
A testClear() 0 10 1
A tearDown() 0 4 1
A testFlushWithGC() 0 10 1
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()));
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