Alexander Cogneau
Alexander Cogneau

Reputation: 1274

Why having more than one test method in a file using Laravel raises error?

when I have more than one test in a testfile with laravel, and I execute them I get:

Fatal error: Cannot redeclare nameSort() (previously declared in C:\wamp\www\project\app\start\global.php:110) in C:\wamp\www\project\app\start\global.php on line 112

This is even when this is my testfile:

class DealControllerTest extends TestCase {

    public function testIndex()
    {
        $this->assertTrue(true);
    }

    public function testApiKey()
    {
        $this->assertTrue(true);
    }
}

Upvotes: 4

Views: 1426

Answers (2)

Leon W
Leon W

Reputation: 61

I was able to solve the issue by replacing require with require_once for includes in the global.php file.

For example,

require app_path().'/helpers.php';

should be

require_once app_path().'/helpers.php';

Upvotes: 6

Alexander Cogneau
Alexander Cogneau

Reputation: 1274

The cause were custom helper functions declared in global.php, I had to put them in a separate class to solve the error. So if you have any helper functions, put them in a helper class and autoload it by adding it to composer.json.

Upvotes: 1

Related Questions