Mockery
$account->shouldReceive('getTotalAmount')->andReturn(2000);
Prophecy
$account->getTotalAmount()->willReturn(2000);
Mockery
$account->shouldReceive('setTotalAmount')->with(4000)->once();
Prophecy
$account->setTotalAmount(4000)->shouldBeCalled();
Mockery
Test base on how the code is structured
Prophecy
The behaviour of the methods
Code
public function add($account, $add = 1000)
{
$currentAmount = $account->getTotalAmount();
echo 'You have total amount: ' . $currentAmount;
$account->setTotalAmount($account->getTotalAmount() + $add);
$currentAmount = $account->getTotalAmount();
echo 'You have total amount: ' . $currentAmount;
}
Mockery
$account = Mockery::mock('Account');
$account->shouldReceive('getTotalAmount')->andReturn(2000, 2000, 4000);
$user->shouldReceive('setTotalAmount')->with(4000)->once();
add($account, 2000);
Code Changed
public function add($account, $add = 1000)
{
$currentAmount = $account->getTotalAmount();
echo 'You have total amount: ' . $currentAmount;
$account->setTotalAmount($currentAmount + $add);
$currentAmount = $account->getTotalAmount();
echo 'You have total amount: ' . $currentAmount;
}
Prophecy
$account->getTotalAmount()->willReturn(2);
$account->setTotalAmount(Argument::type('integer'))->will(function($args) {
$this->getTotalAmount()->willReturn($args[0]);
});
add($account, 2000);
Ref
http://everzet.com/post/72910908762/conceptual-difference-between-mockery-and-prophecy
Prophecy
By Tiến Võ Xuân
Prophecy
- 764