$account->shouldReceive('getTotalAmount')->andReturn(2000);
$account->getTotalAmount()->willReturn(2000);
$account->shouldReceive('setTotalAmount')->with(4000)->once();
$account->setTotalAmount(4000)->shouldBeCalled();
Test base on how the code is structured
The behaviour of the methods
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;
}
$account = Mockery::mock('Account');
$account->shouldReceive('getTotalAmount')->andReturn(2000, 2000, 4000);
$user->shouldReceive('setTotalAmount')->with(4000)->once();
add($account, 2000);
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;
}
$account->getTotalAmount()->willReturn(2);
$account->setTotalAmount(Argument::type('integer'))->will(function($args) {
$this->getTotalAmount()->willReturn($args[0]);
});
add($account, 2000);
http://everzet.com/post/72910908762/conceptual-difference-between-mockery-and-prophecy