| Total Complexity | 4 |
| Total Lines | 39 |
| Duplicated Lines | 0 % |
| Changes | 2 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 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 | } |
||
| 52 |