ghostwriter/psr-phpunit-assertions

This package is abandoned and no longer maintained. The author suggests using the ghostwriter/phpunit-assertions package instead.

Additional assertions for PHPUnit

Maintainers

Package info

github.com/ghostwriter/psr-phpunit-assertions

Homepage

Issues

pkg:composer/ghostwriter/psr-phpunit-assertions

Fund package maintenance!

ghostwriter

Statistics

Installs: 151 243

Dependents: 0

Suggesters: 0

Stars: 0

0.1.0 2026-05-27 19:00 UTC

This package is auto-updated.

Last update: 2026-05-27 23:21:50 UTC


README

GitHub Sponsors Automation Supported PHP Version Downloads

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::assertClassHasMethod
  • ClassAssertionsTrait::assertClassDoesNotHaveMethod
  • ClassAssertionsTrait::assertClassExtendsClass
  • ClassAssertionsTrait::assertClassExtendsClasses
  • ClassAssertionsTrait::assertClassImplementsInterface
  • ClassAssertionsTrait::assertClassImplementsInterfaces
  • ClassAssertionsTrait::assertClassUsesTrait
  • ClassAssertionsTrait::assertClassUsesTraits

Credits

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.