在Mac上的Vagrant机器内运行Laravel 5.1。当我尝试运行phpunit:
./vendor/bin/phpunit
我收到以下错误:
PHP Fatal error: Cannot redeclare view() (previously declared in /vagrant/REPO/vendor/laravel/framework/src/Illuminate/Foundation/helpers.php:743) in /vagrant/REPO/bootstrap/CustomGlobals.php on line 51
PHP Stack trace:
PHP 1. {main}() /vagrant/REPO/vendor/phpunit/phpunit/phpunit:0
PHP 2. PHPUnit_TextUI_Command::main() /vagrant/REPO/vendor/phpunit/phpunit/phpunit:47
PHP 3. PHPUnit_TextUI_Command->run() /vagrant/REPO/vendor/phpunit/phpunit/src/TextUI/Command.php:109
PHP 4. PHPUnit_TextUI_Command->handleArguments() /vagrant/REPO/vendor/phpunit/phpunit/src/TextUI/Command.php:120
PHP 5. PHPUnit_TextUI_Command->handleBootstrap() /vagrant/REPO/vendor/phpunit/phpunit/src/TextUI/Command.php:633
PHP 6. PHPUnit_Util_Fileloader::checkAndLoad() /vagrant/REPO/vendor/phpunit/phpunit/src/TextUI/Command.php:804
PHP 7. PHPUnit_Util_Fileloader::load() /vagrant/REPO/vendor/phpunit/phpunit/src/Util/Fileloader.php:38
PHP 8. include_once() /vagrant/REPO/vendor/phpunit/phpunit/src/Util/Fileloader.php:56
helper.php中的View函数包含在function_exists块中:
if (! function_exists('view')) {
/**
* Get the evaluated view contents for the given view.
*
* @param string $view
* @param array $data
* @param array $mergeData
* @return \Illuminate\View\View|\Illuminate\Contracts\View\Factory
*/
function view($view = null, $data = [], $mergeData = [])
{
// there is code here
}
}
自定义全局变量中的视图函数已经到位,因为我们想要一种通过区域设置轻松分离视图文件的方法。
function view($view = null, $data = [], $mergeData = [])
{
// Code here too....
} // <- This is line 51.
当然,在浏览器中浏览网站,一切都很好。没问题。我的第一个假设是phpunit以不同的方式加载框架。它首先加载helper.php方法,而不是自定义全局方法。如果我在浏览器中,它首先加载自定义全局视图方法。如果停止使用helper.php方法,则该函数存在。
我甚至不知道这是否有意义?
其他一些细节:我们有phpunit工作。然后我们深入到behat / mink,现在它正在工作,phpunit给出了这个错误。我的第二个假设是,版本化让behat / mink与laravel一起玩得很好同时翻转了一些现在导致phpunit不起作用的东西?或者以不同的方式工作?
我的一些composer.json文件:
"require": {
"laravel/framework": "5.1.*",
"barryvdh/laravel-debugbar": "~2.0",
"xinax/laravel-gettext": "^3.0.3",
"doctrine/dbal": "2.3.5",
"propel/propel": "^2.0@dev",
"barryvdh/laravel-ide-helper": "~2.0",
"intervention/image": "dev-master",
"intervention/imagecache": "~2.1",
"braintree/braintree_php" : "^3.1.0",
"tecnick.com/tcpdf" : "^6.0",
"zendframework/zend-cache" : "^2.5",
"zendframework/zend-i18n" : "^2.5",
"illuminate/html": "^5.0"
},
"require-dev": {
"phpunit/phpunit": "5.*",
"phpunit/dbunit" : ">=1.2",
"phpspec/phpspec": "~2.1",
"laracasts/integrated": "^0.15.6",
"mockery/mockery": "dev-master"
},
对此的任何指示都将非常感激。我错过了什么?感谢。