diff --git a/UPGRADE-3.x.md b/UPGRADE-3.x.md index c16d6ce2..52ef9f1f 100644 --- a/UPGRADE-3.x.md +++ b/UPGRADE-3.x.md @@ -4,6 +4,12 @@ UPGRADE 3.x UPGRADE FROM 3.x to 3.x ======================= +### Sonata\DoctrineMongoDBAdminBundle\Model\ModelManager + +Deprecated passing `null` as argument 2 for `find()`. +Deprecated passing `null` or an object which is in state new or removed as argument 1 for `getNormalizedIdentifier()`. +Deprecated passing `null` as argument 1 for `getUrlSafeIdentifier()`. + UPGRADE FROM 3.3 to 3.4 ======================= diff --git a/src/Model/ModelManager.php b/src/Model/ModelManager.php index 1c87f0a1..d0258bef 100755 --- a/src/Model/ModelManager.php +++ b/src/Model/ModelManager.php @@ -165,7 +165,13 @@ public function delete($object) public function find($class, $id) { - if (!isset($id)) { + if (null === $id) { + @trigger_error(sprintf( + 'Passing null as argument 1 for %s() is deprecated since' + .' sonata-project/doctrine-mongodb-admin-bundle 3.x and will be not allowed in version 4.0.', + __METHOD__ + ), E_USER_DEPRECATED); + return null; } @@ -293,7 +299,14 @@ public function getIdentifierFieldNames($class) public function getNormalizedIdentifier($document) { + // NEXT_MAJOR: Remove the following 2 checks and declare "object" as type for argument 1. if (null === $document) { + @trigger_error(sprintf( + 'Passing null as argument 1 for %s() is deprecated since' + .' sonata-project/doctrine-mongodb-admin-bundle 3.x and will be not allowed in version 4.0.', + __METHOD__ + ), E_USER_DEPRECATED); + return null; } @@ -313,6 +326,17 @@ public function getNormalizedIdentifier($document) public function getUrlSafeIdentifier($document) { + // NEXT_MAJOR: Remove the following check and declare "object" as type for argument 1. + if (!\is_object($document)) { + @trigger_error(sprintf( + 'Passing other type than object for argument 1 for %s() is deprecated since' + .' sonata-project/doctrine-mongodb-admin-bundle 3.x and will be not allowed in version 4.0.', + __METHOD__ + ), E_USER_DEPRECATED); + + return null; + } + return $this->getNormalizedIdentifier($document); } diff --git a/tests/Model/ModelManagerTest.php b/tests/Model/ModelManagerTest.php index 2d52a63d..1143254b 100644 --- a/tests/Model/ModelManagerTest.php +++ b/tests/Model/ModelManagerTest.php @@ -90,10 +90,19 @@ public function getWrongDocuments(): iterable yield ['sonata-project']; } + /** + * NEXT_MAJOR: Remove this method. + * + * @group legacy + */ public function testGetNormalizedIdentifierNull(): void { $manager = new ModelManager($this->registry, $this->propertyAccessor); + $this->expectDeprecation( + 'Passing null as argument 1 for Sonata\DoctrineMongoDBAdminBundle\Model\ModelManager::getNormalizedIdentifier() is deprecated since sonata-project/doctrine-mongodb-admin-bundle 3.x and will be not allowed in version 4.0.' + ); + $this->assertNull($manager->getNormalizedIdentifier(null)); } @@ -335,10 +344,19 @@ public function testGetModelInstanceForProtectedDocument(): void $this->assertInstanceOf(ProtectedDocument::class, $model->getModelInstance(ProtectedDocument::class)); } + /** + * NEXT_MAJOR: Remove this method. + * + * @group legacy + */ public function testFindBadId(): void { $model = new ModelManager($this->registry, $this->propertyAccessor); + $this->expectDeprecation( + 'Passing null as argument 1 for Sonata\DoctrineMongoDBAdminBundle\Model\ModelManager::find() is deprecated since sonata-project/doctrine-mongodb-admin-bundle 3.x and will be not allowed in version 4.0.' + ); + $this->assertNull($model->find('notImportant', null)); } @@ -351,10 +369,19 @@ public function testGetUrlSafeIdentifierException(): void $model->getNormalizedIdentifier(new \stdClass()); } + /** + * NEXT_MAJOR: Remove this method. + * + * @group legacy + */ public function testGetUrlSafeIdentifierNull(): void { $model = new ModelManager($this->registry, $this->propertyAccessor); + $this->expectDeprecation( + 'Passing null as argument 1 for Sonata\DoctrineMongoDBAdminBundle\Model\ModelManager::getNormalizedIdentifier() is deprecated since sonata-project/doctrine-mongodb-admin-bundle 3.x and will be not allowed in version 4.0.' + ); + $this->assertNull($model->getNormalizedIdentifier(null)); }