mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-22 15:43:51 +00:00
bootstrap generic doc manager and associated services
This commit is contained in:
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Chill\DocStoreBundle\Tests\GenericDoc;
|
||||
|
||||
use Chill\DocStoreBundle\GenericDoc\FetchQueryToSqlBuilder;
|
||||
use Chill\DocStoreBundle\GenericDoc\FetchQuery;
|
||||
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
* @coversNothing
|
||||
*/
|
||||
class FetchQueryToSqlBuilderTest extends KernelTestCase
|
||||
{
|
||||
public function testToSql(): void
|
||||
{
|
||||
$query = new FetchQuery(
|
||||
'test',
|
||||
'jsonb_build_object(\'id\', a.column)',
|
||||
'a.datecolumn',
|
||||
'my_table a'
|
||||
);
|
||||
$query->addJoinClause('LEFT JOIN other b ON a.id = b.foreign_id', ['foo']);
|
||||
$index = $query->addJoinClause('LEFT JOIN other c ON a.id = c.foreign_id', ['bar']);
|
||||
$query->addJoinClause('LEFT JOIN other d ON a.id = d.foreign_id', ['bar_baz']);
|
||||
$query->removeJoinClause($index);
|
||||
$query->addWhereClause('b.item = ?', ['baz']);
|
||||
$index = $query->addWhereClause('b.cancel', [ 'foz']);
|
||||
$query->removeWhereClause($index);
|
||||
|
||||
['sql' => $sql, 'params' => $params] = (new FetchQueryToSqlBuilder())->toSql($query);
|
||||
|
||||
$filteredSql =
|
||||
implode(" ", array_filter(
|
||||
explode(" ", str_replace("\n", "", $sql)),
|
||||
fn (string $tok) => $tok !== ""
|
||||
))
|
||||
;
|
||||
|
||||
self::assertEquals(
|
||||
"SELECT 'test' AS key, jsonb_build_object('id', a.column) AS identifiers, ".
|
||||
"a.datecolumn AS doc_date FROM my_table a LEFT JOIN other b ON a.id = b.foreign_id LEFT JOIN other d ON a.id = d.foreign_id WHERE b.item = ?",
|
||||
$filteredSql
|
||||
);
|
||||
self::assertEquals(['foo', 'bar_baz', 'baz'], $params);
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Chill\DocStoreBundle\Tests\GenericDoc;
|
||||
|
||||
use Chill\DocStoreBundle\GenericDoc\Manager;
|
||||
use Chill\PersonBundle\Entity\AccompanyingPeriod;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
* @coversNothing
|
||||
*/
|
||||
class ManagerTest extends KernelTestCase
|
||||
{
|
||||
private Manager $manager;
|
||||
|
||||
private EntityManagerInterface $em;
|
||||
|
||||
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");
|
||||
}
|
||||
}
|
||||
|
||||
public function testCountByAccompanyingPeriod(): void
|
||||
{
|
||||
$period = $this->em->createQuery('SELECT a FROM '.AccompanyingPeriod::class.' a')
|
||||
->setMaxResults(1)
|
||||
->getSingleResult();
|
||||
|
||||
if (null === $period) {
|
||||
throw new \UnexpectedValueException("period not found");
|
||||
}
|
||||
|
||||
$nb = $this->manager->countDocForAccompanyingPeriod($period);
|
||||
|
||||
self::assertIsInt($nb);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user