4
0

LogDAOTest.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. <?php
  2. declare(strict_types=1);
  3. use PHPUnit\Framework\TestCase;
  4. class LogDAOTest extends TestCase {
  5. private const LOG_FILE_TEST = 'logFileTest.txt';
  6. private FreshRSS_LogDAO $logDAO;
  7. private string $logPath;
  8. #[\Override]
  9. protected function setUp(): void {
  10. $this->logDAO = new FreshRSS_LogDAO();
  11. $this->logPath = FreshRSS_LogDAO::logPath(self::LOG_FILE_TEST);
  12. file_put_contents(
  13. $this->logPath,
  14. '[Wed, 08 Feb 2023 15:35:05 +0000] [notice] --- Migration 2019_12_22_FooBar: OK'
  15. );
  16. }
  17. public function test_lines_is_array_and_truncate_function_work(): void {
  18. self::assertSame(USERS_PATH . '/' . Minz_User::INTERNAL_USER . '/' . self::LOG_FILE_TEST, $this->logPath);
  19. $line = $this->logDAO::lines(self::LOG_FILE_TEST);
  20. self::assertCount(1, $line);
  21. self::assertSame('Wed, 08 Feb 2023 15:35:05 +0000', $line[0]->date());
  22. self::assertSame('notice', $line[0]->level());
  23. self::assertSame("Migration 2019_12_22_FooBar: OK", $line[0]->info());
  24. $this->logDAO::truncate(self::LOG_FILE_TEST);
  25. self::assertStringContainsString('', file_get_contents($this->logPath) ?: '');
  26. }
  27. #[\Override]
  28. protected function tearDown(): void {
  29. unlink($this->logPath);
  30. }
  31. }