I have a password mutator:
/**
* Mutator for setting the encryption on the user password.
*
* @param $password
*/
public function getPasswordAttribute($password)
{
$this->attributes[ 'password' ] = bcrypt($password);
}
That I'm trying to test:
/**
* A basic check of password mutator.
*
* @return void
*/
public function testCheckPasswordEncryptionUserAttribute()
{
$userFactory = factory('Project\User')->create([
'password' => 'test'
]);
$user = User::first();
$this->assertEquals(bcrypt('test'), $user->password);
}
That when the test runs I get this error:
1) UserTest::testCheckPasswordEncryptionUserAttribute
Failed asserting that null matches expected '$2y$10$iS278efxpv3Pi6rfu4/1eOoVkn4EYN1mFF98scSf2m2WUhrH2kVW6'.
After the test failed I attempted to dd() the password property, but that also failed. My first thought was this might be a mass assignment issue (having just read about that), but password is in $fillable (which makes sense that it would be there), then I noticed $hidden in the User class as well, but after reading about that in the docs, and also removing the password index for $hidden it still produces a null when you try to access the password property.
How would you unit test this mutator, or what have I missed?