Trait LogTestTrait
Make assertions on logs
Method Summary
-
assertLogAbsent() public
Ensure that no log messages of a given level were captured by test loggers.
-
assertLogMessage() public
-
assertLogMessageContains() public
-
captureLogConfigs() public
Capture the log configs before setUp() runs.
-
cleanupLog() public
Reset log configs to the ones that existed before the test.
-
expectLogMessage() protected
-
setupLog() public
Method Detail
assertLogAbsent() ¶ public
assertLogAbsent(string $level, string $failMsg = ''): void
Ensure that no log messages of a given level were captured by test loggers.
Parameters
-
string$level The level of the expected message
-
string$failMsg optional The error message if the message was not in the log engine
Returns
voidassertLogMessage() ¶ public
assertLogMessage(string $level, string $expectedMessage, string|null $scope = null, string $failMsg = ''): void
Parameters
-
string$level The level of the expected message
-
string$expectedMessage The message which should be inside the log engine
-
string|null$scope optional The scope of the expected message. If a message has multiple scopes, the provided scope must be within the message's set.
-
string$failMsg optional The error message if the message was not in the log engine
Returns
voidassertLogMessageContains() ¶ public
assertLogMessageContains(string $level, string $expectedMessage, string|null $scope = null, string $failMsg = ''): void
Parameters
-
string$level The level which should receive a log message
-
string$expectedMessage The message which should be inside the log engine
-
string|null$scope optional The scope of the expected message. If a message has multiple scopes, the provided scope must be within the message's set.
-
string$failMsg optional The error message if the message was not in the log engine
Returns
voidcaptureLogConfigs() ¶ public
captureLogConfigs(): void
Capture the log configs before setUp() runs.
Returns
voidcleanupLog() ¶ public
cleanupLog(): void
Reset log configs to the ones that existed before the test.
Returns
voidexpectLogMessage() ¶ protected
expectLogMessage(string $level, string $expectedMessage, string|null $scope, string $failMsg = '', bool $contains = false): void
Parameters
-
string$level The level which should receive a log message
-
string$expectedMessage The message which should be inside the log engine
-
string|null$scope The scope of the expected message. If a message has multiple scopes, the provided scope must be within the message's set.
-
string$failMsg optional The error message if the message was not in the log engine
-
bool$contains optional Flag to decide if the expectedMessage can only be part of the logged message
Returns
voidsetupLog() ¶ public
setupLog(array|string $levels): void
Parameters
-
array|string$levels The levels(s) which should receive a log message
Returns
void