-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Check logs against parts of the message only #6704
Conversation
The implementation looks good. |
Something wrong with GA checks.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would lean towards creating a new assertLoggedStrict()
or the like, but if you two prefer this I'm good with it.
Edit: the opposite, I suppose! assertLogContains()
I was actually contemplating between a new method and modified method. I'll check what I can do. |
Generally It is better to avoid boolean flag parameter. $this->assertLogged('error', 'variable did not', false); // What's false? Jump to the method.
$this->assertLogContains('error', 'variable did not'); |
5e85901
to
4894788
Compare
$useExactComparison
option to assertLogged
@@ -349,8 +349,6 @@ protected function mockSession() | |||
* @param string|null $expectedMessage | |||
* | |||
* @return bool | |||
* | |||
* @throws Exception | |||
*/ | |||
public function assertLogged(string $level, $expectedMessage = null) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not related to this PR, but why $expectedMessage
can be null?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure either.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤦♂️
/** | ||
* Asserts that there is a log record that contains `$logMessage` in the message. | ||
*/ | ||
public function assertLogContains(string $level, string $logMessage, string $message = ''): void |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
$expectedMessage
is better? assertLogged()
uses it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My understanding is $expectedMessage
is used since the assertion compares the message as expected in the logs.
For assertLogContains
, I think it is counter-intuitive to use $expectedMessage
when it can only be a part of the whole expected message. I was also thinking whether to use $needle
or $needleMessage
as alternative name.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No preference from me
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am a little uncomfortable with both $needle and $needleMessage.
needle needs haystack.
So let's leave it as it is.
Description
Currently,
CIUnitTestCase::assertLogged()
matches the logged message verbatim. For simple messages this is no problem but for complex, hard-to-build, or volatile messages, it may be hard to come up with the exact message. This PR adds the capability for theassertLogged
method to compare only parts of the message instead of the whole.Checklist: