diff --git a/src/Database/Validator/IndexDefinition.php b/src/Database/Validator/IndexDefinition.php index 2287138f0..00f79c81b 100644 --- a/src/Database/Validator/IndexDefinition.php +++ b/src/Database/Validator/IndexDefinition.php @@ -512,7 +512,7 @@ public function checkIndexLengths(Index $index): bool } if ($indexLength > $attributeSize) { - $this->message = 'Index length '.$indexLength.' is larger than the size for '.$attributeName.': '.$attributeSize.'"'; + $this->message = 'Index length '.$indexLength.' is larger than the size for '.$attributeName.': '.$attributeSize; return false; } diff --git a/tests/e2e/Adapter/Scopes/IndexTests.php b/tests/e2e/Adapter/Scopes/IndexTests.php index 23e1a7705..1abe440ff 100644 --- a/tests/e2e/Adapter/Scopes/IndexTests.php +++ b/tests/e2e/Adapter/Scopes/IndexTests.php @@ -302,7 +302,7 @@ public function testIndexLengthExceedsAttributeSize(): void $database->createIndex(__FUNCTION__, Index::key(key: 'index1', attributes: ['title1', 'title2'], lengths: [701, 50])); $this->fail('Failed to throw exception'); } catch (Throwable $e) { - $this->assertEquals('Index length 701 is larger than the size for title1: 700"', $e->getMessage()); + $this->assertEquals('Index length 701 is larger than the size for title1: 700', $e->getMessage()); } $database->deleteCollection(__FUNCTION__); @@ -681,7 +681,7 @@ public function testIndexValidation(): void $validator = $this->indexValidator($attributes, $indexes); if ($adapter->supports(Capability::IndexIdentical)) { - $errorMessage = 'Index length 701 is larger than the size for title1: 700"'; + $errorMessage = 'Index length 701 is larger than the size for title1: 700'; $this->assertFalse($validator->isValid($indexes[0])); $this->assertSame($errorMessage, $validator->getDescription()); diff --git a/tests/unit/Validator/IndexTest.php b/tests/unit/Validator/IndexTest.php index c3e789dd5..a158ef44a 100644 --- a/tests/unit/Validator/IndexTest.php +++ b/tests/unit/Validator/IndexTest.php @@ -485,6 +485,14 @@ public function testTextAttributeWithoutASizeIsJudgedAgainstTheTextMaximum(): vo $this->assertSame('Index length is longer than the maximum: 768', $validator->getDescription()); } + public function testIndexLengthLargerThanTheAttributeNamesBothSizes(): void + { + $validator = new IndexDefinition([Attribute::string(key: 'title', size: 64)], [], Profiles::of(capabilities: self::CAPABILITIES, indexLength: 768)); + + $this->assertFalse($validator->isValid(Index::key(key: 'by_title', attributes: ['title'], lengths: [65]))); + $this->assertSame('Index length 65 is larger than the size for title: 64', $validator->getDescription()); + } + public function testKeyAndUniqueIndexesAreRejectedWithoutAdapterSupport(): void { $validator = new IndexDefinition(