-
-
Notifications
You must be signed in to change notification settings - Fork 64
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
Fix bug in namespace check in MappingDriverChain #341
Conversation
@@ -73,7 +73,7 @@ public function getDrivers() | |||
public function loadMetadataForClass(string $className, ClassMetadata $metadata) | |||
{ | |||
foreach ($this->drivers as $namespace => $driver) { | |||
if (strpos($className, $namespace) === 0) { | |||
if (strpos($className, $namespace . '\\') === 0) { |
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.
The $namespace
can already contain a \
at the end. It'd be better to ensure there's always a single \
in the addDriver
method
Please add a test. |
The namespace matching code has been revised and a new unit test added. Note that in the current implementation, the class name will only match the namespace if it's a direct parent namespace. ie.
|
This is not good IMO. Drivers currently support organizing entities in sub-namespaces. The chain driver should not restrict that more |
@@ -37,7 +37,7 @@ public function testDelegateToMatchingNamespaceDriver(): void | |||
->with(self::equalTo($className)) | |||
->willReturn(true); | |||
|
|||
$chain->addDriver($driver1, 'Doctrine\Tests\Models\Company'); | |||
$chain->addDriver($driver1, 'Doctrine\Tests\Persistence\Map'); |
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.
What's the reason for this change?
@@ -63,7 +63,7 @@ public function testGatherAllClassNames(): void | |||
$driver1 = $this->createMock(MappingDriver::class); | |||
$driver1->expects(self::once()) | |||
->method('getAllClassNames') | |||
->will(self::returnValue(['Doctrine\Tests\Models\Company\Foo'])); | |||
->will(self::returnValue(['Doctrine\Tests\Models\Company\Foo', 'Doctrine\Tests\Models\Company2\Foo'])); |
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.
Same question, why did this test need an adjustment?
self::assertTrue($mdc::isMatchingNamespace($className, 'Doctrine\Tests\Persistence\Mapping\\')); | ||
self::assertTrue($mdc::isMatchingNamespace($className, 'Doctrine\Tests\Persistence\Mapping')); | ||
self::assertFalse($mdc::isMatchingNamespace($className, 'Doctrine\Tests\Persistence\Map')); | ||
self::assertFalse($mdc::isMatchingNamespace($className, 'Doctrine\Tests\Persistence')); |
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.
Those tests don't tell me what problem you're attempting to solve. You're merely testing an internal function, an implementation detail.
No answer… let's close this I guess. |
This is still a issue. Feel free to fork the branch and update it as necessary. In the meantime, I worked around this bug by changing the name of my directory for the mapping:
to this, which worked, because of the unique prefix:
|
This fix improves the checking if a namespace appears in a className by ensuring that the namespace ends in a
\
. Prior to this fix, the following would occur:A className such as
Doctrine\Tests\Persistence\Mapping\DriverChainEntity
would match the namespace:Doctrine\Tests\Persistence\Map
, which isn't correct.Other considerations:
\
? is this a valid case? Probably not.Doctrine\Tests\Persistence
. Should this match against the classNameDoctrine\Tests\Persistence\Mapping\DriverChainEntity
or not? The current logic would match, but I'm not sure if it should....