mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-10-08 06:19:42 +00:00
Add materialized view and repository methods for address search
Introduced a materialized view `view_chill_main_address_reference` to optimize address search queries and added corresponding repository methods `findBySearchString` and `countBySearchString`. Also included test coverage for the repository to validate the new functionality.
This commit is contained in:
@@ -0,0 +1,74 @@
|
||||
<?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\MainBundle\Tests\Repository;
|
||||
|
||||
use Chill\MainBundle\Entity\AddressReference;
|
||||
use Chill\MainBundle\Entity\PostalCode;
|
||||
use Chill\MainBundle\Repository\AddressReferenceRepository;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*
|
||||
* @coversNothing
|
||||
*/
|
||||
class AddressReferenceRepositoryTest extends KernelTestCase
|
||||
{
|
||||
private static AddressReferenceRepository $repository;
|
||||
|
||||
public static function setUpBeforeClass(): void
|
||||
{
|
||||
static::bootKernel();
|
||||
static::$repository = static::getContainer()->get(AddressReferenceRepository::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider generateSearchString
|
||||
*/
|
||||
public function testFindBySearchString(string $search, int|PostalCode|null $postalCode, string $text, ?array $expected = null): void
|
||||
{
|
||||
$actual = static::$repository->findBySearchString($search, $postalCode);
|
||||
|
||||
self::assertIsIterable($actual, $text);
|
||||
|
||||
if (null !== $expected) {
|
||||
self::assertEquals($expected, iterator_to_array($actual));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider generateSearchString
|
||||
*/
|
||||
public function testCountBySearchString(string $search, int|PostalCode|null $postalCode, string $text, ?array $expected = null): void
|
||||
{
|
||||
$actual = static::$repository->countBySearchString($search, $postalCode);
|
||||
|
||||
self::assertIsInt($actual, $text);
|
||||
}
|
||||
|
||||
public static function generateSearchString(): iterable
|
||||
{
|
||||
self::bootKernel();
|
||||
$em = static::getContainer()->get(EntityManagerInterface::class);
|
||||
/** @var AddressReference $ar */
|
||||
$ar = $em->createQuery('SELECT ar FROM '.AddressReference::class.' ar')
|
||||
->setMaxResults(1)
|
||||
->getSingleResult();
|
||||
|
||||
yield ['', null, 'search with empty string', []];
|
||||
yield [' ', null, 'search with spaces only', []];
|
||||
yield ['rue des moulins', null, 'search contains an empty string'];
|
||||
yield ['rue des moulins', $ar->getPostcode()->getId(), 'search with postal code as an id'];
|
||||
yield ['rue des moulins', $ar->getPostcode(), 'search with postal code instance'];
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user