测试新模型时未找到雄辩的类

vik*_*n19 6 phpunit laravel eloquent laravel-4

我正在尝试测试我雄辩的模型,但我的测试仍然失败了"Class'Eloquent'not found'错误.如果我添加一个使用我的雄辩模型的路线并简单地打印存储在数据库中的一些信息,一切正常.只有在尝试运行phpunit时,才会发现eloquent没有被发现的问题.我的模型在应用程序/模型中,所以它应该包含在作曲家类图中,我已经完成了composer dump-autoload.我敢肯定我忽略了一些非常明显但我无法理解的东西.知道问题是什么吗?

我的测试:

class GameTest extends TestCase {

    public function setUp(){
        $this->game = Game::find(1);
    }

    public function testGameInstance(){
        $this->assertInstanceOf('Game', $this->game);
    }
}
Run Code Online (Sandbox Code Playgroud)

我的模特:

class Game extends Eloquent{

    protected $table = 'gm_game';
    protected $primaryKey = 'game_id';
}
Run Code Online (Sandbox Code Playgroud)

小智 26

尝试在test的setUp函数中添加parent :: setUp().这解决了我的问题.

例:

class GameTest extends TestCase {

    public function setUp(){
       parent::SetUp();
       $this->game = Game::find(1);
    }

    public function testGameInstance(){
        $this->assertInstanceOf('Game', $this->game);
    }
}
Run Code Online (Sandbox Code Playgroud)

  • 就像再次查看文档一样容易.http://laravel.com/docs/testing (2认同)