mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
Fix tests
This commit is contained in:
parent
1c04219859
commit
f12d689382
@ -12,6 +12,8 @@ declare(strict_types=1);
|
|||||||
namespace Chill\AsideActivityBundle\Tests\Export\Export;
|
namespace Chill\AsideActivityBundle\Tests\Export\Export;
|
||||||
|
|
||||||
use Chill\AsideActivityBundle\Export\Export\ListAsideActivity;
|
use Chill\AsideActivityBundle\Export\Export\ListAsideActivity;
|
||||||
|
use Chill\MainBundle\Entity\User;
|
||||||
|
use Chill\MainBundle\Export\ExportGenerationContext;
|
||||||
use Doctrine\ORM\AbstractQuery;
|
use Doctrine\ORM\AbstractQuery;
|
||||||
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
|
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
|
||||||
|
|
||||||
@ -33,7 +35,7 @@ class ListAsideActivityTest extends KernelTestCase
|
|||||||
|
|
||||||
public function testExecuteQuery(): void
|
public function testExecuteQuery(): void
|
||||||
{
|
{
|
||||||
$qb = $this->listAsideActivity->initiateQuery([], [], [])
|
$qb = $this->listAsideActivity->initiateQuery([], [], [], new ExportGenerationContext(new User()))
|
||||||
->setMaxResults(1);
|
->setMaxResults(1);
|
||||||
|
|
||||||
$results = $qb->getQuery()->getResult(AbstractQuery::HYDRATE_ARRAY);
|
$results = $qb->getQuery()->getResult(AbstractQuery::HYDRATE_ARRAY);
|
||||||
|
@ -14,9 +14,11 @@ namespace Chill\MainBundle\Tests\Controller;
|
|||||||
use Chill\DocStoreBundle\Entity\StoredObject;
|
use Chill\DocStoreBundle\Entity\StoredObject;
|
||||||
use Chill\MainBundle\Controller\ExportGenerationController;
|
use Chill\MainBundle\Controller\ExportGenerationController;
|
||||||
use Chill\MainBundle\Entity\ExportGeneration;
|
use Chill\MainBundle\Entity\ExportGeneration;
|
||||||
|
use Chill\MainBundle\Export\ExportManager;
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
use Prophecy\Argument;
|
use Prophecy\Argument;
|
||||||
use Prophecy\PhpUnit\ProphecyTrait;
|
use Prophecy\PhpUnit\ProphecyTrait;
|
||||||
|
use Psr\Log\NullLogger;
|
||||||
use Symfony\Component\Security\Core\Security;
|
use Symfony\Component\Security\Core\Security;
|
||||||
use Symfony\Component\Serializer\SerializerInterface;
|
use Symfony\Component\Serializer\SerializerInterface;
|
||||||
use Twig\Environment;
|
use Twig\Environment;
|
||||||
@ -38,13 +40,14 @@ class ExportGenerationControllerTest extends TestCase
|
|||||||
$environment = $this->prophesize(Environment::class);
|
$environment = $this->prophesize(Environment::class);
|
||||||
$serializer = $this->prophesize(SerializerInterface::class);
|
$serializer = $this->prophesize(SerializerInterface::class);
|
||||||
$serializer->serialize(Argument::any(), 'json', ['groups' => ['read']])->willReturn('{}');
|
$serializer->serialize(Argument::any(), 'json', ['groups' => ['read']])->willReturn('{}');
|
||||||
|
$exportManager = $this->prophesize(ExportManager::class);
|
||||||
|
|
||||||
$pending = new ExportGeneration('dummy', []);
|
$pending = new ExportGeneration('dummy', []);
|
||||||
|
|
||||||
$controller = new ExportGenerationController($security->reveal(), $environment->reveal(), $serializer->reveal());
|
$controller = new ExportGenerationController($security->reveal(), $environment->reveal(), $serializer->reveal(), $exportManager->reveal());
|
||||||
|
|
||||||
$actual = $controller->objectStatus($pending);
|
$actual = $controller->objectStatus($pending);
|
||||||
self::assertEquals(json_encode(['status' => 'pending'], JSON_THROW_ON_ERROR), $actual->getContent());
|
self::assertEquals('{}', $actual->getContent());
|
||||||
|
|
||||||
$generated = new ExportGeneration('dummy', []);
|
$generated = new ExportGeneration('dummy', []);
|
||||||
$generated->getStoredObject()->setStatus(StoredObject::STATUS_READY);
|
$generated->getStoredObject()->setStatus(StoredObject::STATUS_READY);
|
||||||
|
@ -93,6 +93,7 @@ class ExportGeneratorTest extends TestCase
|
|||||||
return true;
|
return true;
|
||||||
}),
|
}),
|
||||||
['key' => 'form1'],
|
['key' => 'form1'],
|
||||||
|
Argument::that(static fn ($context) => $context instanceof ExportGenerationContext && $context->byUser === $user),
|
||||||
)->shouldBeCalled()->willReturn($query->reveal());
|
)->shouldBeCalled()->willReturn($query->reveal());
|
||||||
$export->getResult($query->reveal(), $formExportData, Argument::that(static fn (ExportGenerationContext $context) => $context->byUser === $user))
|
$export->getResult($query->reveal(), $formExportData, Argument::that(static fn (ExportGenerationContext $context) => $context->byUser === $user))
|
||||||
->shouldBeCalled()->willReturn([['result0' => '0']]);
|
->shouldBeCalled()->willReturn([['result0' => '0']]);
|
||||||
@ -162,6 +163,7 @@ class ExportGeneratorTest extends TestCase
|
|||||||
[],
|
[],
|
||||||
[['center' => $centerA, 'circles' => []], ['center' => $centerB, 'circles' => []]],
|
[['center' => $centerA, 'circles' => []], ['center' => $centerB, 'circles' => []]],
|
||||||
['key' => 'form1'],
|
['key' => 'form1'],
|
||||||
|
Argument::that(static fn ($context) => $context instanceof ExportGenerationContext && $context->byUser === $user),
|
||||||
)->shouldBeCalled()->willReturn($query->reveal());
|
)->shouldBeCalled()->willReturn($query->reveal());
|
||||||
$export->getResult($query->reveal(), $formExportData, Argument::that(static fn (ExportGenerationContext $context) => $context->byUser === $user))
|
$export->getResult($query->reveal(), $formExportData, Argument::that(static fn (ExportGenerationContext $context) => $context->byUser === $user))
|
||||||
->shouldBeCalled()->willReturn([['result0' => '0']]);
|
->shouldBeCalled()->willReturn([['result0' => '0']]);
|
||||||
@ -207,7 +209,7 @@ class ExportGeneratorTest extends TestCase
|
|||||||
'aggregators' => [],
|
'aggregators' => [],
|
||||||
'pick_formatter' => 'xlsx',
|
'pick_formatter' => 'xlsx',
|
||||||
'formatter' => ['form' => $formatterData = ['key' => 'form4']],
|
'formatter' => ['form' => $formatterData = ['key' => 'form4']],
|
||||||
'centers' => [$centerA = new Center(), $centerB = new Center()],
|
'centers' => ['centers' => [$centerA = new Center(), $centerB = new Center()], 'regroupments' => []],
|
||||||
];
|
];
|
||||||
$user = new User();
|
$user = new User();
|
||||||
|
|
||||||
@ -220,6 +222,7 @@ class ExportGeneratorTest extends TestCase
|
|||||||
Argument::that(static fn (ExportGenerationContext $context) => $user === $context->byUser),
|
Argument::that(static fn (ExportGenerationContext $context) => $user === $context->byUser),
|
||||||
)->shouldBeCalled()
|
)->shouldBeCalled()
|
||||||
->willReturn(new FormattedExportGeneration('export result', 'text/text'));
|
->willReturn(new FormattedExportGeneration('export result', 'text/text'));
|
||||||
|
$export->requiredRole()->willReturn('dummy_role');
|
||||||
|
|
||||||
$exportConfigNormalizer = $this->prophesize(ExportConfigNormalizer::class);
|
$exportConfigNormalizer = $this->prophesize(ExportConfigNormalizer::class);
|
||||||
$exportConfigNormalizer->denormalizeConfig('dummy', $initialData)->willReturn($fullConfig);
|
$exportConfigNormalizer->denormalizeConfig('dummy', $initialData)->willReturn($fullConfig);
|
||||||
@ -227,7 +230,10 @@ class ExportGeneratorTest extends TestCase
|
|||||||
$exportManager = $this->prophesize(ExportManager::class);
|
$exportManager = $this->prophesize(ExportManager::class);
|
||||||
$exportManager->getExport('dummy')->willReturn($export->reveal());
|
$exportManager->getExport('dummy')->willReturn($export->reveal());
|
||||||
|
|
||||||
$generator = new ExportGenerator($exportManager->reveal(), $exportConfigNormalizer->reveal(), new NullLogger());
|
$authorizationHelper = $this->prophesize(AuthorizationHelperInterface::class);
|
||||||
|
$authorizationHelper->getReachableCenters($user, 'dummy_role')->willReturn([$centerA, $centerB]);
|
||||||
|
|
||||||
|
$generator = new ExportGenerator($exportManager->reveal(), $exportConfigNormalizer->reveal(), new NullLogger(), $authorizationHelper->reveal(), new CenterRegroupementResolver());
|
||||||
|
|
||||||
$actual = $generator->generate('dummy', $initialData, $user);
|
$actual = $generator->generate('dummy', $initialData, $user);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user