Running Laravel 5.1 inside a Vagrant machine on a Mac. When I try to run phpunit:
./vendor/bin/phpunit
I get the following error:
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
the View function in helper.php is wrapped in a function_exists block:
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
}
}
The view function in custom globals is in place because we wanted a way to easily separate view files by locales.
function view($view = null, $data = [], $mergeData = [])
{
// Code here too....
} // <- This is line 51.
Of course browsing the site in a browser, everything is ok. No issues at all. My first hypothesis is that phpunit is loading the framework in a different way. It loads the helper.php method first, than the custom global. Where if I am in a browser, it loads the custom global view method first. Then the function exists if stops the helper.php method from being used.
I don't even know if that makes any sense?
Some other details: We had phpunit working. Then we dipped into behat/mink and now that's working, phpunit gives this error. My second hypothesis is that the versioning to get behat/mink playing nice with laravel at the same time flipped something that now causes phpunit to not work? Or work in a different way?
Some of my composer.json file:
"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"
},
Any direction on this would be very much appreciated. What am I missing? Thanks.