Skip to content

RyseSlade/php-expectations

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Aedon PHP Expectations

GitHub release Build Status GitHub license

Reduce lines of code with this expectations library. Use expectations for conditional exceptions.

Requirements

PHP 8

Usage examples

Basic example

Instead of...

$value = new stdClass();

if (!$value instanceof stdClass) {
    throw new InvalidArgumentException('some message');
}

Do it like this...

$value = new stdClass();

\Aedon\Expect::isInstanceOf($value, stdClass::class);

Custom Exceptions

In case you want to change the exception thrown for specific tests.

\Aedon\Expect::registerCustomException('isTrue', InvalidArgumentException::class);

// This will now throw InvalidArgumentException instead of RuntimeException
\Aedon\Expect::isTrue(false); 

This can also be used to execute a callable when an expectation fails.

\Aedon\Expect::registerCustomException('isTrue', function() {
    return false; // omit this if you still want to throw the default exception 
});

Support

Join Discord: https://discord.gg/NEfRerY

Aedon PHP Expectations created by Michael "Striker" Berger