PHP code example of ghostwriter / phpunit-assertions

1. Go to this page and download the library: Download ghostwriter/phpunit-assertions library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

ghostwriter / phpunit-assertions example snippets




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;
}