-
-
Notifications
You must be signed in to change notification settings - Fork 505
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1966 from alcaeus/fix-duplicate-embedded-index-name
Fix embedding documents containing named indexes
- Loading branch information
Showing
4 changed files
with
119 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
88 changes: 88 additions & 0 deletions
88
tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH1344Test.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
<?php | ||
|
||
namespace Doctrine\ODM\MongoDB\Tests\Functional\Ticket; | ||
|
||
use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM; | ||
use Doctrine\ODM\MongoDB\Tests\BaseTest; | ||
use MongoResultException; | ||
|
||
class GH1344Test extends BaseTest | ||
{ | ||
public function testGeneratingIndexesDoesNotThrowException() | ||
{ | ||
$indexes = $this->dm->getSchemaManager()->getDocumentIndexes(GH1344Main::class); | ||
self::assertCount(4, $indexes); | ||
self::assertSame('embedded1_embedded', $indexes[0]['options']['name']); | ||
self::assertSame('embedded1_embedded_nested', $indexes[1]['options']['name']); | ||
self::assertSame('embedded2_embedded', $indexes[2]['options']['name']); | ||
self::assertSame('embedded2_embedded_nested', $indexes[3]['options']['name']); | ||
|
||
$this->dm->getSchemaManager()->ensureDocumentIndexes(GH1344Main::class); | ||
} | ||
|
||
public function testGeneratingIndexesWithTooLongIndexNameThrowsException() | ||
{ | ||
// Ensure that at least the beginning of the index name is contained in | ||
// the exception message. This can vary between driver/server versions. | ||
$this->expectException(MongoResultException::class); | ||
$this->expectExceptionMessageRegExp('#GH1344TooLongIndexName.\$embedded1_this_is_a_really_long_name_that#'); | ||
|
||
$this->dm->getSchemaManager()->ensureDocumentIndexes(GH1344TooLongIndexName::class); | ||
} | ||
} | ||
|
||
/** @ODM\Document */ | ||
class GH1344Main | ||
{ | ||
/** @ODM\Id */ | ||
public $id; | ||
|
||
/** @ODM\EmbedOne(targetDocument=GH1344Embedded::class) */ | ||
public $embedded1; | ||
|
||
/** @ODM\EmbedOne(targetDocument=GH1344Embedded::class) */ | ||
public $embedded2; | ||
} | ||
|
||
/** | ||
* @ODM\EmbeddedDocument | ||
* @ODM\Index(keys={"property"="asc"}, name="embedded") | ||
*/ | ||
class GH1344Embedded | ||
{ | ||
/** @ODM\Field */ | ||
public $property; | ||
|
||
/** @ODM\EmbedOne(targetDocument=GH1344EmbeddedNested::class) */ | ||
public $embedded; | ||
} | ||
|
||
/** | ||
* @ODM\EmbeddedDocument | ||
* @ODM\Index(keys={"property"="asc"}, name="nested") | ||
*/ | ||
class GH1344EmbeddedNested | ||
{ | ||
/** @ODM\Field */ | ||
public $property; | ||
} | ||
|
||
/** @ODM\Document */ | ||
class GH1344TooLongIndexName | ||
{ | ||
/** @ODM\Id */ | ||
public $id; | ||
|
||
/** @ODM\EmbedOne(targetDocument=GH1344TooLongIndexNameEmbedded::class) */ | ||
public $embedded1; | ||
} | ||
|
||
/** | ||
* @ODM\EmbeddedDocument | ||
* @ODM\Index(keys={"property"="asc"}, name="this_is_a_really_long_name_that_will_cause_problems_for_whoever_tries_to_use_it_whether_in_an_embedded_field_or_not") | ||
*/ | ||
class GH1344TooLongIndexNameEmbedded | ||
{ | ||
/** @ODM\Field */ | ||
public $property; | ||
} |