mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-09-26 16:45:01 +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;
|
namespace Chill\ActivityBundle\Tests\Security\Authorization;
|
||||||
|
|
||||||
|
use Chill\ActivityBundle\Security\Authorization\ActivityVoter;
|
||||||
use Chill\ActivityBundle\Test\PrepareActivityTrait;
|
use Chill\ActivityBundle\Test\PrepareActivityTrait;
|
||||||
use Chill\MainBundle\Entity\Center;
|
use Chill\MainBundle\Entity\Center;
|
||||||
use Chill\MainBundle\Entity\Scope;
|
use Chill\MainBundle\Entity\Scope;
|
||||||
@@ -18,8 +19,11 @@ use Chill\MainBundle\Entity\User;
|
|||||||
use Chill\MainBundle\Test\PrepareCenterTrait;
|
use Chill\MainBundle\Test\PrepareCenterTrait;
|
||||||
use Chill\MainBundle\Test\PrepareScopeTrait;
|
use Chill\MainBundle\Test\PrepareScopeTrait;
|
||||||
use Chill\MainBundle\Test\PrepareUserTrait;
|
use Chill\MainBundle\Test\PrepareUserTrait;
|
||||||
|
use Chill\PersonBundle\Security\Authorization\PersonVoter;
|
||||||
use Chill\PersonBundle\Test\PreparePersonTrait;
|
use Chill\PersonBundle\Test\PreparePersonTrait;
|
||||||
|
use Prophecy\Prophet;
|
||||||
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
|
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
|
||||||
|
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
|
||||||
use Symfony\Component\Security\Core\Authorization\Voter\VoterInterface;
|
use Symfony\Component\Security\Core\Authorization\Voter\VoterInterface;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -39,22 +43,16 @@ final class ActivityVoterTest extends KernelTestCase
|
|||||||
|
|
||||||
use PrepareUserTrait;
|
use PrepareUserTrait;
|
||||||
|
|
||||||
/**
|
protected Prophet $prophet;
|
||||||
* @var \Prophecy\Prophet
|
|
||||||
*/
|
|
||||||
protected $prophet;
|
|
||||||
|
|
||||||
/**
|
protected ActivityVoter $voter;
|
||||||
* @var \Chill\PersonBundle\Security\Authorization\PersonVoter
|
|
||||||
*/
|
|
||||||
protected $voter;
|
|
||||||
|
|
||||||
protected function setUp(): void
|
protected function setUp(): void
|
||||||
{
|
{
|
||||||
self::bootKernel();
|
self::bootKernel();
|
||||||
$this->voter = self::$kernel->getContainer()
|
$this->voter = self::getContainer()
|
||||||
->get('chill.activity.security.authorization.activity_voter');
|
->get(ActivityVoter::class);
|
||||||
$this->prophet = new \Prophecy\Prophet();
|
$this->prophet = new Prophet();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testNullUser(): void
|
public function testNullUser(): void
|
||||||
@@ -75,17 +73,15 @@ final class ActivityVoterTest extends KernelTestCase
|
|||||||
/**
|
/**
|
||||||
* @dataProvider dataProvider_testVoteAction
|
* @dataProvider dataProvider_testVoteAction
|
||||||
*
|
*
|
||||||
* @param type $expectedResult
|
* @param type $expectedResult
|
||||||
* @param string $attribute
|
|
||||||
* @param string $message
|
|
||||||
*/
|
*/
|
||||||
public function testVoteAction(
|
public function testVoteAction(
|
||||||
$expectedResult,
|
$expectedResult,
|
||||||
User $user,
|
User $user,
|
||||||
Scope $scope,
|
Scope $scope,
|
||||||
Center $center,
|
Center $center,
|
||||||
$attribute,
|
string $attribute,
|
||||||
$message,
|
string $message,
|
||||||
): void {
|
): void {
|
||||||
$token = $this->prepareToken($user);
|
$token = $this->prepareToken($user);
|
||||||
$activity = $this->prepareActivity($scope, $this->preparePerson($center));
|
$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');
|
$centerA = $this->prepareCenter(1, 'center A');
|
||||||
$centerB = $this->prepareCenter(2, 'center B');
|
$centerB = $this->prepareCenter(2, 'center B');
|
||||||
@@ -154,14 +150,12 @@ final class ActivityVoterTest extends KernelTestCase
|
|||||||
* prepare a token interface with correct rights.
|
* prepare a token interface with correct rights.
|
||||||
*
|
*
|
||||||
* if $permissions = null, user will be null (no user associated with token
|
* 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 = $this->prophet->prophesize();
|
||||||
$token
|
$token
|
||||||
->willImplement('\\'.\Symfony\Component\Security\Core\Authentication\Token\TokenInterface::class);
|
->willImplement('\\'.TokenInterface::class);
|
||||||
|
|
||||||
if (null === $user) {
|
if (null === $user) {
|
||||||
$token->getUser()->willReturn(null);
|
$token->getUser()->willReturn(null);
|
||||||
|
@@ -31,7 +31,7 @@ final class RedisConnectionFactory implements EventSubscriberInterface
|
|||||||
$this->redis = new ChillRedis();
|
$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);
|
$result = $this->redis->connect($this->host, $this->port, $this->timeout);
|
||||||
|
|
||||||
|
@@ -12,6 +12,8 @@ declare(strict_types=1);
|
|||||||
namespace Chill\PersonBundle\Test;
|
namespace Chill\PersonBundle\Test;
|
||||||
|
|
||||||
use Chill\MainBundle\Entity\Center;
|
use Chill\MainBundle\Entity\Center;
|
||||||
|
use Chill\MainBundle\Entity\Gender;
|
||||||
|
use Chill\MainBundle\Entity\GenderEnum;
|
||||||
use Chill\PersonBundle\Entity\Person;
|
use Chill\PersonBundle\Entity\Person;
|
||||||
|
|
||||||
trait PreparePersonTrait
|
trait PreparePersonTrait
|
||||||
@@ -25,15 +27,16 @@ trait PreparePersonTrait
|
|||||||
* - gender
|
* - gender
|
||||||
*
|
*
|
||||||
* This person should not be persisted in a database
|
* 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())
|
return (new Person())
|
||||||
->setCenter($center)
|
->setCenter($center)
|
||||||
->setFirstName('test firstname')
|
->setFirstName('test firstname')
|
||||||
->setLastName('default lastname')
|
->setLastName('default lastname')
|
||||||
->setGender(Person::MALE_GENDER);
|
->setGender($gender);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user