Passed
Push — master ( e72ba5...492fde )
by Alexander
10:28
created

FileTargetTest::testExport()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 19
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 11
c 2
b 0
f 0
dl 0
loc 19
rs 9.9
cc 1
nc 1
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Profiler\Tests;
6
7
use Yiisoft\Files\FileHelper;
8
use Yiisoft\Profiler\FileTarget;
9
use Yiisoft\Profiler\Profiler;
10
11
class FileTargetTest extends TestCase
12
{
13
    protected string $testFilePath;
14
15
    protected function setUp(): void
16
    {
17
        parent::setUp();
18
19
        $this->testFilePath = 'tests/data';
20
    }
21
22
    protected function tearDown(): void
23
    {
24
        parent::tearDown();
25
26
        if (!empty($this->testFilePath)) {
27
            FileHelper::removeDirectory($this->testFilePath);
28
        }
29
    }
30
31
    public function testExport(): void
32
    {
33
        $profiler = new Profiler($this->logger);
34
35
        $filename = $this->testFilePath . DIRECTORY_SEPARATOR . 'test.txt';
36
37
        $target = new FileTarget();
38
        $target->setFilename($filename);
39
        $profiler->addTarget($target);
40
41
        $profiler->begin('test-export', ['category' => 'test-category']);
42
        $profiler->end('test-export', ['category' => 'test-category']);
43
44
        $profiler->flush();
45
46
        $this->assertFileExists($filename);
47
48
        $fileContent = file_get_contents($filename);
49
        $this->assertStringContainsString('[test-category] test-export', $fileContent);
50
    }
51
}
52