elliotchance / concise

✅ Concise is test framework for using plain English and minimal code, built on PHPUnit.
MIT License
45 stars 3 forks source link

Saved mocks #75

Open elliotchance opened 9 years ago

elliotchance commented 9 years ago

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);
}
elliotchance commented 9 years ago

When recording a mock it assumes that;