Skip to content

Commit 52d47d3

Browse files
committed
Add test with overly long index name to confirm exception
1 parent 7d8e93e commit 52d47d3

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH1344Test.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM;
66
use Doctrine\ODM\MongoDB\Tests\BaseTest;
7+
use MongoResultException;
78

89
class GH1344Test extends BaseTest
910
{
@@ -18,6 +19,16 @@ public function testGeneratingIndexesDoesNotThrowException()
1819

1920
$this->dm->getSchemaManager()->ensureDocumentIndexes(GH1344Main::class);
2021
}
22+
23+
public function testGeneratingIndexesWithTooLongIndexNameThrowsException()
24+
{
25+
// Ensure that at least the beginning of the index name is contained in
26+
// the exception message. This can vary between driver/server versions.
27+
$this->expectException(MongoResultException::class);
28+
$this->expectExceptionMessageRegExp('#GH1344TooLongIndexName.\$embedded1_this_is_a_really_long_name_that#');
29+
30+
$this->dm->getSchemaManager()->ensureDocumentIndexes(GH1344TooLongIndexName::class);
31+
}
2132
}
2233

2334
/** @ODM\Document */
@@ -55,3 +66,23 @@ class GH1344EmbeddedNested
5566
/** @ODM\Field */
5667
public $property;
5768
}
69+
70+
/** @ODM\Document */
71+
class GH1344TooLongIndexName
72+
{
73+
/** @ODM\Id */
74+
public $id;
75+
76+
/** @ODM\EmbedOne(targetDocument=GH1344TooLongIndexNameEmbedded::class) */
77+
public $embedded1;
78+
}
79+
80+
/**
81+
* @ODM\EmbeddedDocument
82+
* @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")
83+
*/
84+
class GH1344TooLongIndexNameEmbedded
85+
{
86+
/** @ODM\Field */
87+
public $property;
88+
}

0 commit comments

Comments
 (0)