【发布时间】:2016-05-21 11:52:06
【问题描述】:
我的测试类很简单
<?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');
}
}
当我只有“testBasicExample”方法时,测试运行良好。但是,只要我添加“testAnotherExample”,测试就会失败并显示以下错误消息。
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
如果我注释掉“testBasicExample”,相同的测试,那么另一个测试就可以了。
感谢您的帮助。
【问题讨论】:
-
helpers\functions.php看起来像您自己的文件。你是如何加载它的,它包含什么? -
宾果游戏!感谢您的审查。它有一些共同的功能。将其包含功能从 include 更改为 include_once 解决了问题。
标签: unit-testing laravel