maslosoft / codeception-reflection-asserts
Reflection-based assertions for Codeception & PHPUnit
Package info
github.com/Maslosoft/codeception-reflection-asserts
pkg:composer/maslosoft/codeception-reflection-asserts
1.0.0
2025-11-13 15:42 UTC
Requires
- php: >=7.4
- codeception/codeception: ^5
Requires (Dev)
None
Suggests
None
Provides
None
Conflicts
None
Replaces
None
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/codeception-reflection-asserts --dev
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'); } }