Skip to content

Add #[attribute] support to NoEntityMockingRule#272

Merged
TomasVotruba merged 2 commits into
mainfrom
entity-mocking-attribute-support
Jun 10, 2026
Merged

Add #[attribute] support to NoEntityMockingRule#272
TomasVotruba merged 2 commits into
mainfrom
entity-mocking-attribute-support

Conversation

@TomasVotruba

Copy link
Copy Markdown
Member

Why

NoEntityMockingRule only detected Doctrine entities/documents declared via annotations (@ORM\Entity, @Document). Modern Doctrine code uses PHP attributes (#[ORM\Entity]), which slipped through unflagged.

What

  • DoctrineEntityDocumentAnalyser::isEntityClass() now also inspects native class attributes for Doctrine\ORM\Mapping\Entity and Doctrine\ODM\MongoDB\Mapping\Annotations\Document, in addition to the existing docblock markers.
  • Added test fixture MockingAttributeEntity mocking an #[ORM\Entity] source class, asserting the rule now reports it.

Test

vendor/bin/phpunit tests/Rules/PHPUnit/NoEntityMockingRule/

ECS, Rector and PHPStan all pass.

@TomasVotruba TomasVotruba force-pushed the entity-mocking-attribute-support branch from 08d2a56 to a47cadd Compare June 10, 2026 08:23
@TomasVotruba TomasVotruba merged commit 8a613aa into main Jun 10, 2026
7 checks passed
@TomasVotruba TomasVotruba deleted the entity-mocking-attribute-support branch June 10, 2026 08:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant