aedon/php-expectations

1.0.0 2023-03-12 11:00 UTC

This package is auto-updated.

Last update: 2024-09-18 11:58:22 UTC


README

GitHub release Build Status GitHub license

使用此期望库减少代码行数。使用期望进行条件异常。

需求

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 创建