Skip to content
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

Foundation pushes exception from log context to LoggedExceptionCollection #39904

Closed
Plytas opened this issue Dec 6, 2021 · 2 comments
Closed

Comments

@Plytas
Copy link
Contributor

Plytas commented Dec 6, 2021

  • Laravel Version: 8.74.0
  • PHP Version: 7.4.26
  • Database Driver & Version: not needed

Description:

In our application we had set up a new logging channel and we were passing an array to log context with key exception. FoundationServiceProvider picks up this key and pushes it to LoggedExceptionCollection and that in turn makes tests fail that check response status.

This happens because FoundationServiceProvider listens to MessageLogged event and pushes $event->context['exception'] to LoggedExceptionCollection. TestResponse sees this exception and tries to cast it to string.

I'm not sure if exception key in log context should be treated as real exception. If this behavior is intended, we will adjust our code accordingly.

Steps To Reproduce:

  1. Create a fresh laravel application
  2. Change web.php route to include a log with exception array in context:
Route::get('/', function () {
    \Illuminate\Support\Facades\Log::info('foo', [
        'exception' => [
            'bar'
        ]
    ]);

    return view('welcome');
});
  1. Run default provided test
public function test_example()
{
    $response = $this->get('/');

    $response->assertStatus(200);
}
  1. See ErrorException : Array to string conversion
@X-Coder264
Copy link
Contributor

This behavior is intended -> see #38464 for more details.

@Plytas
Copy link
Contributor Author

Plytas commented Dec 6, 2021

@X-Coder264 thank you. Somehow wasn't able to find mentioned issue.

@Plytas Plytas closed this as completed Dec 6, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants