sophie-spec / versus
A proof-of-concept unit tester for callables
Installs: 4
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
pkg:composer/sophie-spec/versus
Requires
- php: >=7.4.0
- sophie-spec/ensure: ^0.1.1
Requires (Dev)
- consolidation/robo: ^2.0
- friendsofphp/php-cs-fixer: ^2.16
- mockery/mockery: ^1.3
- phlak/semver: ^3.0
- phpmd/phpmd: ^2.8
- phpro/grumphp: ^0.17.1
- povils/phpmnd: ^2.1
- sebastian/phpcpd: ^4.1
- sensiolabs/security-checker: ^6.0
- vimeo/psalm: ^3.7
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.