2021-12-21 15:19:36 +01:00

85 lines
2.2 KiB
PHP

<?php
/**
* 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.
*/
declare(strict_types=1);
namespace Chill\CalendarBundle\Tests\Controller;
use Chill\PersonBundle\Entity\AccompanyingPeriod;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
use Symfony\Component\HttpFoundation\Request;
use function random_int;
/**
* @internal
* @coversNothing
*/
final class CalendarControllerTest extends WebTestCase
{
/**
* Setup before each test method (see phpunit doc).
*/
protected function setUp(): void
{
self::bootKernel();
$this->client = self::createClient([], [
'PHP_AUTH_USER' => 'center a_social',
'PHP_AUTH_PW' => 'password',
]);
}
public function provideAccompanyingPeriod(): iterable
{
self::bootKernel();
$em = self::$container->get(EntityManagerInterface::class);
$nb = $em->createQueryBuilder()
->from(AccompanyingPeriod::class, 'ac')
->select('COUNT(ac) AS nb')
->getQuery()
->getSingleScalarResult();
yield [$em->createQueryBuilder()
->from(AccompanyingPeriod::class, 'ac')
->select('ac.id')
->setFirstResult(random_int(0, $nb))
->setMaxResults(1)
->getQuery()
->getSingleScalarResult(),
];
}
/**
* @dataProvider provideAccompanyingPeriod
*/
public function testList(int $accompanyingPeriodId)
{
$this->client->request(
Request::METHOD_GET,
sprintf('/fr/calendar/calendar/?accompanying_period_id=%d', $accompanyingPeriodId)
);
$this->assertEquals(200, $this->client->getResponse()->getStatusCode());
}
/**
* @dataProvider provideAccompanyingPeriod
*/
public function testNew(int $accompanyingPeriodId)
{
$this->client->request(
Request::METHOD_GET,
sprintf('/fr/calendar/calendar/new?accompanying_period_id=%d', $accompanyingPeriodId)
);
$this->assertEquals(200, $this->client->getResponse()->getStatusCode());
}
}