Laravel 5.5: PHPUnit (with coverage) doesn#39;t like routes from multiple files and throws quot;A facade root has not been setquot;. Without coverage it#39;s green(Laravel 5.5:PHPUnit(有覆盖)不喜欢来自多个文件的路由并抛出“尚未设置外观根.没有覆盖它是绿色的) - IT屋-程序员软件开发技
问题描述
我有 Laravel 5.5,我决定在文件中对路由进行分组,以便以更有意义的方式组织它们.
I have Laravel 5.5 where I decided to group routes in files to organise them in a more meaningful way.
这是一个简化的示例 - 网络路由文件位于:
Here's a simplified example - the web route files live in:
static.php 包含:
test.php 包含:
RouteServiceProvider.php 包含:
到目前为止,我可以通过调用 php artisan route:list
来确认一切正常:
Up to now I can confirm that everything works by calling php artisan route:list
:
现在我要写一些测试,但我需要代码覆盖,所以我补充说:
Now I was going to write some tests but I require code coverage, so I added:
进入我的 phpunit.xml
.
当我调用 phpunit
我得到:
在我删除添加到 xml 文件中的覆盖行并再次运行 phpunit
之后,它是绿色的.
Straight after I remove the coverage lines I added to xml file and run phpunit
again - it's green.
$ phpunit PHPUnit 7.0.1,由 Sebastian Bergmann 和贡献者提供.
$ phpunit PHPUnit 7.0.1 by Sebastian Bergmann and contributors.
.. 2/2 (100%)
.. 2 / 2 (100%)
时间:381 毫秒,内存:20.00MB
Time: 381 ms, Memory: 20.00MB
OK(2 个测试,2 个断言)
OK (2 tests, 2 assertions)
怎么了?为什么具有代码覆盖的 phpunit 不喜欢多个文件中的路由(但没有覆盖它工作得很好)?
What's wrong? Why phpunit with code coverage doesn't like routes in multiple files (but without coverage it works perfectly fine)?
推荐答案
有人遇到了同样的问题并通过从代码覆盖范围中排除路由目录.所以我添加到 phpunit.xml
:
Someone had the same issue and fixed that by excluding routes directories from code coverage. So I added into phpunit.xml
:
而 phpunit
覆盖效果很好.
天哪……外墙很棘手.
这篇关于Laravel 5.5:PHPUnit(有覆盖)不喜欢来自多个文件的路由并抛出“尚未设置外观根".没有覆盖它是绿色的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!