Attempt fix ActivityVoterTest.php

This commit is contained in:
2025-09-11 12:44:06 +02:00
parent 94b5c06d10
commit 6ceb1b9544
3 changed files with 23 additions and 26 deletions

View File

@@ -11,6 +11,7 @@ declare(strict_types=1);
namespace Chill\ActivityBundle\Tests\Security\Authorization;
use Chill\ActivityBundle\Security\Authorization\ActivityVoter;
use Chill\ActivityBundle\Test\PrepareActivityTrait;
use Chill\MainBundle\Entity\Center;
use Chill\MainBundle\Entity\Scope;
@@ -18,8 +19,11 @@ use Chill\MainBundle\Entity\User;
use Chill\MainBundle\Test\PrepareCenterTrait;
use Chill\MainBundle\Test\PrepareScopeTrait;
use Chill\MainBundle\Test\PrepareUserTrait;
use Chill\PersonBundle\Security\Authorization\PersonVoter;
use Chill\PersonBundle\Test\PreparePersonTrait;
use Prophecy\Prophet;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Symfony\Component\Security\Core\Authorization\Voter\VoterInterface;
/**
@@ -39,22 +43,16 @@ final class ActivityVoterTest extends KernelTestCase
use PrepareUserTrait;
/**
* @var \Prophecy\Prophet
*/
protected $prophet;
protected Prophet $prophet;
/**
* @var \Chill\PersonBundle\Security\Authorization\PersonVoter
*/
protected $voter;
protected ActivityVoter $voter;
protected function setUp(): void
{
self::bootKernel();
$this->voter = self::$kernel->getContainer()
->get('chill.activity.security.authorization.activity_voter');
$this->prophet = new \Prophecy\Prophet();
$this->voter = self::getContainer()
->get(ActivityVoter::class);
$this->prophet = new Prophet();
}
public function testNullUser(): void
@@ -75,17 +73,15 @@ final class ActivityVoterTest extends KernelTestCase
/**
* @dataProvider dataProvider_testVoteAction
*
* @param type $expectedResult
* @param string $attribute
* @param string $message
* @param type $expectedResult
*/
public function testVoteAction(
$expectedResult,
User $user,
Scope $scope,
Center $center,
$attribute,
$message,
string $attribute,
string $message,
): void {
$token = $this->prepareToken($user);
$activity = $this->prepareActivity($scope, $this->preparePerson($center));
@@ -97,7 +93,7 @@ final class ActivityVoterTest extends KernelTestCase
);
}
public function dataProvider_testVoteAction()
public function dataProvider_testVoteAction(): array
{
$centerA = $this->prepareCenter(1, 'center A');
$centerB = $this->prepareCenter(2, 'center B');
@@ -154,14 +150,12 @@ final class ActivityVoterTest extends KernelTestCase
* prepare a token interface with correct rights.
*
* if $permissions = null, user will be null (no user associated with token
*
* @return \Symfony\Component\Security\Core\Authentication\Token\TokenInterface
*/
protected function prepareToken(?User $user = null)
protected function prepareToken(?User $user = null): object
{
$token = $this->prophet->prophesize();
$token
->willImplement('\\'.\Symfony\Component\Security\Core\Authentication\Token\TokenInterface::class);
->willImplement('\\'.TokenInterface::class);
if (null === $user) {
$token->getUser()->willReturn(null);

View File

@@ -31,7 +31,7 @@ final class RedisConnectionFactory implements EventSubscriberInterface
$this->redis = new ChillRedis();
}
public function create(): \Chill\MainBundle\Redis\ChillRedis
public function create(): ChillRedis
{
$result = $this->redis->connect($this->host, $this->port, $this->timeout);

View File

@@ -12,6 +12,8 @@ declare(strict_types=1);
namespace Chill\PersonBundle\Test;
use Chill\MainBundle\Entity\Center;
use Chill\MainBundle\Entity\Gender;
use Chill\MainBundle\Entity\GenderEnum;
use Chill\PersonBundle\Entity\Person;
trait PreparePersonTrait
@@ -25,15 +27,16 @@ trait PreparePersonTrait
* - gender
*
* This person should not be persisted in a database
*
* @return Person
*/
protected function preparePerson(Center $center): \Chill\PersonBundle\Entity\Person
protected function preparePerson(Center $center): Person
{
$gender = new Gender();
$gender->setLabel([GenderEnum::MALE]);
return (new Person())
->setCenter($center)
->setFirstName('test firstname')
->setLastName('default lastname')
->setGender(Person::MALE_GENDER);
->setGender($gender);
}
}