Search code examples
phplaravelunit-testingphpunitlaravel-5.3

How to solve Fatal error: Cannot redeclare view() (previously declared? (phpunit laravel 5.3)


When I run ./vendor/bin/phpunit to check my event & listener, there exist error like this :

Fatal error: Cannot redeclare view() (previously declared in C:\xampp\htdocs\myshop\vendor\laravel\framework\src\Illuminate\Foundation\helpers.php:850) in C:\xampp\htdocs\myshop\app\Http\helpers.php on line 92 PHP Fatal error: Cannot redeclare view() (previously declared in C:\xampp\htdocs\myshop\vendor\laravel\framework\src\Illuminate\Foundation\helpers.php:850) in C:\xampp\htdocs\myshop\app\Http\helpers.php on line 92

How can I solve it?


Solution

  • you can use this code

     if (!function_exists('view')) {
        function view()
        {
            //your code here
        }
        }
    

    or you can use

    include_once() or require_once() // your file where you include , so change it and replace it hope it will work