Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Eloquent class not found when testing new models

I'm trying to test my eloquent models but my tests keep failing with "Class 'Eloquent' not found" errors. If I add a route that uses my eloquent model and simply prints some of the information stored in the database, everything works fine. It is only when trying to run phpunit that I get the issues with eloquent not being found. My model is in app/models so it should be included in the composer classmap and I've done composer dump-autoload. I'm sure I'm overlooking something really obvious but I can't pick it out. Any idea what the issue is?

My test:

class GameTest extends TestCase {

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

    public function testGameInstance(){
        $this->assertInstanceOf('Game', $this->game);
    }
}

My model:

class Game extends Eloquent{

    protected $table = 'gm_game';
    protected $primaryKey = 'game_id';
}
like image 842
vikingsfan19 Avatar asked Jun 10 '13 15:06

vikingsfan19


1 Answers

Try adding parent::setUp() in your test's setUp function. This solved the issue for me.

Example:

class GameTest extends TestCase {

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

    public function testGameInstance(){
        $this->assertInstanceOf('Game', $this->game);
    }
}
like image 75
raindancelab Avatar answered Sep 18 '22 11:09

raindancelab