当我对它进行try/catch时DB::Connection()->getPdo();,我得到错误没有设置外观根.Schema在我尝试添加try/catch之前,我相信它也发生在外墙上.当然,测试目录在app目录之外,我觉得它与它有关,但我还没有成功搞清楚.
以下是发生这种情况的测试类:
<?php
namespace Tests\Models;
use Illuminate\Support\Facades\Schema;
use Illuminate\Support\Facades\DB;
use App\Models\Discussion;
use App\User;
use Business\Database\Model;
use Illuminate\Database\Schema\Blueprint;
use Tests\TestCase;
class DiscussionModelTest extends TestCase
{
/**
* Create the tables this model needs for testing.
*/
public static function setUpBeforeClass()
{
try {
DB::connection()->getPdo();
} catch(\Exception $e) {
die($e->getMessage());
}
Schema::create('discussions', function (Blueprint $table) {
$table->integer('id');
$table->integer('user_id');
$table->foreign('user_id')->references('id')->on('users');
});
Schema::create('users', function (Blueprint $table) {
$table->integer('id');
});
}
}
Run Code Online (Sandbox Code Playgroud)