Skip to content

Commit

Permalink
Merge pull request #28438 from golubkovden/5.8
Browse files Browse the repository at this point in the history
[5.8] Fix session resolver in RoutingServiceProvider
  • Loading branch information
taylorotwell authored May 8, 2019
2 parents 6a70dcf + 6ba1530 commit 6eadc33
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
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',
],
];
}
}

0 comments on commit 6eadc33

Please sign in to comment.