diff --git a/src/Bundle/ChillMainBundle/Test/PrepareCircleTrait.php b/src/Bundle/ChillMainBundle/Test/PrepareCircleTrait.php deleted file mode 100644 index 8cbe9337c..000000000 --- a/src/Bundle/ChillMainBundle/Test/PrepareCircleTrait.php +++ /dev/null @@ -1,47 +0,0 @@ -circleProphet) { - $this->circleProphet = new \Prophecy\Prophet(); - } - - $scope = $this->circleProphet->prophesize(); - $scope->willExtend('\\' . \Chill\MainBundle\Entity\Scope::class); - $scope->getId()->willReturn($id); - $scope->getName()->willReturn($name); - - return $scope->reveal(); - } -} diff --git a/src/Bundle/ChillMainBundle/Test/PrepareScopeTrait.php b/src/Bundle/ChillMainBundle/Test/PrepareScopeTrait.php index 4ac86af79..dbd1825d8 100644 --- a/src/Bundle/ChillMainBundle/Test/PrepareScopeTrait.php +++ b/src/Bundle/ChillMainBundle/Test/PrepareScopeTrait.php @@ -11,6 +11,8 @@ declare(strict_types=1); namespace Chill\MainBundle\Test; +use Chill\MainBundle\Entity\Scope; + /** * A trait to prepare center. * @@ -18,25 +20,24 @@ namespace Chill\MainBundle\Test; * and use tearDownTrait after usage. * * @codeCoverageIgnore - * - * @deprecated use PrepareCircleTrait instead */ trait PrepareScopeTrait { - use PrepareCircleTrait; - /** - * prepare a mocked center, with and id and name given. + * prepare a mocked scope, with and id and name given. * - * @param int $id - * @param string $name - * - * @return \Chill\MainBundle\Entity\Center - * - * @deprecated + * The name will be present in both lang `fr` and `en`. */ - protected function prepareScope($id, $name) + protected function prepareScope(int $id, string $name): Scope { - return $this->prepareCircle($id, $name); + $scope = new Scope(); + // set the name + $scope->setName(['fr' => $name, 'en' => $name]); + $reflection = new \ReflectionClass($scope); + $idProperty = $reflection->getProperty('id'); + $idProperty->setAccessible(true); + $idProperty->setValue($scope, $id); + + return $scope; } } diff --git a/src/Bundle/ChillMainBundle/Tests/Security/Authorization/AuthorizationHelperTest.php b/src/Bundle/ChillMainBundle/Tests/Security/Authorization/AuthorizationHelperTest.php index 3f0e6a71d..02d7fce80 100644 --- a/src/Bundle/ChillMainBundle/Tests/Security/Authorization/AuthorizationHelperTest.php +++ b/src/Bundle/ChillMainBundle/Tests/Security/Authorization/AuthorizationHelperTest.php @@ -18,13 +18,12 @@ use Chill\MainBundle\Entity\HasScopeInterface; use Chill\MainBundle\Entity\HasScopesInterface; use Chill\MainBundle\Entity\Scope; use Chill\MainBundle\Entity\User; +use Chill\MainBundle\Security\Authorization\AuthorizationHelper; use Chill\MainBundle\Test\PrepareCenterTrait; use Chill\MainBundle\Test\PrepareScopeTrait; use Chill\MainBundle\Test\PrepareUserTrait; -use Chill\MainBundle\Test\ProphecyTrait; +use Prophecy\PhpUnit\ProphecyTrait; use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; -use Symfony\Component\Security\Core\Role\Role; -use function array_map; use function in_array; /** @@ -198,24 +197,6 @@ final class AuthorizationHelperTest extends KernelTestCase ]; } - public function testFindUsersReaching() - { - $centerA = self::$kernel->getContainer() - ->get('doctrine.orm.entity_manager') - ->getRepository(Center::class) - ->findOneByName('Center A'); - - $users = $this->getAuthorizationHelper() - ->findUsersReaching( - 'CHILL_PERSON_SEE', - $centerA - ); - - $usernames = array_map(static fn (User $u) => $u->getUsername(), $users); - - $this->assertContains('center a_social', $usernames); - } - public function testGetParentRoles() { $parentRoles = $this->getAuthorizationHelper() @@ -272,7 +253,7 @@ final class AuthorizationHelperTest extends KernelTestCase ], ]); $helper = $this->getAuthorizationHelper(); - $entity = $this->getProphet()->prophesize(); + $entity = $this->prophesize(); $entity->willImplement('\\' . \Chill\MainBundle\Entity\HasCenterInterface::class); $entity->willImplement('\\' . \Chill\MainBundle\Entity\HasScopeInterface::class); $entity->getCenter()->willReturn($center); @@ -338,7 +319,7 @@ final class AuthorizationHelperTest extends KernelTestCase ], ]); $helper = $this->getAuthorizationHelper(); - $entity = $this->getProphet()->prophesize(); + $entity = $this->prophesize(); $entity->willImplement(HasCentersInterface::class); $entity->willImplement(HasScopesInterface::class); $entity->getCenters()->willReturn([$centerA, $centerB]); @@ -360,7 +341,7 @@ final class AuthorizationHelperTest extends KernelTestCase ], ]); $helper = $this->getAuthorizationHelper(); - $entity = $this->getProphet()->prophesize(); + $entity = $this->prophesize(); $entity->willImplement(HasCentersInterface::class); $entity->getCenters()->willReturn([$center, $centerB]); @@ -379,7 +360,7 @@ final class AuthorizationHelperTest extends KernelTestCase ], ]); $helper = $this->getAuthorizationHelper(); - $entity = $this->getProphet()->prophesize(); + $entity = $this->prophesize(); $entity->willImplement('\\' . \Chill\MainBundle\Entity\HasCenterInterface::class); $entity->getCenter()->willReturn($center); @@ -403,7 +384,7 @@ final class AuthorizationHelperTest extends KernelTestCase ]); $helper = $this->getAuthorizationHelper(); - $entity = $this->getProphet()->prophesize(); + $entity = $this->prophesize(); $entity->willImplement('\\' . \Chill\MainBundle\Entity\HasCenterInterface::class); $entity->getCenter()->willReturn($center); @@ -427,7 +408,7 @@ final class AuthorizationHelperTest extends KernelTestCase ], ]); $helper = $this->getAuthorizationHelper(); - $entity = $this->getProphet()->prophesize(); + $entity = $this->prophesize(); $entity->willImplement('\\' . \Chill\MainBundle\Entity\HasCenterInterface::class); $entity->willImplement('\\' . \Chill\MainBundle\Entity\HasScopeInterface::class); $entity->getCenter()->willReturn($centerB); @@ -448,7 +429,7 @@ final class AuthorizationHelperTest extends KernelTestCase ], ]); $helper = $this->getAuthorizationHelper(); - $entity = $this->getProphet()->prophesize(); + $entity = $this->prophesize(); $entity->willImplement('\\' . \Chill\MainBundle\Entity\HasCenterInterface::class); $entity->getCenter()->willReturn($center); @@ -467,7 +448,7 @@ final class AuthorizationHelperTest extends KernelTestCase ], ]); $helper = $this->getAuthorizationHelper(); - $entity = $this->getProphet()->prophesize(); + $entity = $this->prophesize(); $entity->willImplement('\\' . \Chill\MainBundle\Entity\HasCenterInterface::class); $entity->willImplement('\\' . \Chill\MainBundle\Entity\HasScopeInterface::class); $entity->getCenter()->willReturn($center); @@ -499,7 +480,7 @@ final class AuthorizationHelperTest extends KernelTestCase ], ]); $helper = $this->getAuthorizationHelper(); - $entity = $this->getProphet()->prophesize(); + $entity = $this->prophesize(); $entity->willImplement('\\' . \Chill\MainBundle\Entity\HasCenterInterface::class); $entity->getCenter()->willReturn($centerA); @@ -519,7 +500,7 @@ final class AuthorizationHelperTest extends KernelTestCase ], ]); $helper = $this->getAuthorizationHelper(); - $entity = $this->getProphet()->prophesize(); + $entity = $this->prophesize(); $entity->willImplement(HasCenterInterface::class); $entity->willImplement(HasScopeInterface::class); $entity->getCenter()->willReturn($center); @@ -543,7 +524,7 @@ final class AuthorizationHelperTest extends KernelTestCase ], ]); $helper = $this->getAuthorizationHelper(); - $entity = $this->getProphet()->prophesize(); + $entity = $this->prophesize(); $entity->willImplement(HasCentersInterface::class); $entity->willImplement(HasScopesInterface::class); $entity->getCenters()->willReturn([$centerA, $centerB]); @@ -566,7 +547,7 @@ final class AuthorizationHelperTest extends KernelTestCase ], ]); $helper = $this->getAuthorizationHelper(); - $entity = $this->getProphet()->prophesize(); + $entity = $this->prophesize(); $entity->willImplement(HasCentersInterface::class); $entity->getCenters()->willReturn([$centerB, $centerC]); @@ -579,6 +560,6 @@ final class AuthorizationHelperTest extends KernelTestCase private function getAuthorizationHelper() { return self::$container - ->get('chill.main.security.authorization.helper'); + ->get(AuthorizationHelper::class); } }