-
-
Notifications
You must be signed in to change notification settings - Fork 406
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
make:entity Use the namespace instead of the full class name for MappingDriver #1054
make:entity Use the namespace instead of the full class name for MappingDriver #1054
Conversation
9531c6a
to
57683b4
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome! Could you rebase this PR please. We've fixed a number of broken tests since you've opened the PR. Thanks in advanced.
13dccc2
to
6563a07
Compare
Rebased the PR |
if (1 < \count($classNameComponents)) { | ||
array_pop($classNameComponents); | ||
} | ||
$classNamespace = implode('\\', $classNameComponents); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you add a comment about which situation this is addressing? A test would be ideal, though I don't know how easy that would be to add.
Thanks!
Hi I have added a comment to the new logic. Regarding the tests I have had a try, but not sure of where they should be placed (I was using The 2 functions I came up with are: /**
* @dataProvider getMappingDriverTests
*/
public function testMappingDriverSelection(string $driverClass, ?array $annotatedPrefixes, bool $doesUseMappingDriver): void
{
$compatUtil = $this->createMock(PhpCompatUtil::class);
$registry = $this->createMock(ManagerRegistry::class);
$registry->expects($this->any())
->method('getManagerForClass')
->willThrowException(new \ReflectionException());
$helper = new DoctrineHelper('', $compatUtil, $registry, true, $annotatedPrefixes);
$this->assertSame($doesUseMappingDriver, $helper->doesClassUseDriver('App\\Entity\\UserProfile', $driverClass),
sprintf('DoctrineHelper confirms that App\\Entity\\UserProfile %s use the %s driver (based on provided config)', $doesUseMappingDriver ? 'does' : 'does not', $driverClass)
);
}
public function getMappingDriverTests(): \Generator
{
yield 'empty_config' => [
'Doctrine\\ORM\\Mapping\\Driver\\AttributeDriver',
null,
false,
];
$hasAttributeDriver = class_exists(\Doctrine\ORM\Mapping\Driver\AttributeDriver::class);
$hasAnnotationDriver = class_exists(\Doctrine\ORM\Mapping\Driver\AnnotationDriver::class);
if ($hasAttributeDriver) {
$attributeDriver = $this->createMock(\Doctrine\ORM\Mapping\Driver\AttributeDriver::class);
yield 'basic_config_attributes' => [
\Doctrine\ORM\Mapping\Driver\AttributeDriver::class,
[
'default' => [
[
'App\\Entity',
$attributeDriver
]
]
],
true,
];
}
if ($hasAnnotationDriver) {
$annotationDriver = $this->createMock(\Doctrine\ORM\Mapping\Driver\AnnotationDriver::class);
yield 'basic_config_annotations' => [
\Doctrine\ORM\Mapping\Driver\AnnotationDriver::class,
[
'default' => [
[
'App\\Entity',
$annotationDriver
]
]
],
true,
];
}
if ($hasAttributeDriver && $hasAnnotationDriver) {
$attributeDriver = $this->createMock(\Doctrine\ORM\Mapping\Driver\AttributeDriver::class);
$annotationDriver = $this->createMock(\Doctrine\ORM\Mapping\Driver\AnnotationDriver::class);
// 2 namespaces - namespaces start with different characters (A / B)
// New class App\Entity\Profile should be using the AttributeDriver as it belongs to App\Entity namespace
yield 'mixed_config_different_namespaces' => [
\Doctrine\ORM\Mapping\Driver\AttributeDriver::class,
[
'default' => [
[
'App\\Entity',
$attributeDriver
],
[
'BetaCorp\Bundle\BetaBundle\Entity',
$annotationDriver
]
]
],
true,
];
// 2 namespaces - namespaces start with same characters (A / A)
// New class App\Entity\Profile should be using the AttributeDriver as it belongs to App\Entity namespace
yield 'mixed_config_similar_namespace' => [
\Doctrine\ORM\Mapping\Driver\AttributeDriver::class,
[
'default' => [
[
'App\\Entity',
$attributeDriver
],
[
'ABC\Bundle\ABCBundle\Entity',
$annotationDriver
]
]
],
true,
];
}
} |
… name when checking which MappingDriver to use
ff6460a
to
2bb6e95
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you @michaelphillpotts!
This fixes #1053