mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-21 07:03:49 +00:00
Feature: add api endpoint for listing all geographical units covering an address
This commit is contained in:
@@ -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()];
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user