I'm just learning PHPUnit with Laravel 5.1. I'm using "use DatabaseMigrations" to migrate the test database for each test, which I set in my phpunit.xml:
<php>
...
<env name="DB_DATABASE" value="project_test"/>
...
</php>
I've setup a bunch of basic tests as I go along to check instantiation, factories, etc, but I wanted to check an accessor and a mutator I have in the UserModel:
public function getFullNameAttribute()
{
return $this->first_name . ' ' . $this->last_name;
}
public function getPasswordAttribute($password)
{
$this->attributes[ 'password' ] = bcrypt($password);
}
But when the accessor test runs:
/**
* A basic check of full name accessor.
*
* @return void
*/
public function testCheckFullNameOfUser()
{
$user = User::all();
$this->assertEquals($user->first_name . ' ' . $user->last_name, $user->fullname);
}
I get this error:
1) UserTest::testCheckFullNameOfUser
ErrorException: Trying to get property of non-object
Which seems to suggest that the database hasn't been migrated, and SSHing into Homestead and logging into MySQL and checking the migrations table the test database is empty with no migrations appearing to have occurred.
What have I missed in the documentation to make this work? I can make it pass by just reusing the user factory, but I don't understand why I can't access the test database, does it need to be initially migrated?