mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-10-19 19:52:49 +00:00
GenericDoc: add provider for AccompanyingCourseDocument, without filtering
This commit is contained in:
@@ -11,9 +11,15 @@ declare(strict_types=1);
|
||||
|
||||
namespace Chill\DocStoreBundle\Tests\GenericDoc;
|
||||
|
||||
use Chill\DocStoreBundle\GenericDoc\FetchQuery;
|
||||
use Chill\DocStoreBundle\GenericDoc\FetchQueryInterface;
|
||||
use Chill\DocStoreBundle\GenericDoc\GenericDocDTO;
|
||||
use Chill\DocStoreBundle\GenericDoc\Manager;
|
||||
use Chill\DocStoreBundle\GenericDoc\ProviderForAccompanyingPeriodInterface;
|
||||
use Chill\PersonBundle\Entity\AccompanyingPeriod;
|
||||
use Doctrine\DBAL\Connection;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Prophecy\PhpUnit\ProphecyTrait;
|
||||
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
|
||||
|
||||
/**
|
||||
@@ -22,21 +28,17 @@ use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
|
||||
*/
|
||||
class ManagerTest extends KernelTestCase
|
||||
{
|
||||
private Manager $manager;
|
||||
|
||||
use ProphecyTrait;
|
||||
private EntityManagerInterface $em;
|
||||
|
||||
private Connection $connection;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
self::bootKernel();
|
||||
|
||||
$this->em = self::$container->get(EntityManagerInterface::class);
|
||||
|
||||
if (null !== $manager = self::$container->get(Manager::class)) {
|
||||
$this->manager = $manager;
|
||||
} else {
|
||||
throw new \UnexpectedValueException("the manager was not found in the kernel");
|
||||
}
|
||||
$this->connection = self::$container->get(Connection::class);
|
||||
}
|
||||
|
||||
public function testCountByAccompanyingPeriod(): void
|
||||
@@ -49,8 +51,51 @@ class ManagerTest extends KernelTestCase
|
||||
throw new \UnexpectedValueException("period not found");
|
||||
}
|
||||
|
||||
$nb = $this->manager->countDocForAccompanyingPeriod($period);
|
||||
$manager = new Manager(
|
||||
[new SimpleProvider()],
|
||||
$this->connection,
|
||||
);
|
||||
|
||||
$nb = $manager->countDocForAccompanyingPeriod($period);
|
||||
|
||||
self::assertIsInt($nb);
|
||||
}
|
||||
|
||||
public function testFindDocByAccompanyingPeriod(): void
|
||||
{
|
||||
$period = $this->em->createQuery('SELECT a FROM '.AccompanyingPeriod::class.' a')
|
||||
->setMaxResults(1)
|
||||
->getSingleResult();
|
||||
|
||||
if (null === $period) {
|
||||
throw new \UnexpectedValueException("period not found");
|
||||
}
|
||||
|
||||
$manager = new Manager(
|
||||
[new SimpleProvider()],
|
||||
$this->connection,
|
||||
);
|
||||
|
||||
foreach ($manager->findDocForAccompanyingPeriod($period) as $doc) {
|
||||
self::assertInstanceOf(GenericDocDTO::class, $doc);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
final readonly class SimpleProvider implements ProviderForAccompanyingPeriodInterface
|
||||
{
|
||||
public function buildFetchQueryForAccompanyingPeriod(AccompanyingPeriod $accompanyingPeriod, ?\DateTimeImmutable $startDate = null, ?\DateTimeImmutable $endDate = null, ?string $content = null, ?string $origin = null): FetchQueryInterface
|
||||
{
|
||||
return new FetchQuery(
|
||||
'accompanying_course_document',
|
||||
sprintf('jsonb_build_object(\'id\', %s)', 'id'),
|
||||
'd',
|
||||
'(VALUES (1, \'2023-05-01\'::date), (2, \'2023-05-01\'::date)) AS sq (id, d)',
|
||||
);
|
||||
}
|
||||
|
||||
public function isAllowedForAccompanyingPeriod(AccompanyingPeriod $accompanyingPeriod): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user