packagefactory / phpunit-custom-assertions
Custom PHPUnit assertions for use in PackageFactory packages
Package info
codeberg.org/PackageFactory/phpunit-custom-assertions
pkg:composer/packagefactory/phpunit-custom-assertions
Requires
- phpunit/phpunit: ^13.3
Requires (Dev)
- phpstan/phpstan: ^2.2
- squizlabs/php_codesniffer: ^4.0
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
Custom PHPUnit assertions for use in PackageFactory packages
Installation
You can install this package using composer:
composer require --dev packagefactory/phpunit-custom-assertions
Usage
To use the custom assertions, just include the CustomAssetions trait with your PHPUnit test case:
declare(strict_types=1);
use PackageFactory\PhpUnit\CustomAssertions\CustomAssertions;
use PHPUnit\Framework\TestCase;
final class MyTest extends TestCase
{
use CustomAssertions;
// ...
}
Available Custom Assertions
assertDeepEquals
function assertDeepEquals(
mixed $expected,
mixed $actual,
array $customComparisonFns = [],
string $message = ''
): void
This assertion compares two values recursively. By default, objects are compared property-by-property and arrays are compared item-by-item.
For objects, you can provide custom comparison functions per-class via the $customComparisonFns parameter.
EXAMPLE:
self::assertDeepEquals(
['foo' => ['bar' => 'baz']],
['foo' => ['bar' => 'qux']],
);
OUTPUT:
Failed asserting that [...] deeply equals [...].
diff at path $value['foo']['bar']:
@@ -1 +1 @@
-'baz'
+'qux'
License

see LICENSE