enable test for calendar

This commit is contained in:
Julien Fastré 2021-09-13 13:13:17 +02:00
parent 75aa600a20
commit ed31dc3157
2 changed files with 37 additions and 27 deletions

View File

@ -10,7 +10,7 @@
<php>
<ini name="error_reporting" value="-1" />
<server name="APP_ENV" value="test" force="true" />
<env name="SYMFONY_DEPRECATIONS_HELPER" value="weak" />
<env name="SYMFONY_DEPRECATIONS_HELPER" value="weak" />
<server name="SHELL_VERBOSITY" value="-1" />
</php>
@ -31,6 +31,9 @@
<!-- temporarily removed, the time to find a fix -->
<exclude>src/Bundle/ChillPersonBundle/Tests/Controller/PersonDuplicateControllerViewTest.php</exclude>
</testsuite>
<testsuite name="CalendarBundle">
<directory suffix="Test.php">src/Bundle/ChillCalendarBundle/Tests/</directory>
</testsuite>
</testsuites>
<listeners>

View File

@ -2,65 +2,72 @@
namespace Chill\CalendarBundle\Tests\Controller;
use Chill\PersonBundle\Repository\AccompanyingPeriodRepository;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
use Symfony\Component\HttpFoundation\Request;
use Chill\PersonBundle\Entity\AccompanyingPeriod;
class CalendarControllerTest extends WebTestCase
{
/**
* Setup before the first test of this class (see phpunit doc)
*/
public static function setUpBeforeClass()
{
static::bootKernel();
}
/**
* Setup before each test method (see phpunit doc)
*/
public function setUp()
{
static::bootKernel();
$this->client = static::createClient(array(), array(
'PHP_AUTH_USER' => 'center a_social',
'PHP_AUTH_PW' => 'password',
));
}
private function getAccompanyingPeriodFromFixtures(): AccompanyingPeriod
public function provideAccompanyingPeriod(): iterable
{
$em = static::$kernel->getContainer()
->get('doctrine.orm.entity_manager');
static::bootKernel();
$em= static::$container->get(EntityManagerInterface::class);
$accompanying_period = $em->getRepository('ChillPersonBundle:AccompanyingPeriod')->find(1);
$nb = $em->createQueryBuilder()
->from(AccompanyingPeriod::class, 'ac')
->select('COUNT(ac) AS nb')
->getQuery()
->getSingleScalarResult()
;
if ($accompanying_period === NULL) {
throw new \RuntimeException("We need an accompanying course with id = 1. Did you add fixtures ?");
}
return $accompanying_period;
yield [ $em->createQueryBuilder()
->from(AccompanyingPeriod::class, 'ac')
->select('ac.id')
->setFirstResult(\random_int(0, $nb))
->setMaxResults(1)
->getQuery()
->getSingleScalarResult()
];
}
public function testList()
/**
* @dataProvider provideAccompanyingPeriod
*/
public function testList(int $accompanyingPeriodId)
{
$this->client->request(
Request::METHOD_GET,
sprintf('/fr/calendar/?accompanying_period_id=%d', $this->getAccompanyingPeriodFromFixtures()->getId())
Request::METHOD_GET,
sprintf('/fr/calendar/calendar/?accompanying_period_id=%d', $accompanyingPeriodId)
);
$this->assertEquals(200, $this->client->getResponse()->getStatusCode());
}
public function testNew()
/**
* @dataProvider provideAccompanyingPeriod
*/
public function testNew(int $accompanyingPeriodId)
{
$this->client->request(
Request::METHOD_GET,
sprintf('/fr/calendar/new?accompanying_period_id=%d', $this->getAccompanyingPeriodFromFixtures()->getId())
Request::METHOD_GET,
sprintf('/fr/calendar/calendar/new?accompanying_period_id=%d', $accompanyingPeriodId)
);
$this->assertEquals(200, $this->client->getResponse()->getStatusCode());
}
}