Phpunit - Why this test fails using FactoryMuff in Laravel 4
I have this simple model User :
<?php
use LaravelBook\Ardent\Ardent;
use Illuminate\Auth\UserInterface;
use Illuminate\Auth\Reminders\RemindableInterface;
class User extends Ardent implements UserInterface, RemindableInterface {
/**
* The attributes excluded from the model's JSON form.
*
* @var array
*/
protected $hidden = array('password');
public static $rules = array(
'username' => 'required|between:4,16',
'email' => 'required|email',
'password' => 'required|alpha_num|min:6|confirmed',
'password_confirmation' => 'required|alpha_num|min:6',
);
public static $factory = array(
'username' => 'string',
'email' => 'email',
'password' => 'password',
'password_confirmation' => 'password',
);
public $autoPurgeRedundantAttributes = true;
public function posts(){
return $this->hasMany('Post');
}
}
And the test :
<?php
use Zizaco\FactoryMuff\Facade\FactoryMuff;
class UserTest extends TestCase {
public function testUsernameIsRequired(){
// $user = new User();
// $user->email = "rafael.adel@dada.com";
// $user->password = "123456";
// $user->password_confirmation = "123456";
$user = FactoryMuff::create('User');
$this->assertEquals($user->username, $user->username);
$this->assertEquals($user->email, $user->email);
$this->assertEquals($user->password, $user->password);
$this->assertFalse($user->save());
$errors = $user->errors()->all();
$this->assertEquals($errors[0], 'The username field is required.');
}
}
?>
Here's my output ::
Time: 126 ms, Memory: 12.25Mb
There was 1 failure:
1) UserTest::testUsernameIsRequired
Failed asserting that two strings are equal.
--- Expected
+++ Actual
@@ @@
-'The password confirmation does not match.'
+'The username field is required.'
/var/www/cribbb/app/tests/Model/UserTest.php:20
FAILURES!
Tests: 2, Assertions: 6, Failures: 1.
Why does the password confirmation fail ? Any help would be appreciated.
No comments:
Post a Comment