LogDAOTest.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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::assertEquals(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::assertInstanceOf(FreshRSS_Log::class, $line[0]);
  22. self::assertEquals('Wed, 08 Feb 2023 15:35:05 +0000', $line[0]->date());
  23. self::assertEquals('notice', $line[0]->level());
  24. self::assertEquals("Migration 2019_12_22_FooBar: OK", $line[0]->info());
  25. $this->logDAO::truncate(self::LOG_FILE_TEST);
  26. self::assertStringContainsString('', file_get_contents($this->logPath) ?: '');
  27. }
  28. #[\Override]
  29. protected function tearDown(): void {
  30. unlink($this->logPath);
  31. }
  32. }