AuthorizationHelper: compare center and scope based on id, not on equality

For an unknown reason, in some circumstances, the use of the `===` comparator does not work when comparing Center instances and Scope instances. Then, we compare them based on the id.
This commit is contained in:
2023-09-13 10:08:44 +02:00
parent 2ce29f36ff
commit d3b68f8f8f
3 changed files with 53 additions and 31 deletions

View File

@@ -11,6 +11,8 @@ declare(strict_types=1);
namespace Chill\MainBundle\Test;
use Chill\MainBundle\Entity\Center;
/**
* A trait to prepare center.
*
@@ -25,23 +27,17 @@ trait PrepareCenterTrait
/**
* prepare a mocked center, with and id and name given.
*
* @param int $id
* @param string $name
*
* @return \Chill\MainBundle\Entity\Center
*/
protected function prepareCenter($id, $name)
protected function prepareCenter(int $id, string $name): Center
{
if (null === $this->centerProphet) {
$this->centerProphet = new \Prophecy\Prophet();
}
$center = new Center();
$center->setName($name);
$center = $this->centerProphet->prophesize();
$center->willExtend('\\' . \Chill\MainBundle\Entity\Center::class);
$center->getId()->willReturn($id);
$center->getName()->willReturn($name);
$reflectionClass = new \ReflectionClass($center);
$reflectionId = $reflectionClass->getProperty('id');
$reflectionId->setAccessible(true);
$reflectionId->setValue($center, $id);
return $center->reveal();
return $center;
}
}