mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-09-25 16:14:59 +00:00
Attempt fix ActivityVoterTest.php
This commit is contained in:
@@ -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);
|
||||
|
@@ -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);
|
||||
|
||||
|
@@ -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);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user