Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@
"php": "~8.4.0 || ~8.5.0"
},
"require-dev": {
"phpstan/phpstan": "^2.2.5",
"phpstan/phpstan": "^2.2.9",
"phpstan/phpstan-phpunit": "^2.0.18",
"phpstan/phpstan-strict-rules": "^2.0.12",
"phpunit/phpunit": "^13.2.5",
"phpunit/phpunit": "^13.3.1",
"slam/php-cs-fixer-extensions": "^3.15.0",
"symfony/console": "^8.1.1"
"symfony/console": "^8.1.5"
},
"autoload": {
"psr-4": {
Expand Down
8 changes: 1 addition & 7 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,6 @@ parameters:
-
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
count: 3
path: tests/ErrorHandlerTest.php

36 changes: 18 additions & 18 deletions tests/ErrorHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,13 +123,12 @@ public function testHandleWebExceptionWithDisplay(): void
$this->errorHandler->setCli(false);
$this->errorHandler->setLogErrors(true);

self::expectErrorLog();
\ob_start();
$this->errorHandler->exceptionHandler($this->exception);
$output = (string) \ob_get_clean();

self::assertStringContainsString($this->exception->getMessage(), $output);

self::expectErrorLog();
$errorLogContent = (string) \file_get_contents(\ini_get('error_log'));
self::assertStringContainsString($this->exception->getMessage(), $errorLogContent);
}
Expand All @@ -140,34 +139,33 @@ public function testHandleWebExceptionWithoutDisplay(): void
$this->errorHandler->setCli(false);
$this->errorHandler->setLogErrors(true);

self::expectErrorLog();
\ob_start();
$this->errorHandler->exceptionHandler($this->exception);
$output = (string) \ob_get_clean();

self::assertStringNotContainsString($this->exception->getMessage(), $output);

self::expectErrorLog();
$errorLogContent = (string) \file_get_contents(\ini_get('error_log'));
self::assertStringContainsString($this->exception->getMessage(), $errorLogContent);
}

public function testLogErrorAndException(): void
{
$this->errorHandler->setLogErrors(false);

$this->errorHandler->logException($this->exception);

self::assertSame(0, \filesize(\ini_get('error_log')));
$errorLogContent = '';
$this->errorHandler->setErrorLogCallback(static function (string $message) use (& $errorLogContent): void {
$errorLogContent .= $message;
});

$this->errorHandler->setLogErrors(true);

$exception = new ErrorException(\uniqid(), \E_USER_ERROR, \E_ERROR, __FILE__, 1, $this->exception);

$this->errorHandler->logException($exception);

self::expectErrorLog();
$errorLogContent = (string) \file_get_contents(\ini_get('error_log'));

self::assertStringContainsString($exception->getMessage(), $errorLogContent);
self::assertStringContainsString($this->exception->getMessage(), $errorLogContent);
}
Expand All @@ -183,8 +181,8 @@ public function testEmailException(): void
$this->errorHandler->setLogErrors(true);

$key = \uniqid(__FUNCTION__);
$_SESSION = [$key => \uniqid()];
$_POST = [$key => \uniqid()];
$_SESSION = [$key => $sessionValue = \uniqid('session_')];
$_POST = [$key => $postValue = \uniqid('post_')];

$this->errorHandler->emailException($this->exception);

Expand All @@ -194,8 +192,9 @@ public function testEmailException(): void
$messageText = $message['body'];
self::assertIsString($messageText);
self::assertStringContainsString($this->exception->getMessage(), $messageText);
self::assertStringContainsString($_SESSION[$key], $messageText);
self::assertStringContainsString($_POST[$key], $messageText);
self::assertStringContainsString($key, $messageText);
self::assertStringContainsString($sessionValue, $messageText);
self::assertStringContainsString($postValue, $messageText);
}

public function testCanHideVariablesFromEmail(): void
Expand All @@ -207,8 +206,8 @@ public function testCanHideVariablesFromEmail(): void
$this->errorHandler->setLogErrors(true);

$key = \uniqid(__FUNCTION__);
$_SESSION = [$key => \uniqid()];
$_POST = [$key => \uniqid()];
$_SESSION = [$key => $sessionValue = \uniqid('session_')];
$_POST = [$key => $postValue = \uniqid('post_')];

$this->errorHandler->emailException($this->exception);

Expand All @@ -217,8 +216,9 @@ public function testCanHideVariablesFromEmail(): void

$messageText = $message['body'];
self::assertStringContainsString($this->exception->getMessage(), $messageText);
self::assertStringNotContainsString($_SESSION[$key], $messageText);
self::assertStringNotContainsString($_POST[$key], $messageText);
self::assertStringNotContainsString($key, $messageText);
self::assertStringNotContainsString($sessionValue, $messageText);
self::assertStringNotContainsString($postValue, $messageText);
}

public function testErroriNellInvioDellaMailVengonoComunqueLoggati(): void
Expand All @@ -230,9 +230,9 @@ public function testErroriNellInvioDellaMailVengonoComunqueLoggati(): void
$errorHandler = new ErrorHandler($mailCallback);
$errorHandler->setLogErrors(true);

self::expectErrorLog();
$errorHandler->emailException($this->exception);

self::expectErrorLog();
$errorLogContent = (string) \file_get_contents(\ini_get('error_log'));
self::assertStringNotContainsString($this->exception->getMessage(), $errorLogContent);
self::assertStringContainsString($mailError, $errorLogContent);
Expand Down Expand Up @@ -320,7 +320,7 @@ public function testCanSetCustomErrorLogCallback(): void

$this->errorHandler->logException($this->exception);

self::assertSame(0, \filesize(\ini_get('error_log')));
self::assertFileDoesNotExist((string) \ini_get('error_log'));
self::assertStringContainsString($this->exception->getMessage(), \var_export($data, true));
}
}