我有一个新的Laravel 样板在运行完美的Laravel Homestead环境中运行。该php -v
命令正在向我返回此信息
PHP 7.1.2-3+deb.sury.org~xenial+1 (cli) (built: Feb 22 2017 10:08:33) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.1.0, Copyright (c) 1998-2017 Zend Technologies
with Zend OPcache v7.1.2-3+deb.sury.org~xenial+1, Copyright (c) 1999-2017, by Zend Technologies
with blackfire v1.14.3~linux-x64-non_zts71, https://blackfire.io, by Blackfireio Inc.
我正在搜索如何设置 phpunit 的代码覆盖率以使其工作,并发现我需要 xDebug 才能使其工作。谷歌搜索了一下,找到了xon
启用 xDebug 扩展的 homestead 命令。所以我运行它,发现 xDebug 扩展已启用,如新php -v
显示:
PHP 7.1.2-3+deb.sury.org~xenial+1 (cli) (built: Feb 22 2017 10:08:33) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.1.0, Copyright (c) 1998-2017 Zend Technologies
with Zend OPcache v7.1.2-3+deb.sury.org~xenial+1, Copyright (c) 1999-2017, by Zend Technologies
with Xdebug v2.5.0, Copyright (c) 2002-2016, by Derick Rethans
with blackfire v1.14.3~linux-x64-non_zts71, https://blackfire.io, by Blackfireio Inc.
我还需要添加 php-code-coverage 依赖项composer require --dev phpunit/php-code-coverage:4.0.8
(特定版本,因为我在尝试安装最新版本时遇到了一些要求错误)。
然后我跑了phpunit --coverage-clover=coverage.xml
,得到了这个致命错误:
PHPUnit 5.7.19 by Sebastian Bergmann and contributors.
PHP Fatal error: Uncaught Error: Class 'Breadcrumbs' not found in /home/vagrant/servirme/app/Http/Breadcrumbs/Backend/Access/User.php:3
Stack trace:
#0 /home/vagrant/servirme/app/Http/Breadcrumbs/Backend/Access.php(3): require()
#1 /home/vagrant/servirme/vendor/phpunit/php-code-coverage/src/CodeCoverage.php(1083): include_once('/home/vagrant/s...')
#2 /home/vagrant/servirme/vendor/phpunit/php-code-coverage/src/CodeCoverage.php(256): SebastianBergmann\CodeCoverage\CodeCoverage->initializeData()
#3 /home/vagrant/servirme/vendor/phpunit/phpunit/src/Framework/TestResult.php(650): SebastianBergmann\CodeCoverage\CodeCoverage->start(Object(AccessHelperTest))
#4 /home/vagrant/servirme/vendor/phpunit/phpunit/src/Framework/TestCase.php(860): PHPUnit_Framework_TestResult->run(Object(AccessHelperTest))
#5 /home/vagrant/servirme/vendor/phpunit/phpunit/src/Framework/TestSuite.php(722): PHPUnit_Framework_TestCase->run(Object(PHPUnit_Framework_TestResult))
#6 /home/vagrant/servirme/vendor/phpunit/phpunit/src/Framework/TestSuite.php(722): PHP in /home/vagrant/servirme/app/Http/Breadcrumbs/Backend/Access/User.php on line 3
Fatal error: Uncaught Error: Class 'Breadcrumbs' not found in /home/vagrant/servirme/app/Http/Breadcrumbs/Backend/Access/User.php on line 3
Error: Class 'Breadcrumbs' not found in /home/vagrant/servirme/app/Http/Breadcrumbs/Backend/Access/User.php on line 3
Call Stack:
0.0005 350872 1. {main}() /home/vagrant/servirme/vendor/phpunit/phpunit/phpunit:0
0.0736 562656 2. PHPUnit_TextUI_Command::main() /home/vagrant/servirme/vendor/phpunit/phpunit/phpunit:52
0.0736 562768 3. PHPUnit_TextUI_Command->run() /home/vagrant/servirme/vendor/phpunit/phpunit/src/TextUI/Command.php:116
0.3058 1886960 4. PHPUnit_TextUI_TestRunner->doRun() /home/vagrant/servirme/vendor/phpunit/phpunit/src/TextUI/Command.php:186
0.5521 1993968 5. PHPUnit_Framework_TestSuite->run() /home/vagrant/servirme/vendor/phpunit/phpunit/src/TextUI/TestRunner.php:517
0.5558 1994968 6. PHPUnit_Framework_TestSuite->run() /home/vagrant/servirme/vendor/phpunit/phpunit/src/Framework/TestSuite.php:722
0.5598 1995536 7. PHPUnit_Framework_TestCase->run() /home/vagrant/servirme/vendor/phpunit/phpunit/src/Framework/TestSuite.php:722
0.5599 1995536 8. PHPUnit_Framework_TestResult->run() /home/vagrant/servirme/vendor/phpunit/phpunit/src/Framework/TestCase.php:860
0.5704 2003832 9. SebastianBergmann\CodeCoverage\CodeCoverage->start() /home/vagrant/servirme/vendor/phpunit/phpunit/src/Framework/TestResult.php:650
0.5704 2003832 10. SebastianBergmann\CodeCoverage\CodeCoverage->initializeData() /home/vagrant/servirme/vendor/phpunit/php-code-coverage/src/CodeCoverage.php:256
0.6267 2193768 11. include_once('/home/vagrant/servirme/app/Http/Breadcrumbs/Backend/Access.php') /home/vagrant/servirme/vendor/phpunit/php-code-coverage/src/CodeCoverage.php:1083
0.6278 2194104 12. require('/home/vagrant/servirme/app/Http/Breadcrumbs/Backend/Access/User.php') /home/vagrant/servirme/app/Http/Breadcrumbs/Backend/Access.php:3
我感觉这与 Laravel Facades 有关,这让我认为 phpunit 没有运行我的自动加载文件,但该属性默认bootstrap="bootstrap/autoload.php"
存在于文件中。phpunit.xml
不知道从哪里开始,不知道哪里出了问题。
编辑:我的宅基地版本是 5.1.0