pest icon indicating copy to clipboard operation
pest copied to clipboard

[Bug]: Arch "classes" test is broken when using intersection and union type together

Open rcerljenko opened this issue 1 year ago • 0 comments

What Happened

When I use expect('App')->toBeClasses() on a sample class that looks like this:

namespace App\Collections;

use Illuminate\Database\Eloquent\Model;
use App\Contracts\HasDragAndDropReorder;

class ModelReorderRepository
{
	protected (Model&HasDragAndDropReorder)|null $model = null;

	public function setModel(Model&HasDragAndDropReorder $model): self
	{
		$this->model = $model;

		return $this;
	}
}

pest explodes with following error:

Tests\Unit\ArchTest > classes                                                                                                                                                                                                                         Error   
  Call to undefined method ReflectionIntersectionType::getName()

  at vendor\ta-tikoma\phpunit-architecture-test\src\Asserts\Properties\Elements\PropertyDescription.php:57
     53▕     ): string|array|null {
     54▕         $type = $reflectionProperty->getType();
     55▕         if ($type !== null) {
     56▕             if ($type instanceof ReflectionUnionType) {
  ➜  57▕                 return array_map(static fn ($type) => $type->getName(), $type->getTypes());
     58▕             }
     59▕
     60▕             if ($type instanceof ReflectionIntersectionType) {
     61▕                 return null; // @todo

  1   vendor\ta-tikoma\phpunit-architecture-test\src\Asserts\Properties\Elements\PropertyDescription.php:57
  2   vendor\ta-tikoma\phpunit-architecture-test\src\Asserts\Properties\Elements\PropertyDescription.php:34

How to Reproduce

Described above

Sample Repository

No response

Pest Version

2.19.2

PHP Version

8.2.10

Operation System

Windows

Notes

I realize that this is maybe a problem with ta-tikoma/phpunit-architecture-test package rather than pest?

I've raised an issue on the mentioned package => https://github.com/ta-tikoma/phpunit-architecture-test/issues/13

rcerljenko avatar Sep 21 '23 08:09 rcerljenko