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

[5.8] Fix session resolver in RoutingServiceProvider #28438

Merged
merged 3 commits into from
May 8, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Illuminate/Routing/RoutingServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ protected function registerUrlGenerator()
// get the information it needs to function. This just provides some of
// the convenience features to this URL generator like "signed" URLs.
$url->setSessionResolver(function () {
return $this->app['session'];
return $this->app['session'] ?? null;
});

$url->setKeyResolver(function () {
Expand Down
44 changes: 44 additions & 0 deletions tests/Integration/Routing/PreviousUrlTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

namespace Illuminate\Tests\Integration\Routing;

use Orchestra\Testbench\TestCase;
use Illuminate\Support\Facades\Route;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Session\SessionServiceProvider;

class PreviousUrlTest extends TestCase
{
public function test_previous_url_without_session()
{
Route::post('/previous-url', function (DummyFormRequest $request) {
return 'OK';
});

$response = $this->postJson('/previous-url');

$this->assertEquals(422, $response->status());
}

protected function getApplicationProviders($app)
{
$providers = parent::getApplicationProviders($app);

return array_filter($providers, function ($provider) {
return $provider !== SessionServiceProvider::class;
});
}
}

class DummyFormRequest extends FormRequest
{
public function rules()
{
return [
'foo' => [
'required',
'string',
],
];
}
}