diff --git a/composer.json b/composer.json index 8b84f43..0a0c99b 100644 --- a/composer.json +++ b/composer.json @@ -17,7 +17,7 @@ "phpstan/phpstan": "^2.1.11", "phpstan/phpstan-phpunit": "^2.0.6", "phpstan/phpstan-strict-rules": "^2.0.4", - "phpunit/phpunit": "^12.0.10", + "phpunit/phpunit": "^12.1.0", "slam/php-cs-fixer-extensions": "^3.12", "symfony/console": "^7.2.5" }, diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 3103387..23048c2 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -42,3 +42,15 @@ parameters: count: 1 path: tests/ErrorHandlerTest.php + - + message: '#^Parameter \#1 \$filename of function file_get_contents expects string, string\|false given\.$#' + identifier: argument.type + count: 4 + path: tests/ErrorHandlerTest.php + + - + message: '#^Parameter \#1 \$filename of function filesize expects string, string\|false given\.$#' + identifier: argument.type + count: 2 + path: tests/ErrorHandlerTest.php + diff --git a/tests/ErrorHandlerTest.php b/tests/ErrorHandlerTest.php index a7e7301..5cf99c0 100644 --- a/tests/ErrorHandlerTest.php +++ b/tests/ErrorHandlerTest.php @@ -12,8 +12,6 @@ final class ErrorHandlerTest extends TestCase { - private string $backupErrorLog; - private string $errorLog; private ErrorException $exception; /** @var list */ @@ -23,11 +21,6 @@ final class ErrorHandlerTest extends TestCase protected function setUp(): void { - $this->backupErrorLog = (string) \ini_get('error_log'); - $this->errorLog = __DIR__ . \DIRECTORY_SEPARATOR . 'error_log_test'; - \touch($this->errorLog); - \ini_set('error_log', $this->errorLog); - $this->exception = new ErrorException(\uniqid('normal_'), \E_USER_NOTICE); $this->errorHandler = new ErrorHandler(function (string $subject, string $body): void { $this->emailsSent[] = [ @@ -43,8 +36,6 @@ protected function setUp(): void protected function tearDown(): void { \putenv('COLUMNS'); - \ini_set('error_log', $this->backupErrorLog); - @\unlink($this->errorLog); if ($this->unregister) { \restore_exception_handler(); \restore_error_handler(); @@ -138,7 +129,8 @@ public function testHandleWebExceptionWithDisplay(): void self::assertStringContainsString($this->exception->getMessage(), $output); - $errorLogContent = (string) \file_get_contents($this->errorLog); + self::expectErrorLog(); + $errorLogContent = (string) \file_get_contents(\ini_get('error_log')); self::assertStringContainsString($this->exception->getMessage(), $errorLogContent); } @@ -154,7 +146,8 @@ public function testHandleWebExceptionWithoutDisplay(): void self::assertStringNotContainsString($this->exception->getMessage(), $output); - $errorLogContent = (string) \file_get_contents($this->errorLog); + self::expectErrorLog(); + $errorLogContent = (string) \file_get_contents(\ini_get('error_log')); self::assertStringContainsString($this->exception->getMessage(), $errorLogContent); } @@ -164,7 +157,7 @@ public function testLogErrorAndException(): void $this->errorHandler->logException($this->exception); - self::assertSame(0, \filesize($this->errorLog)); + self::assertSame(0, \filesize(\ini_get('error_log'))); $this->errorHandler->setLogErrors(true); @@ -172,7 +165,8 @@ public function testLogErrorAndException(): void $this->errorHandler->logException($exception); - $errorLogContent = (string) \file_get_contents($this->errorLog); + self::expectErrorLog(); + $errorLogContent = (string) \file_get_contents(\ini_get('error_log')); self::assertStringContainsString($exception->getMessage(), $errorLogContent); self::assertStringContainsString($this->exception->getMessage(), $errorLogContent); @@ -236,7 +230,8 @@ public function testErroriNellInvioDellaMailVengonoComunqueLoggati(): void $errorHandler->emailException($this->exception); - $errorLogContent = (string) \file_get_contents($this->errorLog); + self::expectErrorLog(); + $errorLogContent = (string) \file_get_contents(\ini_get('error_log')); self::assertStringNotContainsString($this->exception->getMessage(), $errorLogContent); self::assertStringContainsString($mailError, $errorLogContent); } @@ -323,7 +318,7 @@ public function testCanSetCustomErrorLogCallback(): void $this->errorHandler->logException($this->exception); - self::assertSame(0, \filesize($this->errorLog)); + self::assertSame(0, \filesize(\ini_get('error_log'))); self::assertStringContainsString($this->exception->getMessage(), \var_export($data, true)); } }