dongwenyou4298 2017-02-03 20:53
浏览 63
已采纳

更新到Laravel 5.4时PHPUnit出错但在应用程序中出错

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
{
....
}
  • 写回答

1条回答 默认 最新

  • duanniedang3946 2017-02-04 06:57
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算
  • ¥15 java如何提取出pdf里的文字?
  • ¥100 求三轴之间相互配合画圆以及直线的算法
  • ¥100 c语言,请帮蒟蒻写一个题的范例作参考
  • ¥15 名为“Product”的列已属于此 DataTable
  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题