You Are Here: Home » Documentation » Scenario Testing

Enhance PHP Unit Testing And Mocking Framework improve the quality

Scenario Testing

Scenario testing lets you repeat a test many times, with different input and expected outputs, without writing much code.

If you find yourself repeating the same test multiple times, you might find that a scenario test will save you lots of lines of code. The example below replaces five individual tests with a single test that runs the five different scenarios.

class ScenarioTestFixture extends \Enhance\TestFixture
{
    public function addTwoNumbersWithScenariosExpectReturnValues()
    {
        $target = \Enhance\Core::getCodeCoverageWrapper('ScenarioExampleClass');
        $scenario = \Enhance\Core::getScenario($target, 'addTwoNumbers');
        $scenario->with(1, 2)->expect(3);
        $scenario->with(3, 4)->expect(7);
        $scenario->with(3, -4)->expect(-1);
        $scenario->with(-3, -4)->expect(-7);
        $scenario->with(3.14, 4.14)->expect(7.28);
        $scenario->VerifyExpectations();
    }
}