aedon / php-expectations
1.0.0
2023-03-12 11:00 UTC
Requires
- php: ^8.0
Requires (Dev)
- mikey179/vfsstream: ^1.6
- phpunit/phpunit: ^9.5
- vimeo/psalm: ^5.8
README
使用此期望库减少代码行数。使用期望进行条件异常。
需求
PHP 8
使用示例
基本示例
代替...
$value = new stdClass(); if (!$value instanceof stdClass) { throw new InvalidArgumentException('some message'); }
这样做...
$value = new stdClass(); \Aedon\Expect::isInstanceOf($value, stdClass::class);
自定义异常
如果您想更改特定测试抛出的异常。
\Aedon\Expect::registerCustomException('isTrue', InvalidArgumentException::class); // This will now throw InvalidArgumentException instead of RuntimeException \Aedon\Expect::isTrue(false);
这也可以用于在期望失败时执行可调用的函数。
\Aedon\Expect::registerCustomException('isTrue', function() { return false; // omit this if you still want to throw the default exception });
支持
加入Discord: https://discord.gg/NEfRerY
Aedon PHP Expectations 由 Michael "Striker" Berger 创建