Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add self reference test case for DoctrineTargetEntityStringToClassConstantRector #211

Merged
merged 2 commits into from
Jul 23, 2023

Conversation

TomasVotruba
Copy link
Member

@TomasVotruba TomasVotruba commented Jul 23, 2023

Test fixture for rectorphp/rector#8081

@TomasVotruba TomasVotruba changed the title add self reference test case Add self reference test case for DoctrineTargetEntityStringToClassConstantRector Jul 23, 2023

use Doctrine\ORM\Mapping as ORM;

final class KeepSelfReference
Copy link
Contributor

@OskarStark OskarStark Jul 23, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need the #[Entity] Attribute here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, just added 👍

Copy link
Member Author

@TomasVotruba TomasVotruba Jul 23, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Checking other fixtures, it's actually not needed. This rules checks directly these annotations/attributes.

There already is another test fixture for self::class as well 👍

See: https://github.com/rectorphp/rector-doctrine/blob/main/rules-tests/CodeQuality/Rector/Property/DoctrineTargetEntityStringToClassConstantRector/Fixture/Attribute/keep_self.php.inc

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe add:
#[ORM\JoinColumn(name: 'some_entity', onDelete: 'SET NULL')

from my screenshot

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah the difference is, in your existing test you use private ?self.....

while here is no type hint.

Please do:

- private $someEntity;
+ private KeepSelfReference $someEntity;

if this does not work, try to make it nullable:

- private $someEntity;
+ private ?KeepSelfReference $someEntity;

@samsonasik
Copy link
Member

@TomasVotruba TomasVotruba merged commit 281257f into main Jul 23, 2023
3 checks passed
@TomasVotruba TomasVotruba deleted the tv-self-fix branch July 23, 2023 20:25
@TomasVotruba
Copy link
Member Author

Thanks 👍

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.

3 participants