Skip to content

Maslosoft/codeception-reflection-asserts

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Codeception Reflection Asserts

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

About

Codeception Reflection Asserts

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages