Skip to content

Commit

Permalink
Deprecate Pool::hasGroup and Pool::getAdminsByGroup
Browse files Browse the repository at this point in the history
They were added in #1465,
but they have never been used in our code.
  • Loading branch information
franmomu authored and VincentLanglet committed Dec 8, 2020
1 parent d6790b3 commit 916877e
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 2 deletions.
2 changes: 2 additions & 0 deletions UPGRADE-3.x.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ Argument 2 of `Sonata\AdminBundle\Model\ModelManagerInterface::createQuery()` me
- `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\Pool::hasGroup()` method has been deprecated.
- `Sonata\AdminBundle\Admin\Pool::getAdminsByGroup()` method has been deprecated.

### Sonata\AdminBundle\Admin\FieldDescriptionInterface

Expand Down
18 changes: 18 additions & 0 deletions src/Admin/Pool.php
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,10 @@ public function getGroups()
}

/**
* NEXT_MAJOR: Remove this method.
*
* @deprecated since sonata-project/admin-bundle 3.x and will be removed in 4.0.
*
* Returns whether an admin group exists or not.
*
* @param string $group
Expand All @@ -190,6 +194,11 @@ public function getGroups()
*/
public function hasGroup($group)
{
@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);

return isset($this->adminGroups[$group]);
}

Expand Down Expand Up @@ -237,6 +246,10 @@ public function getDashboardGroups()
}

/**
* NEXT_MAJOR: Remove this method.
*
* @deprecated since sonata-project/admin-bundle 3.x and will be removed in 4.0.
*
* Returns all admins related to the given $group.
*
* @param string $group
Expand All @@ -247,6 +260,11 @@ public function getDashboardGroups()
*/
public function getAdminsByGroup($group)
{
@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);

if (!isset($this->adminGroups[$group])) {
throw new \InvalidArgumentException(sprintf('Group "%s" not found in admin pool.', $group));
}
Expand Down
30 changes: 28 additions & 2 deletions tests/Admin/PoolTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,19 @@ public function testGetGroups(): void
$this->assertArrayHasKey('sonata.user.admin.group1', $result['adminGroup1']);
}

/**
* NEXT_MAJOR: Remove this test.
*
* @group legacy
*/
public function testHasGroup(): void
{
$this->pool->setAdminGroups([
'adminGroup1' => [],
]);

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

$this->assertTrue($this->pool->hasGroup('adminGroup1'));
$this->assertFalse($this->pool->hasGroup('adminGroup2'));
}
Expand Down Expand Up @@ -113,26 +120,43 @@ public function testGetDashboardGroups(): void
$this->assertSame($adminGroup1, $groups['adminGroup1']['items']['itemKey']);
}

/**
* NEXT_MAJOR: Remove this test.
*
* @group legacy
*/
public function testGetAdminsByGroupWhenGroupNotSet(): void
{
$this->expectException(\InvalidArgumentException::class);

$this->pool->setAdminGroups([
'adminGroup1' => [],
]);

$this->expectException(\InvalidArgumentException::class);

$this->pool->getAdminsByGroup('adminGroup2');
}

/**
* NEXT_MAJOR: Remove this test.
*
* @group legacy
*/
public function testGetAdminsByGroupWhenGroupIsEmpty(): void
{
$this->pool->setAdminGroups([
'adminGroup1' => [],
]);

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

$this->assertSame([], $this->pool->getAdminsByGroup('adminGroup1'));
}

/**
* NEXT_MAJOR: Remove this test.
*
* @group legacy
*/
public function testGetAdminsByGroup(): void
{
$this->container->set('sonata.admin1', $this->createMock(AdminInterface::class));
Expand All @@ -153,6 +177,8 @@ public function testGetAdminsByGroup(): void
],
]);

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

$this->assertCount(2, $this->pool->getAdminsByGroup('adminGroup1'));
$this->assertCount(1, $this->pool->getAdminsByGroup('adminGroup2'));
}
Expand Down

0 comments on commit 916877e

Please sign in to comment.