LogDAOTest.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  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. protected function setUp(): void {
  9. $this->logDAO = new FreshRSS_LogDAO();
  10. $this->logPath = FreshRSS_LogDAO::logPath(self::LOG_FILE_TEST);
  11. file_put_contents(
  12. $this->logPath,
  13. '[Wed, 08 Feb 2023 15:35:05 +0000] [notice] --- Migration 2019_12_22_FooBar: OK'
  14. );
  15. }
  16. public function test_lines_is_array_and_truncate_function_work(): void {
  17. self::assertEquals(USERS_PATH . '/' . Minz_User::INTERNAL_USER . '/' . self::LOG_FILE_TEST, $this->logPath);
  18. $line = $this->logDAO::lines(self::LOG_FILE_TEST);
  19. self::assertCount(1, $line);
  20. self::assertInstanceOf(FreshRSS_Log::class, $line[0]);
  21. self::assertEquals('Wed, 08 Feb 2023 15:35:05 +0000', $line[0]->date());
  22. self::assertEquals('notice', $line[0]->level());
  23. self::assertEquals("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. protected function tearDown(): void {
  28. unlink($this->logPath);
  29. }
  30. }