2016-03-15 192 views
1

我在Laravel 5.2上,我想第一次运行测试,我知道这个错误已经在SO上讨论过了,但我找不到任何答案。PHP致命错误:类'TestCase'找不到

我运行:

php artisan make:test TerritoryTest 

然后,在项目的根:

phpunit 

但是,我得到这个错误:

PHP Fatal error: Class 'TestCase' not found in /share/tests/TerritoryTest.php on line 8 

那么,谁可以帮忙?

回答

2

我找到了答案,第一:

composer.json我不得不在添加"tests/TestCase.php"

"autoload-dev": { 
     "classmap": [ 
      "tests/TestCase.php" 
     ] 
    }, 

然后,我就手动添加的TestCase.php在测试文件夹:

class TestCase extends Illuminate\Foundation\Testing\TestCase 
{ 
    /** 
    * The base URL to use while testing the application. 
    * 
    * @var string 
    */ 
    protected $baseUrl = 'http://localhost'; 

    /** 
    * Creates the application. 
    * 
    * @return \Illuminate\Foundation\Application 
    */ 
    public function createApplication() 
    { 
     $app = require __DIR__.'/../bootstrap/app.php'; 

     $app->make(Illuminate\Contracts\Console\Kernel::class)->bootstrap(); 

     return $app; 
    } 
} 

我希望这会帮助别人..

相关问题