简体   繁体   中英

Error in PHPUnit but not in app when updating to Laravel 5.4

I'm updating from Laravel 5.3 to 5.4

I get my composer update working fine, and it seems that my app is ok.

But when I run my tests with PHPUnit, all tests fails.

EDIT:

Now, based on patricus response, I installed browser-kit-testing and made everything required on the docs.

Issue is still happening...

Here are the new stacks:

TypeError: Argument 1 passed to Illuminate\Auth\SessionGuard::setRequest() must be an instance of Symfony\Component\HttpFoundation\Request, null given, called in /laravel/vendor/laravel/framework/src/Illuminate/Auth/AuthManager.php on line 139

/laravel/vendor/laravel/framework/src/Illuminate/Auth/SessionGuard.php:768
/laravel/vendor/laravel/framework/src/Illuminate/Auth/AuthManager.php:139
/laravel/vendor/laravel/framework/src/Illuminate/Auth/AuthManager.php:96
/laravel/vendor/laravel/framework/src/Illuminate/Auth/AuthManager.php:70
/laravel/vendor/laravel/framework/src/Illuminate/Auth/AuthManager.php:294
/laravel/vendor/sentry/sentry-laravel/src/Sentry/SentryLaravel/SentryLaravelServiceProvider.php:83
/laravel/vendor/laravel/framework/src/Illuminate/Container/Container.php:678
/laravel/vendor/laravel/framework/src/Illuminate/Container/Container.php:565
/laravel/vendor/laravel/framework/src/Illuminate/Foundation/Application.php:702
/laravel/vendor/laravel/framework/src/Illuminate/Foundation/helpers.php:105
/laravel/vendor/sentry/sentry-laravel/src/Sentry/SentryLaravel/SentryLaravelServiceProvider.php:45
/laravel/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php:28
/laravel/vendor/laravel/framework/src/Illuminate/Support/helpers.php:912
/laravel/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php:86
/laravel/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php:30
/laravel/vendor/laravel/framework/src/Illuminate/Container/Container.php:524
/laravel/vendor/laravel/framework/src/Illuminate/Foundation/Application.php:762
/laravel/vendor/laravel/framework/src/Illuminate/Foundation/Application.php:745
/laravel/vendor/laravel/framework/src/Illuminate/Foundation/Application.php:746
/laravel/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/BootProviders.php:17
/laravel/vendor/laravel/framework/src/Illuminate/Foundation/Application.php:208
/laravel/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php:160
/laravel/tests/BrowserKitTest.php:24
/laravel/vendor/laravel/browser-kit-testing/src/TestCase.php:95
/laravel/vendor/laravel/browser-kit-testing/src/TestCase.php:70
/laravel/tests/functional/RoundRobinTreeTest.php:22

Here is my RoundRobinTest:

class RoundRobinTreeTest extends BrowserKitTest
{
....
} 

and in my tests folder, I copied the old TestCase.php to BrowserKitTest.php

    use Laravel\BrowserKitTesting\TestCase as BaseTestCase;


abstract class BrowserKitTest extends BaseTestCase
{
....
}

Laravel 5.4 updated the testing framework it uses. Laravel 5.4 uses Laravel Dusk, whereas Laravel 5.3 uses Symfony's browserkit component.

The Laravel 5.3 browserkit testing functionality was extracted to its own package ( laravel/browser-kit-testing ), so that you can require the package and have your 5.3 tests work in 5.4. The upgrade instructions in Laravel's documentation explain more.

Basically, pull in the laravel/browser-kit-testing package, and change your TestCase file to extend Laravel\\BrowserKitTesting\\TestCase , and your tests should work as they did in 5.3.


Edit

As best I can tell, you're using the wrong Kernel .

In your stacktrace, Illuminate/Auth/AuthManager.php:139 is this line:

$guard->setRequest($this->app->refresh('request', $guard, 'setRequest'));

That means $this->app->refresh('request', $guard, 'setRequest') is returning null (according to your error message "null given"). $this->app->refresh() will return null when the item being refreshed ( 'request' ) has not been bound yet.

Earlier in your stacktrace shows that your tests/BrowserKitTest.php file is calling bootstrap() on the Illuminate\\Foundation\\Http\\Kernel . The problem with this is that there is nothing in the Http kernel's bootstrapers that binds the 'request' instance.

You should be calling bootstrap() on the Illuminate\\Foundation\\Console\\Kernel , as one of its bootstrappers is Illuminate\\Foundation\\Bootstrap\\SetRequestForConsole , which does provide a binding for the 'request' instance.

Additionally, the Console kernel is the kernel specified by the original TestCase file provided by Laravel.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM