ghostwriter / phpunit-assertions
Additional assertions for PHPUnit
Fund package maintenance!
0.1.x-dev
2026-05-27 16:54 UTC
Requires
- php: ~8.4.0 || ~8.5.0
- ext-mbstring: *
- phpunit/phpunit: ^13.1.13
Requires (Dev)
- ext-xdebug: *
- boundwize/structarmed: ^0.8.0
- ghostwriter/coding-standard: dev-main
- ghostwriter/testify: ^0.1.2
- mockery/mockery: ^1.6.12
- symfony/var-dumper: ^8.0.8
This package is auto-updated.
Last update: 2026-05-27 16:54:28 UTC
README
Additional assertions for PHPUnit
Installation
You can install the package via composer:
composer require ghostwriter/phpunit-assertions --dev
Star ⭐️ this repo if you find it useful
You can also star (🌟) this repo to find it easier later.
Usage
<?php declare(strict_types=1); namespace Tests\Unit; use PHPUnit\Framework\TestCase; use Ghostwriter\PHPUnitAssertions\Trait\ClassAssertionsTrait; final class ExampleTest extends TestCase { use ClassAssertionsTrait; public function testClassAssertions(): void { self::assertClassHasMethod('invoke', ExampleChild::class); self::assertClassDoesNotHaveMethod('missing', ExampleChild::class); self::assertClassExtendsClass(ExampleChild::class, ExampleBase::class); self::assertClassExtendsClasses(ExampleChild::class, [ExampleBase::class, ExampleRoot::class]); self::assertClassImplementsInterface(ExampleChild::class, ExampleInterface::class); self::assertClassImplementsInterfaces(ExampleChild::class, [ExampleInterface::class, ExampleExtraInterface::class]); self::assertClassUsesTrait(ExampleChild::class, ExampleTraitA::class); self::assertClassUsesTraits(ExampleChild::class, [ExampleTraitA::class, ExampleTraitB::class]); } } interface ExampleInterface {} interface ExampleExtraInterface {} interface ExampleCompositeInterface extends ExampleInterface, ExampleExtraInterface {} trait ExampleTraitA {} trait ExampleTraitB {} class ExampleRoot {} class ExampleBase extends ExampleRoot { use ExampleTraitA; public function invoke(): void {} } class ExampleChild extends ExampleBase implements ExampleCompositeInterface { use ExampleTraitB; }
Trait methods
ClassAssertionsTrait
ClassAssertionsTrait::assertClassHasMethodClassAssertionsTrait::assertClassDoesNotHaveMethodClassAssertionsTrait::assertClassExtendsClassClassAssertionsTrait::assertClassExtendsClassesClassAssertionsTrait::assertClassImplementsInterfaceClassAssertionsTrait::assertClassImplementsInterfacesClassAssertionsTrait::assertClassUsesTraitClassAssertionsTrait::assertClassUsesTraits
Credits
- Nathanael Esayeas
- Sebastian Bergmann (PHPUnit creator and maintainer)
- All Contributors
Changelog
Please see CHANGELOG.md for more information on what has changed recently.
License
Please see LICENSE for more information on the license that applies to this project.
Security
Please see SECURITY.md for more information on security disclosure process.