Method [viaRemember] does not exist.
I am running tests in Laravel and trying access to my API.
I am sending token with headers (code bellow), same as a normal API call from postman for example. Api call from the postman works without any errors.
$response = $this->withHeaders([
'Authorization' => 'Bearer ' . JWTAuth::fromUser($this->user),
'Accept' => 'application/json',
])->getJson(route('customers.index.api'));
Your environment:
| Q | A
| ----------------- | ---
| Bug? | yes
| New Feature? | no
| Framework | Laravel
| Framework version | 9.31.0
| Package version | 2.0.0
| PHP version | 8.1
Steps to reproduce
Try to send request from laravel test
$response = $this->withHeaders([
'Authorization' => 'Bearer ' . JWTAuth::fromUser($this->user),
'Accept' => 'application/json',
])->getJson(route('customers.index.api'));
Expected behaviour
To allow access to API same as a request from the postman or mobile app for example.
Actual behaviour
• Tests\Feature\Customer\CustomerTest > if user can get api response
Expected response status code [200] but received 500.
Failed asserting that 200 is identical to 500.
The following exception occurred during the last request:
BadMethodCallException: Method [viaRemember] does not exist. in /Users/igor/Sites/invoicequick/vendor/php-open-source-saver/jwt-auth/src/JWTGuard.php:583
Stack trace:
#0 /Users/igor/Sites/invoicequick/vendor/laravel/framework/src/Illuminate/Auth/AuthManager.php(336): PHPOpenSourceSaver\JWTAuth\JWTGuard->__call('viaRemember', Array)
#1 /Users/igor/Sites/invoicequick/vendor/laravel/framework/src/Illuminate/Session/Middleware/AuthenticateSession.php(43): Illuminate\Auth\AuthManager->__call('viaRemember', Array)
#2 /Users/igor/Sites/invoicequick/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(180): Illuminate\Session\Middleware\AuthenticateSession->handle(Object(Illuminate\Http\Request), Object(Closure))
#3 /Users/igor/Sites/invoicequick/vendor/laravel/framework/src/Illuminate/Auth/Middleware/Authenticate.php(44): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#4 /Users/igor/Sites/invoicequick/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(180): Illuminate\Auth\Middleware\Authenticate->handle(Object(Illuminate\Http\Request), Object(Closure), 'api')
#5 /Users/igor/Sites/invoicequick/vendor/laravel/framework/src/Illuminate/View/Middleware/ShareErrorsFromSession.php(49): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#6 /Users/igor/Sites/invoicequick/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(180): Illuminate\View\Middleware\ShareErrorsFromSession->handle(Object(Illuminate\Http\Request), Object(Closure))
#7 /Users/igor/Sites/invoicequick/vendor/laravel/framework/src/Illuminate/Session/Middleware/StartSession.php(121): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#8 /Users/igor/Sites/invoicequick/vendor/laravel/framework/src/Illuminate/Session/Middleware/StartSession.php(64): Illuminate\Session\Middleware\StartSession->handleStatefulRequest(Object(Illuminate\Http\Request), Object(Illuminate\Session\Store), Object(Closure))
#9 /Users/igor/Sites/invoicequick/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(180): Illuminate\Session\Middleware\StartSession->handle(Object(Illuminate\Http\Request), Object(Closure))
#10 /Users/igor/Sites/invoicequick/vendor/laravel/framework/src/Illuminate/Cookie/Middleware/AddQueuedCookiesToResponse.php(37): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#11 /Users/igor/Sites/invoicequick/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(180): Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse->handle(Object(Illuminate\Http\Request), Object(Closure))
#12 /Users/igor/Sites/invoicequick/vendor/laravel/framework/src/Illuminate/Cookie/Middleware/EncryptCookies.php(67): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#13 /Users/igor/Sites/invoicequick/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(180): Illuminate\Cookie\Middleware\EncryptCookies->handle(Object(Illuminate\Http\Request), Object(Closure))
#14 /Users/igor/Sites/invoicequick/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(116): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#15 /Users/igor/Sites/invoicequick/vendor/laravel/framework/src/Illuminate/Routing/Router.php(726): Illuminate\Pipeline\Pipeline->then(Object(Closure))
#16 /Users/igor/Sites/invoicequick/vendor/laravel/framework/src/Illuminate/Routing/Router.php(703): Illuminate\Routing\Router->runRouteWithinStack(Object(Illuminate\Routing\Route), Object(Illuminate\Http\Request))
#17 /Users/igor/Sites/invoicequick/vendor/laravel/framework/src/Illuminate/Routing/Router.php(667): Illuminate\Routing\Router->runRoute(Object(Illuminate\Http\Request), Object(Illuminate\Routing\Route))
#18 /Users/igor/Sites/invoicequick/vendor/laravel/framework/src/Illuminate/Routing/Router.php(656): Illuminate\Routing\Router->dispatchToRoute(Object(Illuminate\Http\Request))
#19 /Users/igor/Sites/invoicequick/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(190): Illuminate\Routing\Router->dispatch(Object(Illuminate\Http\Request))
#20 /Users/igor/Sites/invoicequick/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(141): Illuminate\Foundation\Http\Kernel->Illuminate\Foundation\Http\{closure}(Object(Illuminate\Http\Request))
#21 /Users/igor/Sites/invoicequick/vendor/livewire/livewire/src/DisableBrowserCache.php(19): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#22 /Users/igor/Sites/invoicequick/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(180): Livewire\DisableBrowserCache->handle(Object(Illuminate\Http\Request), Object(Closure))
#23 /Users/igor/Sites/invoicequick/vendor/barryvdh/laravel-debugbar/src/Middleware/InjectDebugbar.php(59): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#24 /Users/igor/Sites/invoicequick/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(180): Barryvdh\Debugbar\Middleware\InjectDebugbar->handle(Object(Illuminate\Http\Request), Object(Closure))
#25 /Users/igor/Sites/invoicequick/vendor/fruitcake/laravel-cors/src/HandleCors.php(52): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#26 /Users/igor/Sites/invoicequick/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(180): Fruitcake\Cors\HandleCors->handle(Object(Illuminate\Http\Request), Object(Closure))
#27 /Users/igor/Sites/invoicequick/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php(21): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#28 /Users/igor/Sites/invoicequick/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TrimStrings.php(40): Illuminate\Foundation\Http\Middleware\TransformsRequest->handle(Object(Illuminate\Http\Request), Object(Closure))
#29 /Users/igor/Sites/invoicequick/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(180): Illuminate\Foundation\Http\Middleware\TrimStrings->handle(Object(Illuminate\Http\Request), Object(Closure))
#30 /Users/igor/Sites/invoicequick/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/ValidatePostSize.php(27): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#31 /Users/igor/Sites/invoicequick/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(180): Illuminate\Foundation\Http\Middleware\ValidatePostSize->handle(Object(Illuminate\Http\Request), Object(Closure))
#32 /Users/igor/Sites/invoicequick/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/PreventRequestsDuringMaintenance.php(86): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#33 /Users/igor/Sites/invoicequick/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(180): Illuminate\Foundation\Http\Middleware\PreventRequestsDuringMaintenance->handle(Object(Illuminate\Http\Request), Object(Closure))
#34 /Users/igor/Sites/invoicequick/vendor/laravel/framework/src/Illuminate/Http/Middleware/TrustProxies.php(39): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#35 /Users/igor/Sites/invoicequick/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(180): Illuminate\Http\Middleware\TrustProxies->handle(Object(Illuminate\Http\Request), Object(Closure))
#36 /Users/igor/Sites/invoicequick/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(116): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#37 /Users/igor/Sites/invoicequick/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(165): Illuminate\Pipeline\Pipeline->then(Object(Closure))
#38 /Users/igor/Sites/invoicequick/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(134): Illuminate\Foundation\Http\Kernel->sendRequestThroughRouter(Object(Illuminate\Http\Request))
#39 /Users/igor/Sites/invoicequick/vendor/laravel/framework/src/Illuminate/Foundation/Testing/Concerns/MakesHttpRequests.php(545): Illuminate\Foundation\Http\Kernel->handle(Object(Illuminate\Http\Request))
#40 /Users/igor/Sites/invoicequick/vendor/laravel/framework/src/Illuminate/Foundation/Testing/Concerns/MakesHttpRequests.php(511): Illuminate\Foundation\Testing\TestCase->call('GET', 'https://invoice...', Array, Array, Array, Array, '[]')
#41 /Users/igor/Sites/invoicequick/vendor/laravel/framework/src/Illuminate/Foundation/Testing/Concerns/MakesHttpRequests.php(324): Illuminate\Foundation\Testing\TestCase->json('GET', 'https://invoice...', Array, Array)
#42 /Users/igor/Sites/invoicequick/tests/Feature/Customer/CustomerTest.php(82): Illuminate\Foundation\Testing\TestCase->getJson('https://invoice...')
#43 /Users/igor/Sites/invoicequick/vendor/phpunit/phpunit/src/Framework/TestCase.php(1548): Tests\Feature\Customer\CustomerTest->test_if_user_can_get_api_response()
#44 /Users/igor/Sites/invoicequick/vendor/phpunit/phpunit/src/Framework/TestCase.php(1154): PHPUnit\Framework\TestCase->runTest()
#45 /Users/igor/Sites/invoicequick/vendor/phpunit/phpunit/src/Framework/TestResult.php(728): PHPUnit\Framework\TestCase->runBare()
#46 /Users/igor/Sites/invoicequick/vendor/phpunit/phpunit/src/Framework/TestCase.php(904): PHPUnit\Framework\TestResult->run(Object(Tests\Feature\Customer\CustomerTest))
#47 /Users/igor/Sites/invoicequick/vendor/phpunit/phpunit/src/Framework/TestSuite.php(673): PHPUnit\Framework\TestCase->run(Object(PHPUnit\Framework\TestResult))
#48 /Users/igor/Sites/invoicequick/vendor/phpunit/phpunit/src/Framework/TestSuite.php(673): PHPUnit\Framework\TestSuite->run(Object(PHPUnit\Framework\TestResult))
#49 /Users/igor/Sites/invoicequick/vendor/phpunit/phpunit/src/Framework/TestSuite.php(673): PHPUnit\Framework\TestSuite->run(Object(PHPUnit\Framework\TestResult))
#50 /Users/igor/Sites/invoicequick/vendor/phpunit/phpunit/src/TextUI/TestRunner.php(673): PHPUnit\Framework\TestSuite->run(Object(PHPUnit\Framework\TestResult))
#51 /Users/igor/Sites/invoicequick/vendor/phpunit/phpunit/src/TextUI/Command.php(144): PHPUnit\TextUI\TestRunner->run(Object(PHPUnit\Framework\TestSuite), Array, Array, true)
#52 /Users/igor/Sites/invoicequick/vendor/phpunit/phpunit/src/TextUI/Command.php(97): PHPUnit\TextUI\Command->run(Array, true)
#53 /Users/igor/Sites/invoicequick/vendor/phpunit/phpunit/phpunit(98): PHPUnit\TextUI\Command::main()
#54 {main}
bug