GenericDoc: add provider for AccompanyingCourseDocument, without filtering

This commit is contained in:
2023-05-24 11:42:30 +02:00
parent afcd6e0605
commit 8dbe2d6ec2
12 changed files with 414 additions and 46 deletions

View File

@@ -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;
}
}