Skip to content

Commit

Permalink
Fix php-console tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Seldaek committed Nov 11, 2024
1 parent 9180bec commit 006e90c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"guzzlehttp/psr7": "^2.2",
"mongodb/mongodb": "^1.8",
"php-amqplib/php-amqplib": "~2.4 || ^3",
"php-console/php-console": "^3.1",
"phpstan/phpstan": "^2",
"phpstan/phpstan-deprecation-rules": "^2",
"phpstan/phpstan-strict-rules": "^2",
Expand Down
16 changes: 10 additions & 6 deletions tests/Monolog/Handler/PHPConsoleHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
use PhpConsole\Dispatcher\Errors as ErrorDispatcher;
use PhpConsole\Handler as VendorPhpConsoleHandler;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\WithoutErrorHandler;
use PHPUnit\Framework\MockObject\MockObject;

/**
Expand Down Expand Up @@ -169,6 +170,7 @@ public function testDebugTags($tagsContextKeys = null)
}
}

#[WithoutErrorHandler]
public function testError($classesPartialsTraceIgnore = null)
{
$code = E_USER_NOTICE;
Expand All @@ -182,10 +184,12 @@ public function testError($classesPartialsTraceIgnore = null)
$this->equalTo($line),
$classesPartialsTraceIgnore ?: $this->equalTo($this->getHandlerDefaultOption('classesPartialsTraceIgnore'))
);
$errorHandler = ErrorHandler::register($this->initLogger($classesPartialsTraceIgnore ? ['classesPartialsTraceIgnore' => $classesPartialsTraceIgnore] : []), false);
$errorHandler = ErrorHandler::register($this->initLogger($classesPartialsTraceIgnore ? ['classesPartialsTraceIgnore' => $classesPartialsTraceIgnore] : []), false, false);
$errorHandler->registerErrorHandler([], false, E_USER_WARNING);
$reflMethod = new \ReflectionMethod($errorHandler, 'handleError');
$reflMethod->invoke($errorHandler, $code, $message, $file, $line);

restore_error_handler();
}

public function testException()
Expand Down Expand Up @@ -215,11 +219,6 @@ public function testOptionEnabled()
$this->initLogger(['enabled' => false])->debug('test');
}

public function testOptionClassesPartialsTraceIgnore()
{
$this->testError(['Class', 'Namespace\\']);
}

public function testOptionDebugTagsKeysInContext()
{
$this->testDebugTags(['key1', 'key2']);
Expand All @@ -232,6 +231,11 @@ public function testOptionUseOwnErrorsAndExceptionsHandler()
}));
$this->assertEquals([VendorPhpConsoleHandler::getInstance(), 'handleException'], set_exception_handler(function () {
}));

restore_exception_handler();
restore_error_handler();
restore_exception_handler();
restore_error_handler();
}

public static function provideConnectorMethodsOptionsSets()
Expand Down

0 comments on commit 006e90c

Please sign in to comment.