A saved mock allows easy and verifiable mocks between integration (or expensive logic) and unit (cheap logic) tests:
public function test1()
{
$calc = $this->niceMock('Calculator')
->saveAs('calc')
->done();
$this->assert($calc->add(3, 5), equals, 8);
}
public function test2()
{
$calc = $this->savedMock('calc');
// add(3, 5) was prerecorded as returning 8
$this->assert($calc->add(3, 5), equals, 8);
// add(3, 7) was not recorded so it has to go back to the original object to calculate it
$this->assert($calc->add(3, 7), equals, 10);
}
A saved mock allows easy and verifiable mocks between integration (or expensive logic) and unit (cheap logic) tests: