From 36a345cff01f8e11e3fc7c0669b33eb911a55170 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Tamarelle?= Date: Tue, 30 May 2023 13:28:21 +0200 Subject: [PATCH 1/2] Deprecate method IndexInfo::isGeoHaystack() MongoDB 5.0 removes support for "geoHaystack" indexes, the method "IndexInfo::isGeoHaystack()" will be removed in a future release --- .../MongoDBModelIndexInfo-isGeoHaystack.txt | 7 ++--- src/Model/IndexInfo.php | 3 ++ tests/Model/IndexInfoFunctionalTest.php | 4 ++- tests/Model/IndexInfoTest.php | 28 ++++++++++++++----- 4 files changed, 30 insertions(+), 12 deletions(-) diff --git a/docs/reference/method/MongoDBModelIndexInfo-isGeoHaystack.txt b/docs/reference/method/MongoDBModelIndexInfo-isGeoHaystack.txt index 97f844f10..f6c2007df 100644 --- a/docs/reference/method/MongoDBModelIndexInfo-isGeoHaystack.txt +++ b/docs/reference/method/MongoDBModelIndexInfo-isGeoHaystack.txt @@ -4,6 +4,9 @@ MongoDB\\Model\\IndexInfo::isGeoHaystack() .. versionadded:: 1.4 +.. deprecated:: 1.16 + MongoDB 5.0 and later no longer supports geoHaystack indexes. + .. default-domain:: mongodb .. contents:: On this page @@ -24,10 +27,6 @@ Definition function isGeoHaystack(): boolean - .. note:: - - MongoDB 5.0 and later no longer supports geoHaystack indexes. - Return Values ------------- diff --git a/src/Model/IndexInfo.php b/src/Model/IndexInfo.php index ce4b2af8a..94e21c764 100644 --- a/src/Model/IndexInfo.php +++ b/src/Model/IndexInfo.php @@ -124,9 +124,12 @@ public function is2dSphere() * Return whether or not this index is of type geoHaystack. * * @return boolean + * @deprecated Since 1.16: MongoDB 5.0 removes support for geoHaystack indexes. */ public function isGeoHaystack() { + trigger_error('MongoDB 5.0 removes support for "geoHaystack" indexes, the method "IndexInfo::isGeoHaystack()" will be removed in a future release', E_USER_DEPRECATED); + return array_search('geoHaystack', $this->getKey(), true) !== false; } diff --git a/tests/Model/IndexInfoFunctionalTest.php b/tests/Model/IndexInfoFunctionalTest.php index f7e19e513..a45a97724 100644 --- a/tests/Model/IndexInfoFunctionalTest.php +++ b/tests/Model/IndexInfoFunctionalTest.php @@ -50,7 +50,9 @@ public function testIsGeoHaystack(): void $index = $result->current(); $this->assertEquals($indexName, $index->getName()); - $this->assertTrue($index->isGeoHaystack()); + $this->assertDeprecated(function () use ($index): void { + $this->assertTrue($index->isGeoHaystack()); + }); $this->assertEquals(5, $index['bucketSize']); } diff --git a/tests/Model/IndexInfoTest.php b/tests/Model/IndexInfoTest.php index b4c482597..30cb26aea 100644 --- a/tests/Model/IndexInfoTest.php +++ b/tests/Model/IndexInfoTest.php @@ -22,7 +22,9 @@ public function testBasicIndex(): void $this->assertSame('x_1', $info->getName()); $this->assertSame('foo.bar', $info->getNamespace()); $this->assertFalse($info->is2dSphere()); - $this->assertFalse($info->isGeoHaystack()); + $this->assertDeprecated(function () use ($info): void { + $this->assertFalse($info->isGeoHaystack()); + }); $this->assertFalse($info->isSparse()); $this->assertFalse($info->isText()); $this->assertFalse($info->isTtl()); @@ -44,7 +46,9 @@ public function testSparseIndex(): void $this->assertSame('y_sparse', $info->getName()); $this->assertSame('foo.bar', $info->getNamespace()); $this->assertFalse($info->is2dSphere()); - $this->assertFalse($info->isGeoHaystack()); + $this->assertDeprecated(function () use ($info): void { + $this->assertFalse($info->isGeoHaystack()); + }); $this->assertTrue($info->isSparse()); $this->assertFalse($info->isText()); $this->assertFalse($info->isTtl()); @@ -66,7 +70,9 @@ public function testUniqueIndex(): void $this->assertSame('z_unique', $info->getName()); $this->assertSame('foo.bar', $info->getNamespace()); $this->assertFalse($info->is2dSphere()); - $this->assertFalse($info->isGeoHaystack()); + $this->assertDeprecated(function () use ($info): void { + $this->assertFalse($info->isGeoHaystack()); + }); $this->assertFalse($info->isSparse()); $this->assertFalse($info->isText()); $this->assertFalse($info->isTtl()); @@ -88,7 +94,9 @@ public function testTtlIndex(): void $this->assertSame('z_unique', $info->getName()); $this->assertSame('foo.bar', $info->getNamespace()); $this->assertFalse($info->is2dSphere()); - $this->assertFalse($info->isGeoHaystack()); + $this->assertDeprecated(function () use ($info): void { + $this->assertFalse($info->isGeoHaystack()); + }); $this->assertFalse($info->isSparse()); $this->assertFalse($info->isText()); $this->assertTrue($info->isTtl()); @@ -166,7 +174,9 @@ public function testIs2dSphere(): void $this->assertSame('pos_2dsphere', $info->getName()); $this->assertSame('foo.bar', $info->getNamespace()); $this->assertTrue($info->is2dSphere()); - $this->assertFalse($info->isGeoHaystack()); + $this->assertDeprecated(function () use ($info): void { + $this->assertFalse($info->isGeoHaystack()); + }); $this->assertFalse($info->isSparse()); $this->assertFalse($info->isText()); $this->assertFalse($info->isTtl()); @@ -187,7 +197,9 @@ public function testIsGeoHaystack(): void $this->assertSame('pos2_geoHaystack_x_1', $info->getName()); $this->assertSame('foo.bar', $info->getNamespace()); $this->assertFalse($info->is2dSphere()); - $this->assertTrue($info->isGeoHaystack()); + $this->assertDeprecated(function () use ($info): void { + $this->assertTrue($info->isGeoHaystack()); + }); $this->assertFalse($info->isSparse()); $this->assertFalse($info->isText()); $this->assertFalse($info->isTtl()); @@ -208,7 +220,9 @@ public function testIsText(): void $this->assertSame('title_text_description_text', $info->getName()); $this->assertSame('foo.bar', $info->getNamespace()); $this->assertFalse($info->is2dSphere()); - $this->assertFalse($info->isGeoHaystack()); + $this->assertDeprecated(function () use ($info): void { + $this->assertFalse($info->isGeoHaystack()); + }); $this->assertFalse($info->isSparse()); $this->assertTrue($info->isText()); $this->assertFalse($info->isTtl()); From 7dc5d33d5ec8b844bc3d53badf2ce131a9f7de80 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Tamarelle?= Date: Thu, 1 Jun 2023 22:35:34 +0200 Subject: [PATCH 2/2] Fix CS --- src/Model/IndexInfo.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/Model/IndexInfo.php b/src/Model/IndexInfo.php index 94e21c764..4d86bab16 100644 --- a/src/Model/IndexInfo.php +++ b/src/Model/IndexInfo.php @@ -23,6 +23,9 @@ use function array_key_exists; use function array_search; +use function trigger_error; + +use const E_USER_DEPRECATED; /** * Index information model class.