mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
ci: Update PHPUnit behavior.
This commit is contained in:
parent
64ec3e62da
commit
f93b1935ee
@ -16,13 +16,23 @@ use Chill\MainBundle\Export\ExportInterface;
|
||||
use Chill\MainBundle\Export\ExportManager;
|
||||
use Chill\MainBundle\Export\FilterInterface;
|
||||
use Chill\MainBundle\Form\Type\Export\ExportType;
|
||||
use Chill\MainBundle\Security\Authorization\AuthorizationHelper;
|
||||
use Chill\MainBundle\Test\PrepareCenterTrait;
|
||||
use Chill\MainBundle\Test\PrepareScopeTrait;
|
||||
use Chill\MainBundle\Test\PrepareUserTrait;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Doctrine\ORM\QueryBuilder;
|
||||
use Prophecy\Argument;
|
||||
use Prophecy\Prophet;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use RuntimeException;
|
||||
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorage;
|
||||
use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken;
|
||||
use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;
|
||||
use Symfony\Component\Security\Core\Role\Role;
|
||||
use Symfony\Component\Security\Core\User\UserInterface;
|
||||
use function count;
|
||||
|
||||
/**
|
||||
@ -33,14 +43,11 @@ use function count;
|
||||
*/
|
||||
final class ExportManagerTest extends KernelTestCase
|
||||
{
|
||||
use \Chill\MainBundle\Test\PrepareCenterTrait;
|
||||
use \Chill\MainBundle\Test\PrepareScopeTrait;
|
||||
use \Chill\MainBundle\Test\PrepareUserTrait;
|
||||
use PrepareCenterTrait;
|
||||
use PrepareScopeTrait;
|
||||
use PrepareUserTrait;
|
||||
|
||||
/**
|
||||
* @var Prophecy\Prophet
|
||||
*/
|
||||
private $prophet;
|
||||
private Prophet $prophet;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
@ -379,11 +386,10 @@ final class ExportManagerTest extends KernelTestCase
|
||||
$this->assertInstanceof('Chill\MainBundle\Export\AggregatorInterface', $obtained);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \RuntimeException
|
||||
*/
|
||||
public function testGetAggregatorNonExistant()
|
||||
{
|
||||
$this->expectException(\RuntimeException::class);
|
||||
|
||||
$exportManager = $this->createExportManager();
|
||||
|
||||
$exportManager->getAggregator('non existing');
|
||||
@ -438,11 +444,10 @@ final class ExportManagerTest extends KernelTestCase
|
||||
$this->assertInstanceof(ExportInterface::class, $obtained);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \RuntimeException
|
||||
*/
|
||||
public function testGetExportNonExistant()
|
||||
{
|
||||
$this->expectException(\RuntimeException::class);
|
||||
|
||||
$exportManager = $this->createExportManager();
|
||||
|
||||
$exportManager->getExport('non existing');
|
||||
@ -478,11 +483,10 @@ final class ExportManagerTest extends KernelTestCase
|
||||
$this->assertInstanceof('Chill\MainBundle\Export\FilterInterface', $obtained);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \RuntimeException
|
||||
*/
|
||||
public function testGetFilterNonExistant()
|
||||
{
|
||||
$this->expectException(\RuntimeException::class);
|
||||
|
||||
$exportManager = $this->createExportManager();
|
||||
|
||||
$exportManager->getFilter('non existing');
|
||||
@ -640,11 +644,10 @@ final class ExportManagerTest extends KernelTestCase
|
||||
$this->assertFalse($result);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \RuntimeException
|
||||
*/
|
||||
public function testNonExistingFormatter()
|
||||
{
|
||||
$this->expectException(\RuntimeException::class);
|
||||
|
||||
$exportManager = $this->createExportManager();
|
||||
|
||||
$exportManager->getFormatter('non existing');
|
||||
@ -656,35 +659,28 @@ final class ExportManagerTest extends KernelTestCase
|
||||
* If null is provided for an element, this is replaced by the equivalent
|
||||
* from the container; if the user provided is null, this is replaced by the
|
||||
* user 'center a_social' from database.
|
||||
*
|
||||
* @param \Psr\Log\LoggerInterface $logger
|
||||
* @param \Doctrine\ORM\EntityManagerInterface $em
|
||||
* @param \Symfony\Component\Security\Core\Authorization\AuthorizationChecker $authorizationChecker
|
||||
* @param \Chill\MainBundle\Security\Authorization\AuthorizationHelper $authorizationHelper
|
||||
* @param \Symfony\Component\Security\Core\User\UserInterface $user
|
||||
*
|
||||
* @return ExportManager
|
||||
*/
|
||||
protected function createExportManager(
|
||||
?\Psr\Log\LoggerInterface $logger = null,
|
||||
?\Doctrine\ORM\EntityManagerInterface $em = null,
|
||||
?LoggerInterface $logger = null,
|
||||
?EntityManagerInterface $em = null,
|
||||
?AuthorizationCheckerInterface $authorizationChecker = null,
|
||||
?\Chill\MainBundle\Security\Authorization\AuthorizationHelper $authorizationHelper = null,
|
||||
?\Symfony\Component\Security\Core\User\UserInterface $user = null
|
||||
) {
|
||||
$localUser = null === $user ? self::$container->get('doctrine.orm.entity_manager')
|
||||
->getRepository('ChillMainBundle:User')
|
||||
->findOneBy(['username' => 'center a_social']) :
|
||||
$user;
|
||||
$token = new \Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken($localUser, 'password', 'provider');
|
||||
$tokenStorage = new \Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorage();
|
||||
?AuthorizationHelper $authorizationHelper = null,
|
||||
?UserInterface $user = null
|
||||
): ExportManager {
|
||||
$localUser = $user ?? self::$container->get(
|
||||
'doctrine.orm.entity_manager'
|
||||
)
|
||||
->getRepository('ChillMainBundle:User')
|
||||
->findOneBy(['username' => 'center a_social']);
|
||||
$token = new UsernamePasswordToken($localUser, 'password', 'provider');
|
||||
$tokenStorage = new TokenStorage();
|
||||
$tokenStorage->setToken($token);
|
||||
|
||||
return new ExportManager(
|
||||
null === $logger ? self::$container->get('logger') : $logger,
|
||||
null === $em ? self::$container->get('doctrine.orm.entity_manager') : $em,
|
||||
null === $authorizationChecker ? self::$container->get('security.authorization_checker') : $authorizationChecker,
|
||||
null === $authorizationHelper ? self::$container->get('chill.main.security.authorization.helper') : $authorizationHelper,
|
||||
$logger ?? self::$container->get('logger'),
|
||||
$em ?? self::$container->get('doctrine.orm.entity_manager'),
|
||||
$authorizationChecker ?? self::$container->get('security.authorization_checker'),
|
||||
$authorizationHelper ?? self::$container->get('chill.main.security.authorization.helper'),
|
||||
$tokenStorage
|
||||
);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user