sophie-spec/versus

A proof-of-concept unit tester for callables

0.1.4 2020-03-28 17:53 UTC

This package is auto-updated.

Last update: 2024-03-29 03:52:22 UTC


README

Like Ensure, Versus is born with the thought that an ideal unit test should be a strict equality between the output of a function and its expected result. Versus enlarges Ensure tool so we can verify several inputs/ouputs with ease.

Install

composer require --dev sophie-spec/versus

Requires PHP >= 7.4.

Use

To test a method with several inputs/outputs, we simply pass the callable and yield values from a generator:

use function Sophie\Versus\versus;

$add = function ($a, $b) {
    return $a + $b;
};

versus($add, function () {
    yield [1, 2] => 3;
    yield [-2, -3] => -5;
    yield [10, -20] => -10;
});

If the assertion fails, a Sophie\Ensure\FailedAssertionException error is thrown with a detailed message:

versus($add, function () {
    yield [1, 2] => 100;
});
/*
    Both values are not equal.

    Provided value:
        3

    Expected value:
        100
*/

License

MIT.