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';
}
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);
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With