Skip to content

Commit

Permalink
Add support for sonata-project/block-bundle 5
Browse files Browse the repository at this point in the history
  • Loading branch information
core23 committed Jul 20, 2023
1 parent aba2881 commit ad60592
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 25 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
],
"require": {
"php": "^8.1",
"sonata-project/block-bundle": "^3.23.0 || ^4.5.1",
"sonata-project/block-bundle": "^4.21 || ^5.0",
"sonata-project/form-extensions": "^1.19 || ^2.0",
"symfony/dependency-injection": "^5.4 || ^6.2",
"symfony/event-dispatcher": "^5.4 || ^6.2",
Expand Down
11 changes: 5 additions & 6 deletions src/Block/Service/GDPRInformationBlockService.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

namespace Nucleos\GDPRBundle\Block\Service;

use LogicException;
use Sonata\BlockBundle\Block\BlockContextInterface;
use Sonata\BlockBundle\Block\Service\AbstractBlockService;
use Sonata\BlockBundle\Block\Service\EditableBlockService;
Expand Down Expand Up @@ -56,11 +55,11 @@ public function execute(BlockContextInterface $blockContext, ?Response $response
'block' => $blockContext->getBlock(),
];

if (!\is_string($blockContext->getTemplate())) {
throw new LogicException('Cannot render block without template');
}

return $this->renderPrivateResponse($blockContext->getTemplate(), $parameters, $response);
return $this
->renderResponse($blockContext->getTemplate(), $parameters, $response)
->setTtl(0)

Check warning on line 60 in src/Block/Service/GDPRInformationBlockService.php

View workflow job for this annotation

GitHub Actions / run / Mutation Tests (8.2)

Escaped Mutant for Mutator "DecrementInteger": --- Original +++ New @@ @@ return new Response('', Response::HTTP_NO_CONTENT); } $parameters = ['context' => $blockContext, 'settings' => $blockContext->getSettings(), 'block' => $blockContext->getBlock()]; - return $this->renderResponse($blockContext->getTemplate(), $parameters, $response)->setTtl(0)->setPrivate(); + return $this->renderResponse($blockContext->getTemplate(), $parameters, $response)->setTtl(-1)->setPrivate(); } public function configureCreateForm(FormMapper $form, BlockInterface $block) : void {

Check warning on line 60 in src/Block/Service/GDPRInformationBlockService.php

View workflow job for this annotation

GitHub Actions / run / Mutation Tests (8.2)

Escaped Mutant for Mutator "IncrementInteger": --- Original +++ New @@ @@ return new Response('', Response::HTTP_NO_CONTENT); } $parameters = ['context' => $blockContext, 'settings' => $blockContext->getSettings(), 'block' => $blockContext->getBlock()]; - return $this->renderResponse($blockContext->getTemplate(), $parameters, $response)->setTtl(0)->setPrivate(); + return $this->renderResponse($blockContext->getTemplate(), $parameters, $response)->setTtl(1)->setPrivate(); } public function configureCreateForm(FormMapper $form, BlockInterface $block) : void {
->setPrivate()
;
}

public function configureCreateForm(FormMapper $form, BlockInterface $block): void
Expand Down
18 changes: 0 additions & 18 deletions tests/Block/Service/GDPRInformationBlockServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

namespace Nucleos\GDPRBundle\Tests\Block\Service;

use LogicException;
use Nucleos\GDPRBundle\Block\Service\GDPRInformationBlockService;
use PHPUnit\Framework\MockObject\MockObject;
use Sonata\BlockBundle\Block\BlockContext;
Expand Down Expand Up @@ -89,23 +88,6 @@ public function testExecute(): void
static::assertSame('TWIG_CONTENT', $response->getContent());
}

public function testExecuteWithNullTemplate(): void
{
$this->expectException(LogicException::class);
$this->expectExceptionMessage('Cannot render block without template');

$block = new Block();

$blockContext = new BlockContext($block, [
'template' => null,
]);

$response = new Response();

$blockService = new GDPRInformationBlockService($this->twig, $this->requestStack);
$blockService->execute($blockContext, $response);
}

public function testExecuteWithExistingCookie(): void
{
$this->request->cookies->set(GDPRInformationBlockService::COOKIE_NAME, 'true');
Expand Down

0 comments on commit ad60592

Please sign in to comment.