Skip to content

Commit

Permalink
Trim leading backslash in collectionClass
Browse files Browse the repository at this point in the history
  • Loading branch information
malarzm authored and Maciej Malarz committed Mar 3, 2016
1 parent b413717 commit 2734a7d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
7 changes: 5 additions & 2 deletions lib/Doctrine/ODM/MongoDB/Mapping/ClassMetadataInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -1100,8 +1100,11 @@ public function mapField(array $mapping)
if (isset($mapping['targetDocument']) && strpos($mapping['targetDocument'], '\\') === false && strlen($this->namespace)) {
$mapping['targetDocument'] = $this->namespace . '\\' . $mapping['targetDocument'];
}
if (isset($mapping['collectionClass']) && strpos($mapping['collectionClass'], '\\') === false && strlen($this->namespace)) {
$mapping['collectionClass'] = $this->namespace . '\\' . $mapping['collectionClass'];
if (isset($mapping['collectionClass'])) {
if (strpos($mapping['collectionClass'], '\\') === false && strlen($this->namespace)) {
$mapping['collectionClass'] = $this->namespace . '\\' . $mapping['collectionClass'];
}
$mapping['collectionClass'] = ltrim($mapping['collectionClass'], '\\');
}
if ( ! empty($mapping['collectionClass'])) {
$rColl = new \ReflectionClass($mapping['collectionClass']);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@ public function testMappingNamespaceIsAdded()
$this->assertSame(MyEmbedsCollection::class, $cm->fieldMappings['coll']['collectionClass']);
}

public function testLeadingBackslashIsRemoved()
{
$d = new DocumentWithCustomCollection();
$cm = $this->dm->getClassMetadata(get_class($d));
$this->assertSame(MyDocumentsCollection::class, $cm->fieldMappings['inverseRefMany']['collectionClass']);
}

/**
* @expectedException \Doctrine\ODM\MongoDB\Mapping\MappingException
* @expectedExceptionMessage stdClass used as custom collection class for stdClass::assoc has to implement Doctrine\Common\Collections\Collection interface.
Expand Down Expand Up @@ -145,7 +152,7 @@ class DocumentWithCustomCollection

/**
* @ODM\ReferenceMany(
* collectionClass="MyDocumentsCollection",
* collectionClass="\Doctrine\ODM\MongoDB\Tests\Functional\MyDocumentsCollection",
* mappedBy="refMany",
* targetDocument="DocumentWithCustomCollection"
* )
Expand Down

0 comments on commit 2734a7d

Please sign in to comment.