This commit is contained in:
2025-04-08 14:09:16 +02:00
parent 3a904e8ea1
commit a2713041da
11 changed files with 27 additions and 51 deletions

View File

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

View File

@@ -96,7 +96,7 @@ interface ExportInterface extends ExportElementInterface
* which do not need to be translated, or value already translated in
* database. But the header must be, in every case, translated.
*
* @param string $key The column key, as added in the query
* @param string $key The column key, as added in the query
* @param list<mixed> $values The values from the result. if there are duplicates, those might be given twice. Example: array('FR', 'BE', 'CZ', 'FR', 'BE', 'FR')
*
* @return (callable(string|int|float|'_header'|null $value): string|int|\DateTimeInterface|TranslatableInterface) where the first argument is the value, and the function should return the label to show in the formatted file. Example : `function($countryCode) use ($countries) { return $countries[$countryCode]->getName(); }`
@@ -117,7 +117,7 @@ interface ExportInterface extends ExportElementInterface
/**
* Return the results of the query builder.
*
* @param Q $query
* @param Q $query
* @param D $data the data from the export's fomr (added by self::buildForm)
*
* @return mixed[] an array of results
@@ -151,13 +151,12 @@ interface ExportInterface extends ExportElementInterface
/**
* @param D $formData
* @return array
*/
public function normalizeFormData(array $formData): array;
/**
* @param array $formData the normalized data
* @param int $fromVersion
*
* @return D
*/
public function denormalizeFormData(array $formData, int $fromVersion): array;

View File

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

View File

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

View File

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

View File

@@ -11,6 +11,8 @@ declare(strict_types=1);
namespace Chill\MainBundle\Test\Export;
use Chill\MainBundle\Entity\User;
use Chill\MainBundle\Export\ExportGenerationContext;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\QueryBuilder;
use Prophecy\PhpUnit\ProphecyTrait;
@@ -23,16 +25,6 @@ abstract class AbstractFilterTest extends KernelTestCase
{
use ProphecyTrait;
/**
* @var \Prophecy\Prophet
*/
private $prophet;
protected function setUp(): void
{
$this->prophet = $this->getProphet();
}
public static function tearDownAfterClass(): void
{
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.
*
@@ -138,7 +143,7 @@ abstract class AbstractFilterTest extends KernelTestCase
{
$aliases = $qb->getAllAliases();
$this->getFilter()->alterQuery($qb, $data);
$this->getFilter()->alterQuery($qb, $data, new ExportGenerationContext($this->getUser()));
$alteredQuery = $qb->getAllAliases();
@@ -166,7 +171,9 @@ abstract class AbstractFilterTest extends KernelTestCase
$nbOfSelect = null !== $query->getDQLPart('select') ?
\count($query->getDQLPart('select')) : 0;
$this->getFilter()->alterQuery($query, $data);
$context = new ExportGenerationContext($this->getUser());
$this->getFilter()->alterQuery($query, $data, $context);
$this->assertGreaterThanOrEqual(
$nbOfFrom,
@@ -192,7 +199,7 @@ abstract class AbstractFilterTest extends KernelTestCase
*/
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();
@@ -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'
);
}
}