fix: option to supress vendor deprecation
This commit is contained in:
@@ -10,10 +10,15 @@ use PHPUnit\Framework\TestCase;
|
||||
class ErrorHandlerTest extends TestCase
|
||||
{
|
||||
private array $serverBackup = [];
|
||||
private int $errorReportingBackup = 0;
|
||||
private string|false $vendorIssueModeBackup = false;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->serverBackup = $_SERVER;
|
||||
$this->errorReportingBackup = error_reporting();
|
||||
error_reporting(E_ALL);
|
||||
$this->vendorIssueModeBackup = getenv('APP_VENDOR_PHP_ISSUES_MODE');
|
||||
RequestContext::resetForTests();
|
||||
Debugger::$enabled = false;
|
||||
header_remove();
|
||||
@@ -23,6 +28,12 @@ class ErrorHandlerTest extends TestCase
|
||||
protected function tearDown(): void
|
||||
{
|
||||
$_SERVER = $this->serverBackup;
|
||||
error_reporting($this->errorReportingBackup);
|
||||
if ($this->vendorIssueModeBackup === false) {
|
||||
putenv('APP_VENDOR_PHP_ISSUES_MODE');
|
||||
} else {
|
||||
putenv('APP_VENDOR_PHP_ISSUES_MODE=' . $this->vendorIssueModeBackup);
|
||||
}
|
||||
RequestContext::resetForTests();
|
||||
Debugger::$enabled = false;
|
||||
header_remove();
|
||||
@@ -75,4 +86,44 @@ class ErrorHandlerTest extends TestCase
|
||||
|
||||
$this->assertSame(500, http_response_code());
|
||||
}
|
||||
|
||||
public function testHandleErrorThrowsForVendorDeprecationInStrictMode(): void
|
||||
{
|
||||
putenv('APP_VENDOR_PHP_ISSUES_MODE=strict');
|
||||
|
||||
$this->expectException(\ErrorException::class);
|
||||
ErrorHandler::handleError(E_DEPRECATED, 'deprecated', '/var/www/vendor/mintyphp/core/src/Router.php', 69);
|
||||
}
|
||||
|
||||
public function testHandleErrorSuppressesVendorDeprecationsWhenConfigured(): void
|
||||
{
|
||||
putenv('APP_VENDOR_PHP_ISSUES_MODE=suppress_deprecations');
|
||||
|
||||
$result = ErrorHandler::handleError(E_DEPRECATED, 'deprecated', '/var/www/vendor/mintyphp/core/src/Router.php', 69);
|
||||
$this->assertTrue($result);
|
||||
}
|
||||
|
||||
public function testHandleErrorSuppressesVendorWarningsOnlyInWarningMode(): void
|
||||
{
|
||||
putenv('APP_VENDOR_PHP_ISSUES_MODE=suppress_deprecations');
|
||||
|
||||
try {
|
||||
ErrorHandler::handleError(E_WARNING, 'warning', '/var/www/vendor/mintyphp/core/src/Router.php', 69);
|
||||
$this->fail('Expected ErrorException for vendor warning in suppress_deprecations mode.');
|
||||
} catch (\ErrorException) {
|
||||
// expected
|
||||
}
|
||||
|
||||
putenv('APP_VENDOR_PHP_ISSUES_MODE=suppress_deprecations_warnings');
|
||||
$result = ErrorHandler::handleError(E_WARNING, 'warning', '/var/www/vendor/mintyphp/core/src/Router.php', 69);
|
||||
$this->assertTrue($result);
|
||||
}
|
||||
|
||||
public function testHandleErrorNeverSuppressesNonVendorWarnings(): void
|
||||
{
|
||||
putenv('APP_VENDOR_PHP_ISSUES_MODE=suppress_deprecations_warnings');
|
||||
|
||||
$this->expectException(\ErrorException::class);
|
||||
ErrorHandler::handleError(E_WARNING, 'warning', '/var/www/lib/Http/ErrorHandler.php', 69);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user