Skip to content

Commit

Permalink
Deprecate Pool::getGroups
Browse files Browse the repository at this point in the history
This function does not work and it throws a RuntimeError because
the internal the array  property adminGroups changed some time
ago its content, but this function was not updated.
  • Loading branch information
franmomu committed Dec 6, 2020
1 parent fc4c26f commit afde2f4
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
1 change: 1 addition & 0 deletions UPGRADE-3.x.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ Argument 2 of `Sonata\AdminBundle\Model\ModelManagerInterface::createQuery()` me
Use `Sonata\AdminBundle\SonataConfiguration::getLogo()` instead.
- `Sonata\AdminBundle\Admin\Pool::getOption()` method has been deprecated.
Use `Sonata\AdminBundle\SonataConfiguration::getOption()` instead.
- `Sonata\AdminBundle\Admin\Pool::getGroups()` method has been deprecated.

### Sonata\AdminBundle\Admin\FieldDescriptionInterface

Expand Down
12 changes: 12 additions & 0 deletions src/Admin/Pool.php
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,20 @@ public function __construct(
$this->propertyAccessor = $propertyAccessor;
}

/**
* NEXT_MAJOR: Remove this method.
*
* @deprecated since sonata-project/admin-bundle 3.x and will be removed in 4.0.
*
* @return array
*/
public function getGroups()
{
@trigger_error(sprintf(
'Method "%s()" is deprecated since sonata-project/admin-bundle 3.x and will be removed in version 4.0.',
__METHOD__
), E_USER_DEPRECATED);

$groups = $this->adminGroups;

foreach ($this->adminGroups as $name => $adminGroup) {
Expand Down
10 changes: 10 additions & 0 deletions tests/Admin/PoolTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,14 @@
use Sonata\AdminBundle\Admin\AdminInterface;
use Sonata\AdminBundle\Admin\Pool;
use Sonata\AdminBundle\Templating\MutableTemplateRegistryInterface;
use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait;
use Symfony\Component\DependencyInjection\Container;
use Symfony\Component\DependencyInjection\ContainerInterface;

class PoolTest extends TestCase
{
use ExpectDeprecationTrait;

/**
* @var Container
*/
Expand All @@ -40,6 +43,11 @@ protected function setUp(): void
$this->pool = new Pool($this->container, 'Sonata Admin', '/path/to/pic.png', ['foo' => 'bar']);
}

/**
* NEXT_MAJOR: Remove this method.
*
* @group legacy
*/
public function testGetGroups(): void
{
$this->container->set('sonata.user.admin.group1', $this->createMock(AdminInterface::class));
Expand All @@ -50,6 +58,8 @@ public function testGetGroups(): void
'adminGroup1' => ['sonata.user.admin.group1' => []],
]);

$this->expectDeprecation('Method "Sonata\AdminBundle\Admin\Pool::getGroups()" is deprecated since sonata-project/admin-bundle 3.x and will be removed in version 4.0.');

$result = $this->pool->getGroups();
$this->assertArrayHasKey('adminGroup1', $result);
$this->assertArrayHasKey('sonata.user.admin.group1', $result['adminGroup1']);
Expand Down

0 comments on commit afde2f4

Please sign in to comment.