sophie-spec / ensure
Ensure that both arguments are equal
0.1.8
2020-03-28 17:48 UTC
Requires
- php: >=7.4.0
- symfony/var-dumper: ^5.0
Requires (Dev)
- consolidation/robo: ^2.0
- friendsofphp/php-cs-fixer: ^2.16
- 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
Ensure 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. Then, Ensure is that base tool for anything to test.
Install
composer require --dev sophie-spec/ensure
Requires PHP >= 7.4.
Use
use function Sophie\Ensure\ensure; $add = function ($a, $b) { return $a + $b; }; ensure($add(1, 2), 3);
If the assertion fails, a Sophie\Ensure\FailedAssertionException
error is thrown with a detailed message:
ensure($add(1, 2), 10); /* Both values are not equal. Provided value: 3 Expected value: 10 */
More complex values are also well printed:
ensure( [ 'strawberry', 'orange', 'lime', ], [ 'orange', 'lime', 'strawberry', ], ); /* Both values are not equal. Provided value: array:3 [ 0 => (10) "strawberry" 1 => (6) "orange" 2 => (4) "lime" ] Expected value: array:3 [ 0 => (6) "orange" 1 => (4) "lime" 2 => (10) "strawberry" ] */
License
MIT.