maslosoft/codeception-reflection-asserts

Reflection-based assertions for Codeception & PHPUnit

Installs: 1

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 0

Forks: 0

Open Issues: 0

pkg:composer/maslosoft/codeception-reflection-asserts

1.0.0 2025-11-13 15:42 UTC

This package is auto-updated.

Last update: 2025-12-13 15:58:02 UTC


README

This asserts module is prepared to test code generation tools to assert existing of classes, methods, properties.

Installation and configuration

Use composer to install:

composer require maslosoft/maslosoft/codeception-reflection-asserts

Add to tests/unit.suite.yml:

actor: UnitTester
suite_namespace: Tests\Unit
modules:
    enabled:
      - \Maslosoft\Codeception\Module\ReflectionAsserts

Usage

Using in cest/cept

$I->assertMethodExists(Foo::class, 'bar');
$I->assertMethodIsPublic(Foo::class, 'bar');
$I->assertPropertyExists(Foo::class, 'baz');
$I->assertPropertyIsPrivate(Foo::class, 'baz');
$I->assertMethodHasParameter(
    Foo::class,
    'bar',
    'limit',
    type: 'int',
    allowsNull: false,
    optional: true
);

Using in unit test

<?php
...
class SomeTest extends Unit
{
	use Maslosoft\Testing\Reflection\ReflectionAssertionsTrait;

	function testMyReflection(): void
	{
        $this->assertClassExists(SomeService::class);

        $this->assertMethodExists(SomeService::class, 'handle');
        $this->assertMethodIsPublic(SomeService::class, 'handle');

        $this->assertMethodHasParameter(
            SomeService::class,
            'handle',
            'request',
            type: Request::class,
            allowsNull: false,
            optional: false
        );

        $this->assertPropertyExists(SomeService::class, 'repository');
        $this->assertPropertyIsPrivate(SomeService::class, 'repository');
    }
}