-
I have a protected function failedValidation(Validator $validator)
{
Log::channel('logistics')->info('Validation failed. Submitted serials:', [
'contents' => $this->input('contents'),
]);
... I want to test that this logs correctly, so in a test I'm doing this: Log::spy();
$this->postJson(
'logistics/delivery',
[
'location_id' => $location->uuid,
'contents' => [
$case1->serial,
],
]
)
->assertUnprocessable();
Log::shouldHaveReceived('info')
->withArgs(function ($message, $context) use ($case1) {
$this->assertStringContainsString('Validation failed. Submitted serials:', $message);
$this->assertArrayHasKey('contents', $context);
$this->assertEquals([$case1->serial], $context['contents']);
return true;
}); This fails in the I'm using I also tried spying on the channel specifically, using If I remove the use of How should I test this? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
I found that the easiest way to deal with this is to use timacdonald/log-fake, which allows tests on log channels to work properly. |
Beta Was this translation helpful? Give feedback.
I found that the easiest way to deal with this is to use timacdonald/log-fake, which allows tests on log channels to work properly.