1

My test class is very simple

<?php

use Illuminate\Foundation\Testing\WithoutMiddleware;
use Illuminate\Foundation\Testing\DatabaseMigrations;
use Illuminate\Foundation\Testing\DatabaseTransactions;

class ExampleTest extends TestCase
{
    /**
     * A basic functional test example.
     *
     * @return void
     */
    public function testBasicExample()
    {
        $this->visit('/');

    }

    // when I add this, I get an error
    public function testAnotherExample()
    {
        $this->visit('profile');

    }
}

When I only have the "testBasicExample" method, the test runs fine. However, as soon as I add "testAnotherExample", the test fails with following error message.

Fatal error: Cannot redeclare formatBytes() (previously declared in C:\xampp\htdocs\laravellab\helpers\functions.php:3) in C:\xampp\htdocs\laravellab\helpers\functions.php on line 7

Fatal error: Uncaught exception 'Illuminate\Contracts\Container\BindingResolutionException' with message 'Target [Illuminate\Contracts\Debug\ExceptionHandler] is not instantiable.' in C:\xampp\htdocs\laravellab\vendor\laravel\framework\src\Illuminate\Container\Container.php:749
Stack trace:
#0 C:\xampp\htdocs\laravellab\vendor\laravel\framework\src\Illuminate\Container\Container.php(631): Illuminate\Container\Container->build('Illuminate\\Cont...', Array)
#1 C:\xampp\htdocs\laravellab\vendor\laravel\framework\src\Illuminate\Foundation\Application.php(674): Illuminate\Container\Container->make('Illuminate\\Cont...', Array)
#2 C:\xampp\htdocs\laravellab\vendor\laravel\framework\src\Illuminate\Foundation\Bootstrap\HandleExceptions.php(154): Illuminate\Foundation\Application->make('Illuminate\\Cont...')
#3 C:\xampp\htdocs\laravellab\vendor\laravel\framework\src\Illuminate\Foundation\Bootstrap\HandleExceptions.php(79): Illuminate\Foundation\Bootstrap\HandleExceptions->getExceptionHandler()
#4 C:\xampp\htdocs\laravellab\vendor\laravel\framework\src\Illuminate\Container\Container.php on line 749

The same test if I comment out the "testBasicExample", then the other test works just fine.

Thank you for your help.

2
  • helpers\functions.php looks like your own file. How are you loading it, and what does it contain? Commented Feb 10, 2016 at 22:20
  • bingo! thanks for the scrutiny. it had some common functions. changing its include function from include to include_once resolved the problem. Commented Feb 10, 2016 at 22:29

2 Answers 2

1

PHPUnit 5.3.2 above works just fine with Laravel 5.

You need to Uninstall old phpunit first.

sudo apt-get purge phpunit
sudo apt-get purge --auto-remove phpunit

Then install PHPUnit 5.6.1 as below

wget https://phar.phpunit.de/phpunit.phar
chmod +x phpunit.phar
sudo mv phpunit.phar /usr/local/bin/phpunit
phpunit --version

Now you can run phpunit !!!

Sign up to request clarification or add additional context in comments.

Comments

0

answer from @ceejayoz was that :

Fatal error: Cannot redeclare formatBytes() (previously declared in C:\xampp\htdocs\laravellab\helpers\functions.php:3) in C:\xampp\htdocs\laravellab\helpers\functions.php on line 7

was the culprit.

However your solution elixir to go from include to include_once just checks that the include is only declare once which is the classic way to include files in procedural PHP.

I would recommend to autoload the file rather by changing your composer.json file. Just include the logic file path (from where composer.json file is) inside the autoload section

"autoload": {
    "files": ["helpers\functions.php"]

},

https://getcomposer.org/doc/04-schema.md#files

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.