mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-09-05 06:14:59 +00:00
fix tests
This commit is contained in:
@@ -76,12 +76,18 @@ final readonly class ReferrerFilter implements FilterInterface
|
||||
|
||||
public function normalizeFormData(array $formData): array
|
||||
{
|
||||
return ['accepted_agents' => $this->normalizeDoctrineEntity($formData['accepted_agents']), 'agent_at' => $formData['agent_at']->normalize()];
|
||||
return [
|
||||
'accepted_agents' => $this->normalizeDoctrineEntity($formData['accepted_agents']),
|
||||
'agent_at' => array_key_exists('agent_at', $formData) ? $formData['agent_at']?->normalize() : (new RollingDate(RollingDate::T_TODAY))->normalize(),
|
||||
];
|
||||
}
|
||||
|
||||
public function denormalizeFormData(array $formData, int $fromVersion): array
|
||||
{
|
||||
return ['accepted_agents' => $this->denormalizeDoctrineEntity($formData['accepted_agents'], $this->userRepository), 'agent_at' => RollingDate::fromNormalized($formData['agent_at'])];
|
||||
return [
|
||||
'accepted_agents' => $this->denormalizeDoctrineEntity($formData['accepted_agents'], $this->userRepository),
|
||||
'agent_at' => array_key_exists('agent_at', $formData) ? RollingDate::fromNormalized($formData['agent_at']) : new RollingDate(RollingDate::T_TODAY),
|
||||
];
|
||||
}
|
||||
|
||||
public function getFormDefaultData(): array
|
||||
|
@@ -12,7 +12,6 @@ declare(strict_types=1);
|
||||
namespace Chill\PersonBundle\Tests\Export\Export;
|
||||
|
||||
use Chill\MainBundle\Entity\Center;
|
||||
use Chill\MainBundle\Entity\User;
|
||||
use Chill\MainBundle\Repository\CenterRepositoryInterface;
|
||||
use Chill\MainBundle\Repository\ScopeRepositoryInterface;
|
||||
use Chill\MainBundle\Security\Authorization\AuthorizationHelperForCurrentUserInterface;
|
||||
@@ -27,7 +26,6 @@ use Chill\PersonBundle\Security\Authorization\AccompanyingPeriodVoter;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Prophecy\Argument;
|
||||
use Prophecy\PhpUnit\ProphecyTrait;
|
||||
use Symfony\Component\Security\Core\Security;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
|
@@ -15,6 +15,7 @@ use Chill\MainBundle\Test\Export\AbstractFilterTest;
|
||||
use Chill\PersonBundle\Entity\AccompanyingPeriod\AccompanyingPeriodWork;
|
||||
use Chill\PersonBundle\Export\Filter\AccompanyingCourseFilters\HandlingThirdPartyFilter;
|
||||
use Chill\ThirdPartyBundle\Entity\ThirdParty;
|
||||
use Chill\ThirdPartyBundle\Repository\ThirdPartyRepository;
|
||||
use Chill\ThirdPartyBundle\Templating\Entity\ThirdPartyRender;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
|
||||
@@ -27,16 +28,19 @@ class HandlingThirdPartyFilterTest extends AbstractFilterTest
|
||||
{
|
||||
private ThirdPartyRender $thirdPartyRender;
|
||||
|
||||
private ThirdPartyRepository $thirdPartyRepository;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
self::bootKernel();
|
||||
$this->thirdPartyRender = self::getContainer()->get(ThirdPartyRender::class);
|
||||
$this->thirdPartyRepository = self::getContainer()->get(ThirdPartyRepository::class);
|
||||
}
|
||||
|
||||
public function getFilter()
|
||||
{
|
||||
return new HandlingThirdPartyFilter($this->thirdPartyRender);
|
||||
return new HandlingThirdPartyFilter($this->thirdPartyRender, $this->thirdPartyRepository);
|
||||
}
|
||||
|
||||
public static function getFormData(): array
|
||||
|
@@ -59,6 +59,49 @@ final class ReferrerFilterTest extends AbstractFilterTest
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider dataProviderFormDataToNormalize
|
||||
*/
|
||||
public function testDataNormalization(array $data, int $version, array $expected): void
|
||||
{
|
||||
$filter = $this->getFilter();
|
||||
|
||||
$normalized = $filter->normalizeFormData($data);
|
||||
$actual = $filter->denormalizeFormData($normalized, $version);
|
||||
|
||||
self::assertEqualsCanonicalizing(array_keys($expected), array_keys($actual));
|
||||
}
|
||||
|
||||
public static function dataProviderFormDataToNormalize(): iterable
|
||||
{
|
||||
self::bootKernel();
|
||||
$em = self::getContainer()->get(EntityManagerInterface::class);
|
||||
$users = array_slice($em->getRepository(User::class)->findAll(), 0, 1);
|
||||
|
||||
yield [
|
||||
[
|
||||
'accepted_agents' => [$users[0]],
|
||||
'agent_at' => new RollingDate(RollingDate::T_TODAY),
|
||||
],
|
||||
1,
|
||||
[
|
||||
'accepted_agents' => [$users[0]],
|
||||
'agent_at' => new RollingDate(RollingDate::T_TODAY),
|
||||
],
|
||||
];
|
||||
|
||||
yield [
|
||||
[
|
||||
'accepted_agents' => [$users[0]],
|
||||
],
|
||||
1,
|
||||
[
|
||||
'accepted_agents' => [$users[0]],
|
||||
'agent_at' => new RollingDate(RollingDate::T_TODAY),
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
public static function getQueryBuilders(): iterable
|
||||
{
|
||||
self::bootKernel();
|
||||
|
Reference in New Issue
Block a user