Open juhasev opened 3 years ago
You haven't changed anything else? Not sure why the HandleCors class would be null if it's resolved from the container
No other changes. Reverted back to the previous version 2.0.3 and everything works properly with the above config.
With Laravel 8? No Octane or anything?
I just did composer require laravel/laravel
en moved the HandleCors from $middleware to the web
part and don't get any errors.
Does it happen immediately? Or on CORS requests?
It's strange cause this is calling it:
$this->app->make(HandleCors::class)->onRequestHandled($event);
But why would that be null. It registered in register()
This is Laravel 8 standard without Octane. The error happened during testing.
What do you mean during testing? A unit test? How does it look?
Yes during a unit (feature) controller test. Standard Laravel test setup. The test bootstrap loads the HTTP kernel normally, so I would assume this would also happen outside the tests.
I got the same error after upgrading to 2.0.4. from 2.0.3 on Laravel 8.44.0, no Octane. The issue occurs only during phpunit feature tests. Like so:
/**
* @test
* @return void
*/
public function verifyResponse(): void
{
$this->withoutMiddleware([HandleCors::class])
$response = $this->call('GET', '/api/v1/some-route');
$response->assertStatus(Response::HTTP_OK);
}
Here is the call stack:
3) Tests\Feature\someTest::verifyResponse
Error: Call to undefined method class@anonymous::onRequestHandled()
/var/www/html/vendor/fruitcake/laravel-cors/src/CorsServiceProvider.php:42
/var/www/html/vendor/laravel/framework/src/Illuminate/Events/Dispatcher.php:392
/var/www/html/vendor/laravel/framework/src/Illuminate/Events/Dispatcher.php:237
/var/www/html/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php:118
/var/www/html/vendor/laravel/framework/src/Illuminate/Foundation/Testing/Concerns/MakesHttpRequests.php:509
/var/www/html/tests/Feature/someTest.php:88
After reverting to 2.0.3 the issue is resolved.
I am getting this error after upgrading the package.
This is caused by HandleCors::class not resolving from the container. Seems like the package now has an issue if HandleCors::class is loaded in $middlewareGroups. Adding HandleCors::class to the $middleware array does not solve the issue either. We have 3 different middleware groups and we are only using HandleCors::class in one of them.
Here is the HTTP kernel