This commit is contained in:
Julien Fastré 2025-04-08 14:09:16 +02:00
parent 3a904e8ea1
commit a2713041da
Signed by: julienfastre
GPG Key ID: BDE2190974723FCB
11 changed files with 27 additions and 51 deletions

View File

@ -153,8 +153,6 @@ class ListCV implements ListInterface, ExportElementValidatedInterface
* Most of the type, it will be a string which references an entity. * Most of the type, it will be a string which references an entity.
* *
* Example of types : Chill\PersonBundle\Export\Declarations::PERSON_TYPE * Example of types : Chill\PersonBundle\Export\Declarations::PERSON_TYPE
*
* @return string
*/ */
public function getType(): string public function getType(): string
{ {
@ -216,8 +214,6 @@ class ListCV implements ListInterface, ExportElementValidatedInterface
* this function will return `array('count_id')`. * this function will return `array('count_id')`.
* *
* @param mixed[] $data the data from the export's form (added by self::buildForm) * @param mixed[] $data the data from the export's form (added by self::buildForm)
*
* @return array
*/ */
public function getQueryKeys($data): array public function getQueryKeys($data): array
{ {

View File

@ -166,8 +166,6 @@ class ListFrein implements ListInterface, ExportElementValidatedInterface
* Most of the type, it will be a string which references an entity. * Most of the type, it will be a string which references an entity.
* *
* Example of types : Chill\PersonBundle\Export\Declarations::PERSON_TYPE * Example of types : Chill\PersonBundle\Export\Declarations::PERSON_TYPE
*
* @return string
*/ */
public function getType(): string public function getType(): string
{ {
@ -239,8 +237,6 @@ class ListFrein implements ListInterface, ExportElementValidatedInterface
* this function will return `array('count_id')`. * this function will return `array('count_id')`.
* *
* @param mixed[] $data the data from the export's form (added by self::buildForm) * @param mixed[] $data the data from the export's form (added by self::buildForm)
*
* @return array
*/ */
public function getQueryKeys($data): array public function getQueryKeys($data): array
{ {

View File

@ -172,8 +172,6 @@ class ListProjetProfessionnel implements ListInterface, ExportElementValidatedIn
* Most of the type, it will be a string which references an entity. * Most of the type, it will be a string which references an entity.
* *
* Example of types : Chill\PersonBundle\Export\Declarations::PERSON_TYPE * Example of types : Chill\PersonBundle\Export\Declarations::PERSON_TYPE
*
* @return string
*/ */
public function getType(): string public function getType(): string
{ {
@ -245,8 +243,6 @@ class ListProjetProfessionnel implements ListInterface, ExportElementValidatedIn
* this function will return `array('count_id')`. * this function will return `array('count_id')`.
* *
* @param mixed[] $data the data from the export's form (added by self::buildForm) * @param mixed[] $data the data from the export's form (added by self::buildForm)
*
* @return array
*/ */
public function getQueryKeys($data): array public function getQueryKeys($data): array
{ {

View File

@ -38,13 +38,10 @@ interface AggregatorInterface extends ModifierInterface
/** /**
* @param D $formData * @param D $formData
* @return array
*/ */
public function normalizeFormData(array $formData): array; public function normalizeFormData(array $formData): array;
/** /**
* @param array $formData
* @param int $fromVersion
* @return D * @return D
*/ */
public function denormalizeFormData(array $formData, int $fromVersion): array; public function denormalizeFormData(array $formData, int $fromVersion): array;
@ -106,6 +103,7 @@ interface AggregatorInterface extends ModifierInterface
* this function will return `array('count_id')`. * this function will return `array('count_id')`.
* *
* @param D $data the data from the export's form (added by self::buildForm) * @param D $data the data from the export's form (added by self::buildForm)
*
* @return list<string> * @return list<string>
*/ */
public function getQueryKeys(array $data): array; public function getQueryKeys(array $data): array;

View File

@ -151,13 +151,12 @@ interface ExportInterface extends ExportElementInterface
/** /**
* @param D $formData * @param D $formData
* @return array
*/ */
public function normalizeFormData(array $formData): array; public function normalizeFormData(array $formData): array;
/** /**
* @param array $formData the normalized data * @param array $formData the normalized data
* @param int $fromVersion *
* @return D * @return D
*/ */
public function denormalizeFormData(array $formData, int $fromVersion): array; public function denormalizeFormData(array $formData, int $fromVersion): array;

View File

@ -45,13 +45,10 @@ interface FilterInterface extends ModifierInterface
/** /**
* @param D $formData * @param D $formData
* @return array
*/ */
public function normalizeFormData(array $formData): array; public function normalizeFormData(array $formData): array;
/** /**
* @param array $formData
* @param int $fromVersion
* @return D * @return D
*/ */
public function denormalizeFormData(array $formData, int $fromVersion): array; public function denormalizeFormData(array $formData, int $fromVersion): array;

View File

@ -100,7 +100,7 @@ class CSVListFormatter implements FormatterInterface, ExportManagerAwareInterfac
return ['numerotation' => true]; return ['numerotation' => true];
} }
public function getName(): string|\Symfony\Contracts\Translation\TranslatableInterface public function getName(): string|TranslatableInterface
{ {
return 'CSV vertical list'; return 'CSV vertical list';
} }

View File

@ -25,6 +25,7 @@ use Doctrine\ORM\QueryBuilder;
* *
* @template Q of QueryBuilder|NativeQuery * @template Q of QueryBuilder|NativeQuery
* @template D of array * @template D of array
*
* @template-extends ExportInterface<Q, D> * @template-extends ExportInterface<Q, D>
*/ */
interface ListInterface extends ExportInterface {} interface ListInterface extends ExportInterface {}

View File

@ -11,6 +11,8 @@ declare(strict_types=1);
namespace Chill\MainBundle\Test\Export; namespace Chill\MainBundle\Test\Export;
use Chill\MainBundle\Entity\User;
use Chill\MainBundle\Export\ExportGenerationContext;
use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\QueryBuilder; use Doctrine\ORM\QueryBuilder;
use Prophecy\PhpUnit\ProphecyTrait; use Prophecy\PhpUnit\ProphecyTrait;
@ -23,16 +25,6 @@ abstract class AbstractFilterTest extends KernelTestCase
{ {
use ProphecyTrait; use ProphecyTrait;
/**
* @var \Prophecy\Prophet
*/
private $prophet;
protected function setUp(): void
{
$this->prophet = $this->getProphet();
}
public static function tearDownAfterClass(): void public static function tearDownAfterClass(): void
{ {
if (null !== self::getContainer()) { if (null !== self::getContainer()) {
@ -98,6 +90,19 @@ abstract class AbstractFilterTest extends KernelTestCase
} }
} }
private function getUser(): User
{
$em = static::getContainer()->get(EntityManagerInterface::class);
if (null === $user = $em->createQueryBuilder()->select('u')
->from(User::class, 'u')
->setMaxResults(1)
->getQuery()->getOneOrNullResult()) {
throw new \RuntimeException('User not found');
}
return $user;
}
/** /**
* Create a filter which will be used in tests. * Create a filter which will be used in tests.
* *
@ -138,7 +143,7 @@ abstract class AbstractFilterTest extends KernelTestCase
{ {
$aliases = $qb->getAllAliases(); $aliases = $qb->getAllAliases();
$this->getFilter()->alterQuery($qb, $data); $this->getFilter()->alterQuery($qb, $data, new ExportGenerationContext($this->getUser()));
$alteredQuery = $qb->getAllAliases(); $alteredQuery = $qb->getAllAliases();
@ -166,7 +171,9 @@ abstract class AbstractFilterTest extends KernelTestCase
$nbOfSelect = null !== $query->getDQLPart('select') ? $nbOfSelect = null !== $query->getDQLPart('select') ?
\count($query->getDQLPart('select')) : 0; \count($query->getDQLPart('select')) : 0;
$this->getFilter()->alterQuery($query, $data); $context = new ExportGenerationContext($this->getUser());
$this->getFilter()->alterQuery($query, $data, $context);
$this->assertGreaterThanOrEqual( $this->assertGreaterThanOrEqual(
$nbOfFrom, $nbOfFrom,
@ -192,7 +199,7 @@ abstract class AbstractFilterTest extends KernelTestCase
*/ */
public function testQueryExecution(QueryBuilder $qb, mixed $data): void public function testQueryExecution(QueryBuilder $qb, mixed $data): void
{ {
$this->getFilter()->alterQuery($qb, $data); $this->getFilter()->alterQuery($qb, $data, new ExportGenerationContext($this->getUser()));
$actual = $qb->getQuery()->getResult(); $actual = $qb->getQuery()->getResult();
@ -262,15 +269,4 @@ abstract class AbstractFilterTest extends KernelTestCase
); );
} }
} }
public function testGetTitle()
{
$title = $this->getFilter()->getTitle();
$this->assertIsString($title);
$this->assertNotEmpty(
$title,
'test that the title is not empty'
);
}
} }

View File

@ -63,8 +63,6 @@ final class FilterListAccompanyingPeriodHelperTest extends KernelTestCase
if (null === $user) { if (null === $user) {
throw new \RuntimeException('no user found'); throw new \RuntimeException('no user found');
} }
$security = $this->prophesize(Security::class);
$security->getUser()->willReturn($user);
// mock authorization helper // mock authorization helper
$scopes = $this->scopeRepository->findAll(); $scopes = $this->scopeRepository->findAll();
@ -76,7 +74,6 @@ final class FilterListAccompanyingPeriodHelperTest extends KernelTestCase
->willReturn($scopesConfidentials); ->willReturn($scopesConfidentials);
$filter = new FilterListAccompanyingPeriodHelper( $filter = new FilterListAccompanyingPeriodHelper(
$security->reveal(),
$this->centerRepository, $this->centerRepository,
$authorizationHelper->reveal(), $authorizationHelper->reveal(),
$parameterBag $parameterBag

View File

@ -308,7 +308,7 @@ class ReportList implements ExportElementValidatedInterface, ListInterface
return 'report'; return 'report';
} }
public function initiateQuery(array $requiredModifiers, array $acl, array $data, \Chill\MainBundle\Export\ExportGenerationContext $context): \Doctrine\ORM\QueryBuilder public function initiateQuery(array $requiredModifiers, array $acl, array $data, \Chill\MainBundle\Export\ExportGenerationContext $context): QueryBuilder
{ {
$centers = array_map(static fn ($el) => $el['center'], $acl); $centers = array_map(static fn ($el) => $el['center'], $acl);