From 350fd5998e56037824a04ddb6db14b7d6d9c0659 Mon Sep 17 00:00:00 2001 From: Fran Moreno Date: Fri, 11 Sep 2020 01:11:04 +0200 Subject: [PATCH] Deprecate collection-related methods on ModelManager These methods were deprecated in the interface in https://github.com/sonata-project/SonataAdminBundle/pull/6312 and released in 3.75 --- composer.json | 2 +- src/Model/ModelManager.php | 70 ++++++++++++++++++++++++++++ tests/App/public/bundles/sonataadmin | 1 + tests/App/public/bundles/sonatacore | 1 + tests/App/public/bundles/sonatatwig | 1 + tests/Model/ModelManagerTest.php | 21 +++++++++ 6 files changed, 95 insertions(+), 1 deletion(-) create mode 120000 tests/App/public/bundles/sonataadmin create mode 120000 tests/App/public/bundles/sonatacore create mode 120000 tests/App/public/bundles/sonatatwig diff --git a/composer.json b/composer.json index 2f2e82c8..d8bf3ae6 100644 --- a/composer.json +++ b/composer.json @@ -30,7 +30,7 @@ "doctrine/mongodb-odm": "^1.3 || ^2.0", "doctrine/mongodb-odm-bundle": "^3.0 || ^4.0", "doctrine/persistence": "^1.3.4 || ^2.0", - "sonata-project/admin-bundle": "^3.69", + "sonata-project/admin-bundle": "^3.75", "sonata-project/form-extensions": "^0.1 || ^1.4", "symfony/config": "^4.4", "symfony/dependency-injection": "^4.4", diff --git a/src/Model/ModelManager.php b/src/Model/ModelManager.php index 0314eae8..0be9eb47 100755 --- a/src/Model/ModelManager.php +++ b/src/Model/ModelManager.php @@ -356,8 +356,18 @@ public function getModelInstance($class) return new $class(); } + /** + * NEXT_MAJOR: Remove this method. + * + * @deprecated since sonata-project/doctrine-mongodb-admin-bundle 3.x and will be removed in version 4.0. + */ public function getSortParameters(FieldDescriptionInterface $fieldDescription, DatagridInterface $datagrid) { + @trigger_error(sprintf( + 'Method %s() is deprecated since sonata-project/doctrine-mongodb-admin-bundle 3.x and will be removed in version 4.0.', + __METHOD__ + ), E_USER_DEPRECATED); + $values = $datagrid->getValues(); if ($this->isFieldAlreadySorted($fieldDescription, $datagrid)) { @@ -375,8 +385,18 @@ public function getSortParameters(FieldDescriptionInterface $fieldDescription, D return ['filter' => $values]; } + /** + * NEXT_MAJOR: Remove this method. + * + * @deprecated since sonata-project/doctrine-mongodb-admin-bundle 3.x and will be removed in version 4.0. + */ public function getPaginationParameters(DatagridInterface $datagrid, $page) { + @trigger_error(sprintf( + 'Method %s() is deprecated since sonata-project/doctrine-mongodb-admin-bundle 3.x and will be removed in version 4.0.', + __METHOD__ + ), E_USER_DEPRECATED); + $values = $datagrid->getValues(); if (isset($values['_sort_by']) && $values['_sort_by'] instanceof FieldDescriptionInterface) { @@ -421,28 +441,78 @@ public function modelReverseTransform($class, array $array = []) return $instance; } + /** + * NEXT_MAJOR: Remove this method. + * + * @deprecated since sonata-project/doctrine-mongodb-admin-bundle 3.x and will be removed in version 4.0. + */ public function getModelCollectionInstance($class) { + @trigger_error(sprintf( + 'Method %s() is deprecated since sonata-project/doctrine-mongodb-admin-bundle 3.x and will be removed in version 4.0.', + __METHOD__ + ), E_USER_DEPRECATED); + return new ArrayCollection(); } + /** + * NEXT_MAJOR: Remove this method. + * + * @deprecated since sonata-project/doctrine-mongodb-admin-bundle 3.x and will be removed in version 4.0. + */ public function collectionClear(&$collection) { + @trigger_error(sprintf( + 'Method %s() is deprecated since sonata-project/doctrine-mongodb-admin-bundle 3.x and will be removed in version 4.0.', + __METHOD__ + ), E_USER_DEPRECATED); + return $collection->clear(); } + /** + * NEXT_MAJOR: Remove this method. + * + * @deprecated since sonata-project/doctrine-mongodb-admin-bundle 3.x and will be removed in version 4.0. + */ public function collectionHasElement(&$collection, &$element) { + @trigger_error(sprintf( + 'Method %s() is deprecated since sonata-project/doctrine-mongodb-admin-bundle 3.x and will be removed in version 4.0.', + __METHOD__ + ), E_USER_DEPRECATED); + return $collection->contains($element); } + /** + * NEXT_MAJOR: Remove this method. + * + * @deprecated since sonata-project/doctrine-mongodb-admin-bundle 3.x and will be removed in version 4.0. + */ public function collectionAddElement(&$collection, &$element) { + @trigger_error(sprintf( + 'Method %s() is deprecated since sonata-project/doctrine-mongodb-admin-bundle 3.x and will be removed in version 4.0.', + __METHOD__ + ), E_USER_DEPRECATED); + return $collection->add($element); } + /** + * NEXT_MAJOR: Remove this method. + * + * @deprecated since sonata-project/doctrine-mongodb-admin-bundle 3.x and will be removed in version 4.0. + */ public function collectionRemoveElement(&$collection, &$element) { + @trigger_error(sprintf( + 'Method %s() is deprecated since sonata-project/doctrine-mongodb-admin-bundle 3.x and will be removed in version 4.0.', + __METHOD__ + ), E_USER_DEPRECATED); + return $collection->removeElement($element); } diff --git a/tests/App/public/bundles/sonataadmin b/tests/App/public/bundles/sonataadmin new file mode 120000 index 00000000..be0b1571 --- /dev/null +++ b/tests/App/public/bundles/sonataadmin @@ -0,0 +1 @@ +/Users/fran/projects/SonataDoctrineMongoDBAdminBundle/vendor/sonata-project/admin-bundle/src/Resources/public \ No newline at end of file diff --git a/tests/App/public/bundles/sonatacore b/tests/App/public/bundles/sonatacore new file mode 120000 index 00000000..09b071e1 --- /dev/null +++ b/tests/App/public/bundles/sonatacore @@ -0,0 +1 @@ +/Users/fran/projects/SonataDoctrineMongoDBAdminBundle/vendor/sonata-project/admin-bundle/src/Resources/private/SonataCoreBundleAssets \ No newline at end of file diff --git a/tests/App/public/bundles/sonatatwig b/tests/App/public/bundles/sonatatwig new file mode 120000 index 00000000..0b37a238 --- /dev/null +++ b/tests/App/public/bundles/sonatatwig @@ -0,0 +1 @@ +/Users/fran/projects/SonataDoctrineMongoDBAdminBundle/vendor/sonata-project/twig-extensions/src/Bridge/Symfony/Resources/public \ No newline at end of file diff --git a/tests/Model/ModelManagerTest.php b/tests/Model/ModelManagerTest.php index 4b0ad864..85b6aab9 100644 --- a/tests/Model/ModelManagerTest.php +++ b/tests/Model/ModelManagerTest.php @@ -33,12 +33,15 @@ use Sonata\DoctrineMongoDBAdminBundle\Tests\Fixtures\Document\SimpleDocument; use Sonata\DoctrineMongoDBAdminBundle\Tests\Fixtures\Document\SimpleDocumentWithPrivateSetter; use Symfony\Bridge\Doctrine\ManagerRegistry; +use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait; use Symfony\Component\PropertyAccess\Exception\NoSuchPropertyException; use Symfony\Component\PropertyAccess\PropertyAccess; use Symfony\Component\PropertyAccess\PropertyAccessor; final class ModelManagerTest extends TestCase { + use ExpectDeprecationTrait; + /** * @var PropertyAccessor */ @@ -89,6 +92,11 @@ public function testGetNormalizedIdentifierNull(): void $this->assertNull($manager->getNormalizedIdentifier(null)); } + /** + * NEXT_MAJOR: Remove this method. + * + * @group legacy + */ public function testSortParameters(): void { $manager = new ModelManager($this->registry, $this->propertyAccessor); @@ -120,6 +128,7 @@ public function testSortParameters(): void '_sort_order' => 'ASC', ]); + $this->expectDeprecation('Method Sonata\DoctrineMongoDBAdminBundle\Model\ModelManager::getSortParameters() is deprecated since sonata-project/doctrine-mongodb-admin-bundle 3.x and will be removed in version 4.0.'); $parameters = $manager->getSortParameters($field1, $datagrid1); $this->assertSame('DESC', $parameters['filter']['_sort_order']); @@ -239,10 +248,16 @@ public function testModelReverseTransformFailsWithPrivateProperties2(): void $manager->modelReverseTransform($class, ['plumbus' => 42]); } + /** + * NEXT_MAJOR: Remove this test. + * + * @group legacy + */ public function testCollections(): void { $model = new ModelManager($this->registry, $this->propertyAccessor); + $this->expectDeprecation('Method Sonata\DoctrineMongoDBAdminBundle\Model\ModelManager::getModelCollectionInstance() is deprecated since sonata-project/doctrine-mongodb-admin-bundle 3.x and will be removed in version 4.0.'); $collection = $model->getModelCollectionInstance('whyDoWeEvenHaveThisParameter'); $this->assertInstanceOf(ArrayCollection::class, $collection); @@ -272,6 +287,11 @@ public function testModelTransform(): void $this->assertSame($instance, $result); } + /** + * NEXT_MAJOR: Remove this test. + * + * @group legacy + */ public function testGetPaginationParameters(): void { $datagrid = $this->createMock(DatagridInterface::class); @@ -287,6 +307,7 @@ public function testGetPaginationParameters(): void $model = new ModelManager($this->registry, $this->propertyAccessor); + $this->expectDeprecation('Method Sonata\DoctrineMongoDBAdminBundle\Model\ModelManager::getPaginationParameters() is deprecated since sonata-project/doctrine-mongodb-admin-bundle 3.x and will be removed in version 4.0.'); $result = $model->getPaginationParameters($datagrid, $page = 5); $this->assertSame($page, $result['filter']['_page']);