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

VerifyCsrfToken $next($request) returning null #20456

Closed
willselby opened this issue Aug 7, 2017 · 1 comment
Closed

VerifyCsrfToken $next($request) returning null #20456

willselby opened this issue Aug 7, 2017 · 1 comment

Comments

@willselby
Copy link

  • Laravel Version: 5.2.14
  • PHP Version: 7.0.18
  • Database Driver & Version: MySQL 5.7.19

Description:

When running a phpunit test that calls $this->visit('...'), VerifyCsrfToken.php is failing to call $this->addCookieToResponse($request, $next($request)) (line 64) because $next($request) is returning null. It's my understanding that $next($request) should return a response object.

Steps To Reproduce:

  1. Create phpunit test that calls $this->visit('...')
  2. Run test without using withoutMiddleware()

Stack:

ErrorException: Trying to get property of non-object in /var/www/html/training_portal/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/VerifyCsrfToken.php:135
Stack trace:
#0 /var/www/html/training_portal/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/VerifyCsrfToken.php(135): Illuminate\Foundation\Bootstrap\HandleExceptions->handleError(8, 'Trying to get p...', '/var/www/html/t...', 135, Array)
#1 /var/www/html/training_portal/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/VerifyCsrfToken.php(64): Illuminate\Foundation\Http\Middleware\VerifyCsrfToken->addCookieToResponse(Object(Illuminate\Http\Request), NULL)
#2 [internal function]: Illuminate\Foundation\Http\Middleware\VerifyCsrfToken->handle(Object(Illuminate\Http\Request), Object(Closure))
#3 /var/www/html/training_portal/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(124): call_user_func_array(Array, Array)
#4 [internal function]: Illuminate\Pipeline\Pipeline->Illuminate\Pipeline{closure}(Object(Illuminate\Http\Request))
#5 /var/www/html/training_portal/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(32): call_user_func(Object(Closure), Object(Illuminate\Http\Request))
#6 /var/www/html/training_portal/vendor/laravel/framework/src/Illuminate/View/Middleware/ShareErrorsFromSession.php(49): Illuminate\Routing\Pipeline->Illuminate\Routing{closure}(Object(Illuminate\Http\Request))
#7 [internal function]: Illuminate\View\Middleware\ShareErrorsFromSession->handle(Object(Illuminate\Http\Request), Object(Closure))
#8 /var/www/html/training_portal/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(124): call_user_func_array(Array, Array)
#9 [internal function]: Illuminate\Pipeline\Pipeline->Illuminate\Pipeline{closure}(Object(Illuminate\Http\Request))
#10 /var/www/html/training_portal/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(32): call_user_func(Object(Closure), Object(Illuminate\Http\Request))
#11 /var/www/html/training_portal/vendor/laravel/framework/src/Illuminate/Session/Middleware/StartSession.php(62): Illuminate\Routing\Pipeline->Illuminate\Routing{closure}(Object(Illuminate\Http\Request))
#12 [internal function]: Illuminate\Session\Middleware\StartSession->handle(Object(Illuminate\Http\Request), Object(Closure))
#13 /var/www/html/training_portal/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(124): call_user_func_array(Array, Array)
#14 [internal function]: Illuminate\Pipeline\Pipeline->Illuminate\Pipeline{closure}(Object(Illuminate\Http\Request))
#15 /var/www/html/training_portal/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(32): call_user_func(Object(Closure), Object(Illuminate\Http\Request))
#16 /var/www/html/training_portal/vendor/laravel/framework/src/Illuminate/Cookie/Middleware/AddQueuedCookiesToResponse.php(37): Illuminate\Routing\Pipeline->Illuminate\Routing{closure}(Object(Illuminate\Http\Request))
#17 [internal function]: Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse->handle(Object(Illuminate\Http\Request), Object(Closure))
#18 /var/www/html/training_portal/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(124): call_user_func_array(Array, Array)
#19 [internal function]: Illuminate\Pipeline\Pipeline->Illuminate\Pipeline{closure}(Object(Illuminate\Http\Request))
#20 /var/www/html/training_portal/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(32): call_user_func(Object(Closure), Object(Illuminate\Http\Request))
#21 /var/www/html/training_portal/vendor/laravel/framework/src/Illuminate/Cookie/Middleware/EncryptCookies.php(59): Illuminate\Routing\Pipeline->Illuminate\Routing{closure}(Object(Illuminate\Http\Request))
#22 [internal function]: Illuminate\Cookie\Middleware\EncryptCookies->handle(Object(Illuminate\Http\Request), Object(Closure))
#23 /var/www/html/training_portal/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(124): call_user_func_array(Array, Array)
#24 [internal function]: Illuminate\Pipeline\Pipeline->Illuminate\Pipeline{closure}(Object(Illuminate\Http\Request))
#25 /var/www/html/training_portal/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(32): call_user_func(Object(Closure), Object(Illuminate\Http\Request))
#26 [internal function]: Illuminate\Routing\Pipeline->Illuminate\Routing{closure}(Object(Illuminate\Http\Request))
#27 /var/www/html/training_portal/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(102): call_user_func(Object(Closure), Object(Illuminate\Http\Request))
#28 /var/www/html/training_portal/vendor/laravel/framework/src/Illuminate/Routing/Router.php(705): Illuminate\Pipeline\Pipeline->then(Object(Closure))
#29 /var/www/html/training_portal/vendor/laravel/framework/src/Illuminate/Routing/Router.php(678): Illuminate\Routing\Router->runRouteWithinStack(Object(Illuminate\Routing\Route), Object(Illuminate\Http\Request))
#30 /var/www/html/training_portal/vendor/laravel/framework/src/Illuminate/Routing/Router.php(654): Illuminate\Routing\Router->dispatchToRoute(Object(Illuminate\Http\Request))
#31 /var/www/html/training_portal/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(246): Illuminate\Routing\Router->dispatch(Object(Illuminate\Http\Request))
#32 [internal function]: Illuminate\Foundation\Http\Kernel->Illuminate\Foundation\Http{closure}(Object(Illuminate\Http\Request))
#33 /var/www/html/training_portal/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(52): call_user_func(Object(Closure), Object(Illuminate\Http\Request))
#34 /var/www/html/training_portal/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/CheckForMaintenanceMode.php(44): Illuminate\Routing\Pipeline->Illuminate\Routing{closure}(Object(Illuminate\Http\Request))
#35 [internal function]: Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode->handle(Object(Illuminate\Http\Request), Object(Closure))
#36 /var/www/html/training_portal/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(124): call_user_func_array(Array, Array)
#37 [internal function]: Illuminate\Pipeline\Pipeline->Illuminate\Pipeline{closure}(Object(Illuminate\Http\Request))
#38 /var/www/html/training_portal/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(32): call_user_func(Object(Closure), Object(Illuminate\Http\Request))
#39 [internal function]: Illuminate\Routing\Pipeline->Illuminate\Routing{closure}(Object(Illuminate\Http\Request))
#40 /var/www/html/training_portal/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(102): call_user_func(Object(Closure), Object(Illuminate\Http\Request))
#41 /var/www/html/training_portal/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(132): Illuminate\Pipeline\Pipeline->then(Object(Closure))
#42 /var/www/html/training_portal/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(99): Illuminate\Foundation\Http\Kernel->sendRequestThroughRouter(Object(Illuminate\Http\Request))
#43 /var/www/html/training_portal/vendor/laravel/framework/src/Illuminate/Foundation/Testing/Concerns/MakesHttpRequests.php(480): Illuminate\Foundation\Http\Kernel->handle(Object(Illuminate\Http\Request))
#44 /var/www/html/training_portal/vendor/laravel/framework/src/Illuminate/Foundation/Testing/Concerns/InteractsWithPages.php(62): Illuminate\Foundation\Testing\TestCase->call('GET', 'http://localhos...', Array, Array, Array)
#45 /var/www/html/training_portal/vendor/laravel/framework/src/Illuminate/Foundation/Testing/Concerns/InteractsWithPages.php(45): Illuminate\Foundation\Testing\TestCase->makeRequest('GET', 'http://localhos...')
#46 /var/www/html/training_portal/tests/ProgrammeFinalSignoffTest.php(54): Illuminate\Foundation\Testing\TestCase->visit('/programmes/pro...')
#47 [internal function]: ProgrammeManagerFinalSignoffTest->testProgrammeFinalSignoff()
#48 /var/www/html/training_portal/vendor/phpunit/phpunit/src/Framework/TestCase.php(908): ReflectionMethod->invokeArgs(Object(ProgrammeManagerFinalSignoffTest), Array)
#49 /var/www/html/training_portal/vendor/phpunit/phpunit/src/Framework/TestCase.php(768): PHPUnit_Framework_TestCase->runTest()
#50 /var/www/html/training_portal/vendor/phpunit/phpunit/src/Framework/TestResult.php(612): PHPUnit_Framework_TestCase->runBare()
#51 /var/www/html/training_portal/vendor/phpunit/phpunit/src/Framework/TestCase.php(724): PHPUnit_Framework_TestResult->run(Object(ProgrammeManagerFinalSignoffTest))
#52 /var/www/html/training_portal/vendor/phpunit/phpunit/src/Framework/TestSuite.php(747): PHPUnit_Framework_TestCase->run(Object(PHPUnit_Framework_TestResult))
#53 /var/www/html/training_portal/vendor/phpunit/phpunit/src/TextUI/TestRunner.php(440): PHPUnit_Framework_TestSuite->run(Object(PHPUnit_Framework_TestResult))
#54 /var/www/html/training_portal/vendor/phpunit/phpunit/src/TextUI/Command.php(149): PHPUnit_TextUI_TestRunner->doRun(Object(PHPUnit_Framework_TestSuite), Array)
#55 /var/www/html/training_portal/vendor/phpunit/phpunit/src/TextUI/Command.php(100): PHPUnit_TextUI_Command->run(Array, true)
#56 /var/www/html/training_portal/vendor/phpunit/phpunit/phpunit(47): PHPUnit_TextUI_Command::main()
#57 {main}

@Dylan-DPC-zz
Copy link

Laravel 5.2 is no longer supported. Use the forums or slack channel for assistance.

@themsaid themsaid closed this as completed Aug 7, 2017
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

3 participants