Uploaded image for project: 'translate5'
  1. translate5
  2. TRANSLATE-4523

Create test to check php.log file

XMLWordPrintable

      Hint by Marc: We should not only check for warnings, but also for errors and fatals.

      To ensure that a log check runs after all other tests, create a dedicated test class and make sure it runs last.

      1. Create tests/FinalLogCheckTest.php
      **

      use PHPUnit\Framework\TestCase;   
      
      class FinalLogCheckTest extends TestCase → translate5 test base class here
      {
          public function testPhpLogShouldNotContainWarnings(): void
          {
              $logFile = '/path/to/php.log';
      
              if (!file_exists($logFile)) {
                  $this->markTestSkipped('The php.log file does not exist.');
              }
      
              $logContent = file_get_contents($logFile);
              $this->assertStringNotContainsString('PHP Warning', $logContent, 'PHP warnings were found in the log file!');
          }
      }

      2. Ensure This Test Runs Last
      PHPUnit executes test files alphabetically. To enforce execution order, name the file accordingly:

      tests/
      ├── 01_SomeTest.php
      ├── 02_OtherTest.php
      ├── ZZ_FinalLogCheckTest.php  <-- Runs last 

      Alternatively, define the order explicitly in phpunit.xml:

      <phpunit>
          <testsuites>
              <testsuite name="All Tests">
                  <file>tests/01_SomeTest.php</file>
                  <file>tests/02_OtherTest.php</file>
                  <file>tests/ZZ_FinalLogCheckTest.php</file>
              </testsuite>
          </testsuites>
      </phpunit> 

            pavelperminov Pavel Perminov
            pavelperminov Pavel Perminov
            Thomas Lauria
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: