Hi all,
I hope someone can help me. This is my first project practising a mixture of TDD/BDD (I'll get to DDD once I've mastered the practice of test first development).
In general it's going great. It's taking considerably longer but I have massive confidence in my code now.
I am now testing the user model and am to the point where I need to unit test the create method. Considering that I do not wan't to touch the extended Eloquent model I am struggling how to separate them.
I have tried a few times. Here are the relevant tests.
public function setUp()
{
// the Eloquent object is mocked but no expectations are set on it as yet
$this->eloquent = m::mock('\Illuminate\Database\Eloquent\Model');
// Only mock the hasOne; all other methods behave as normal
$this->user = m::mock('MPC\Models\User[hasOne]');
}
public function tearDown()
{
m::close();
}
public function testMakeSureThatUsersCanCreateAccountsOk()
{
$this->eloquent
->shouldReceive('create')
->andReturn('newUserObject');
assertEquals('newUserObject', $this->user->create([]));
}
And the Model's method
public static function create(array $attributes = array())
{
$user = parent::create($attributes);
// $user->save();
return $user;
}
I gave up on the test first mantra for this one to makra on this one. I hope someone can see what (if anything) I am doing wrong.
Thanks in advance
John