Feature: add api endpoint for listing all geographical units covering an address

This commit is contained in:
2023-03-15 14:52:25 +01:00
parent b740a88ae3
commit 71d0785ab4
5 changed files with 169 additions and 4 deletions

View File

@@ -0,0 +1,40 @@
<?php
namespace Chill\MainBundle\Tests\Controller;
use Chill\MainBundle\Entity\Address;
use Chill\MainBundle\Test\PrepareClientTrait;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
class GeographicalUnitByAddressApiControllerTest extends WebTestCase
{
use PrepareClientTrait;
/**
* @dataProvider generateRandomAddress
*/
public function testGetGeographicalUnitCoveringAddress(int $addressId): void
{
$client = $this->getClientAuthenticated();
$client->request('GET', '/api/1.0/main/geographical-unit/by-address/'.$addressId.'.json');
$this->assertResponseIsSuccessful();
}
public static function generateRandomAddress(): iterable
{
self::bootKernel();
$em = self::$container->get(EntityManagerInterface::class);
$nb = $em->createQuery('SELECT COUNT(a) FROM '.Address::class.' a')->getSingleScalarResult();
/** @var \Chill\MainBundle\Entity\Address $random */
$random = $em->createQuery('SELECT a FROM '.Address::class.' a')
->setFirstResult(rand(0, $nb))
->setMaxResults(1)
->getSingleResult();
yield [$random->getId()];
}
}