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\ExportManager;
|
||||||
use Chill\MainBundle\Export\FilterInterface;
|
use Chill\MainBundle\Export\FilterInterface;
|
||||||
use Chill\MainBundle\Form\Type\Export\ExportType;
|
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 Doctrine\ORM\QueryBuilder;
|
||||||
use Prophecy\Argument;
|
use Prophecy\Argument;
|
||||||
|
use Prophecy\Prophet;
|
||||||
|
use Psr\Log\LoggerInterface;
|
||||||
use RuntimeException;
|
use RuntimeException;
|
||||||
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
|
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
|
||||||
use Symfony\Component\HttpFoundation\Response;
|
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\Authorization\AuthorizationCheckerInterface;
|
||||||
use Symfony\Component\Security\Core\Role\Role;
|
use Symfony\Component\Security\Core\Role\Role;
|
||||||
|
use Symfony\Component\Security\Core\User\UserInterface;
|
||||||
use function count;
|
use function count;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -33,14 +43,11 @@ use function count;
|
|||||||
*/
|
*/
|
||||||
final class ExportManagerTest extends KernelTestCase
|
final class ExportManagerTest extends KernelTestCase
|
||||||
{
|
{
|
||||||
use \Chill\MainBundle\Test\PrepareCenterTrait;
|
use PrepareCenterTrait;
|
||||||
use \Chill\MainBundle\Test\PrepareScopeTrait;
|
use PrepareScopeTrait;
|
||||||
use \Chill\MainBundle\Test\PrepareUserTrait;
|
use PrepareUserTrait;
|
||||||
|
|
||||||
/**
|
private Prophet $prophet;
|
||||||
* @var Prophecy\Prophet
|
|
||||||
*/
|
|
||||||
private $prophet;
|
|
||||||
|
|
||||||
protected function setUp(): void
|
protected function setUp(): void
|
||||||
{
|
{
|
||||||
@ -379,11 +386,10 @@ final class ExportManagerTest extends KernelTestCase
|
|||||||
$this->assertInstanceof('Chill\MainBundle\Export\AggregatorInterface', $obtained);
|
$this->assertInstanceof('Chill\MainBundle\Export\AggregatorInterface', $obtained);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @expectedException \RuntimeException
|
|
||||||
*/
|
|
||||||
public function testGetAggregatorNonExistant()
|
public function testGetAggregatorNonExistant()
|
||||||
{
|
{
|
||||||
|
$this->expectException(\RuntimeException::class);
|
||||||
|
|
||||||
$exportManager = $this->createExportManager();
|
$exportManager = $this->createExportManager();
|
||||||
|
|
||||||
$exportManager->getAggregator('non existing');
|
$exportManager->getAggregator('non existing');
|
||||||
@ -438,11 +444,10 @@ final class ExportManagerTest extends KernelTestCase
|
|||||||
$this->assertInstanceof(ExportInterface::class, $obtained);
|
$this->assertInstanceof(ExportInterface::class, $obtained);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @expectedException \RuntimeException
|
|
||||||
*/
|
|
||||||
public function testGetExportNonExistant()
|
public function testGetExportNonExistant()
|
||||||
{
|
{
|
||||||
|
$this->expectException(\RuntimeException::class);
|
||||||
|
|
||||||
$exportManager = $this->createExportManager();
|
$exportManager = $this->createExportManager();
|
||||||
|
|
||||||
$exportManager->getExport('non existing');
|
$exportManager->getExport('non existing');
|
||||||
@ -478,11 +483,10 @@ final class ExportManagerTest extends KernelTestCase
|
|||||||
$this->assertInstanceof('Chill\MainBundle\Export\FilterInterface', $obtained);
|
$this->assertInstanceof('Chill\MainBundle\Export\FilterInterface', $obtained);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @expectedException \RuntimeException
|
|
||||||
*/
|
|
||||||
public function testGetFilterNonExistant()
|
public function testGetFilterNonExistant()
|
||||||
{
|
{
|
||||||
|
$this->expectException(\RuntimeException::class);
|
||||||
|
|
||||||
$exportManager = $this->createExportManager();
|
$exportManager = $this->createExportManager();
|
||||||
|
|
||||||
$exportManager->getFilter('non existing');
|
$exportManager->getFilter('non existing');
|
||||||
@ -640,11 +644,10 @@ final class ExportManagerTest extends KernelTestCase
|
|||||||
$this->assertFalse($result);
|
$this->assertFalse($result);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @expectedException \RuntimeException
|
|
||||||
*/
|
|
||||||
public function testNonExistingFormatter()
|
public function testNonExistingFormatter()
|
||||||
{
|
{
|
||||||
|
$this->expectException(\RuntimeException::class);
|
||||||
|
|
||||||
$exportManager = $this->createExportManager();
|
$exportManager = $this->createExportManager();
|
||||||
|
|
||||||
$exportManager->getFormatter('non existing');
|
$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
|
* 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
|
* from the container; if the user provided is null, this is replaced by the
|
||||||
* user 'center a_social' from database.
|
* 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(
|
protected function createExportManager(
|
||||||
?\Psr\Log\LoggerInterface $logger = null,
|
?LoggerInterface $logger = null,
|
||||||
?\Doctrine\ORM\EntityManagerInterface $em = null,
|
?EntityManagerInterface $em = null,
|
||||||
?AuthorizationCheckerInterface $authorizationChecker = null,
|
?AuthorizationCheckerInterface $authorizationChecker = null,
|
||||||
?\Chill\MainBundle\Security\Authorization\AuthorizationHelper $authorizationHelper = null,
|
?AuthorizationHelper $authorizationHelper = null,
|
||||||
?\Symfony\Component\Security\Core\User\UserInterface $user = null
|
?UserInterface $user = null
|
||||||
) {
|
): ExportManager {
|
||||||
$localUser = null === $user ? self::$container->get('doctrine.orm.entity_manager')
|
$localUser = $user ?? self::$container->get(
|
||||||
->getRepository('ChillMainBundle:User')
|
'doctrine.orm.entity_manager'
|
||||||
->findOneBy(['username' => 'center a_social']) :
|
)
|
||||||
$user;
|
->getRepository('ChillMainBundle:User')
|
||||||
$token = new \Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken($localUser, 'password', 'provider');
|
->findOneBy(['username' => 'center a_social']);
|
||||||
$tokenStorage = new \Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorage();
|
$token = new UsernamePasswordToken($localUser, 'password', 'provider');
|
||||||
|
$tokenStorage = new TokenStorage();
|
||||||
$tokenStorage->setToken($token);
|
$tokenStorage->setToken($token);
|
||||||
|
|
||||||
return new ExportManager(
|
return new ExportManager(
|
||||||
null === $logger ? self::$container->get('logger') : $logger,
|
$logger ?? self::$container->get('logger'),
|
||||||
null === $em ? self::$container->get('doctrine.orm.entity_manager') : $em,
|
$em ?? self::$container->get('doctrine.orm.entity_manager'),
|
||||||
null === $authorizationChecker ? self::$container->get('security.authorization_checker') : $authorizationChecker,
|
$authorizationChecker ?? self::$container->get('security.authorization_checker'),
|
||||||
null === $authorizationHelper ? self::$container->get('chill.main.security.authorization.helper') : $authorizationHelper,
|
$authorizationHelper ?? self::$container->get('chill.main.security.authorization.helper'),
|
||||||
$tokenStorage
|
$tokenStorage
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user