feat: Check logs against parts of the message only#6704
feat: Check logs against parts of the message only#6704kenjis merged 2 commits intocodeigniter4:4.3from
Conversation
|
The implementation looks good. |
|
Something wrong with GA checks.
|
|
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| * | ||
| * @throws Exception | ||
| */ | ||
| public function assertLogged(string $level, $expectedMessage = null) |
There was a problem hiding this comment.
This is not related to this PR, but why $expectedMessage can be null?
There was a problem hiding this comment.
I'm not sure either.
| /** | ||
| * 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.
$expectedMessage is better? assertLogged() uses it.
There was a problem hiding this comment.
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.
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 theassertLoggedmethod to compare only parts of the message instead of the whole.Checklist: