framadate/tests/FramaWebTestCase.php
Thomas Citharel 68feae33c2
Upgrade to SF4
Signed-off-by: Thomas Citharel <tcit@tcit.fr>
2018-04-11 20:04:11 +02:00

46 lines
1.2 KiB
PHP

<?php
namespace Framadate\Tests;
use Framadate\Entity\Poll;
use Symfony\Bundle\FrameworkBundle\Client;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
use Throwable;
abstract class FramaWebTestCase extends WebTestCase {
/**
* @var Client
*/
protected $client;
protected function setUp()
{
$this->client = static::createClient();
}
/**
* {@inheritdoc}
*/
protected function onNotSuccessfulTest(Throwable $exception)
{
$message = null;
if ($this->client->getCrawler() && count($this->client->getCrawler()->filter('.exception-message')) > 0) {
$message = preg_replace('#\s{2,}#', '', $this->client->getCrawler()->filter('.exception-message')->text());
}
if ($message) {
$exceptionClass = get_class($exception);
throw new $exceptionClass($exception->getMessage() . ' | ' . $message);
}
throw $exception;
}
/**
* @param string $id
* @return Poll
* @throws \Doctrine\DBAL\DBALException
*/
protected function getPollById(string $id): Poll
{
return $this->client->getContainer()->get('framadate.poll_service.public')->findById($id);
}
}