PHPUnit code coverage in PhpStorm does not bootstrap Laravel
I'm having a strange problem on Laravel 5.5. I'm using PhpStorm and am trying to use it to make a phpunit
call on my Vagrant host to PHPUnit like this:
vagrant:///Users/mymachine/Webdev/project/usr/bin/php -dxdebug.coverage_enable=1 /home/vagrant/project/vendor/phpunit/phpunit/phpunit --coverage-clover /home/vagrant/.phpstorm_helpers/project_AdminLoginTest_coverage --bootstrap /home/vagrant/project/bootstrap/app.php --configuration /home/vagrant/project/phpunit.xml TestsIntegrationAuthenticationAdminLoginTest /home/vagrant/project/tests/Integration/Authentication/AdminLoginTest.php --teamcity
I've defined my default configuration file to be the phpunit.xml
file that comes with Laravel by default, and running tests normally without coverage works just fine. It's whenever I try to make use of code coverage that it starts failing with the following error:
Uncaught Error: Class 'Route' not found in /home/vagrant/project/app/routes.php:5
The reason for this is because it's not loading the Facade properly and is likely not even booting Laravel.
Has anyone got this to work before? If so how?
I am using a setUp()
call, it's defined as such
protected function setUp()
{
parent::setUp(); // Must run first, Laravel is set up using this parent call //
/** @var AdminModel $user */
$this->user = $this->createAdmin();
}
I do run setUp()
from the parent first as that is supposed to call createApplication()
which should take care of booting Laravel if I'm not mistaken.
I've set up Xdebug on my Vagrant machine on both FPM and CLI as well, and PhpStorm successfully reports that it can detect Xdebug 2.5.5
on my Vagrant box via CLI, so I'm ruling that out as a possibility unless I need to install something extra for the Coverage.
My phpunit.xml
also sets up the bootstrap/app.php
file in it's bootstrap definition, which is the Laravel default, so that should work fine and the fact that it works without the coverage confuses me.
Am I missing something here? Thank you for your help. Let me know if I'm missing some details you need.
After much trial and error i figured it out, so, the problem is that my PHPUnit code coverage in this case is including the routes.php
and PHPUnit's XDebug used for the code coverage feature fails to understand the Facade usage in this file (guess it's booted too early? would appreciate clarification if anyone knows why this is)
Note that this is only an issue because i have a custom routes.php file inside my App
directory, the way to make this work is to just tell PHPUnit to exclude this specific routes file from the Whitelist that Laravel defines.
<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">./app/API</directory>
<exclude>
<file>./app/API/routes.php</file>
</exclude>
</whitelist>
</filter>
For me it looks like that, after you exclude that file the Code Coverage should work fine provided that you have XDebug installed, the other Facades are loaded just fine, so i'm guessing the one in routes.php
doesn't because that's loaded earlier in the lifecycle of Laravel.
Hope this helps someone in the future :)
链接地址: http://www.djcxy.com/p/83202.html上一篇: laravel 4.2模型多态函数