Skip to content
12 changes: 0 additions & 12 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -30570,12 +30570,6 @@ parameters:
count: 1
path: tests/bundle/Core/Fragment/DirectFragmentRendererTest.php

-
message: '#^Call to method PHPUnit\\Framework\\Assert\:\:assertInstanceOf\(\) with ''Symfony\\\\Component\\\\HttpFoundation\\\\Response'' and Symfony\\Component\\HttpFoundation\\Response will always evaluate to true\.$#'
identifier: method.alreadyNarrowedType
count: 4
path: tests/bundle/Core/Fragment/DirectFragmentRendererTest.php

-
message: '#^Method Ibexa\\Tests\\Bundle\\Core\\Fragment\\FragmentListenerFactoryTest\:\:buildFragmentListenerProvider\(\) has no return type specified\.$#'
identifier: missingType.return
Expand Down Expand Up @@ -58764,12 +58758,6 @@ parameters:
count: 1
path: tests/lib/MVC/Symfony/Templating/RenderContentStrategyTest.php

-
message: '#^Call to method PHPUnit\\Framework\\Assert\:\:assertInstanceOf\(\) with ''Symfony\\\\Component\\\\HttpKernel\\\\Controller\\\\ControllerReference'' and Symfony\\Component\\HttpKernel\\Controller\\ControllerReference will always evaluate to true\.$#'
identifier: method.alreadyNarrowedType
count: 1
path: tests/lib/MVC/Symfony/Templating/RenderContentStrategyTest.php

-
message: '#^Anonymous function has an unused use \$content\.$#'
identifier: closure.unusedUse
Expand Down
1 change: 1 addition & 0 deletions src/lib/MVC/Symfony/Templating/RenderContentStrategy.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public function render(ValueObject $valueObject, RenderOptions $options): string
$controllerReference = new ControllerReference('ibexa_content::viewAction', [
'contentId' => $content->id,
'viewType' => $options->get('viewType', self::DEFAULT_VIEW_TYPE),
'params' => $options->get('params', []),
]);

$renderer = $this->getFragmentRenderer($options->get('method', $this->defaultRenderer));
Expand Down
1 change: 1 addition & 0 deletions src/lib/MVC/Symfony/Templating/RenderLocationStrategy.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public function render(ValueObject $valueObject, RenderOptions $options): string
'contentId' => $content->id,
'locationId' => $location->id,
'viewType' => $options->get('viewType', self::DEFAULT_VIEW_TYPE),
'params' => $options->get('params', []),
]);

$renderer = $this->getFragmentRenderer($options->get('method', $this->defaultRenderer));
Expand Down
4 changes: 0 additions & 4 deletions tests/bundle/Core/Fragment/DirectFragmentRendererTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ public function testSubRequestBuilding(): void
$directFragmentRenderer = $this->getDirectFragmentRenderer($controllerResolver);
$response = $directFragmentRenderer->render($controllerReference, $request);

$this->assertInstanceOf(Response::class, $response);
$this->assertSame('rendered_response', $response->getContent());
}

Expand All @@ -82,7 +81,6 @@ public function testControllerResponse(): void
$directFragmentRenderer = $this->getDirectFragmentRenderer($controllerResolver);
$response = $directFragmentRenderer->render('', new Request(), []);

$this->assertInstanceOf(Response::class, $response);
$this->assertSame('response_body', $response->getContent());
}

Expand Down Expand Up @@ -113,7 +111,6 @@ public function testControllerViewResponse(): void
);
$response = $directFragmentRenderer->render('', new Request(), []);

$this->assertInstanceOf(Response::class, $response);
$this->assertSame('rendered_template_identifier', $response->getContent());
}

Expand All @@ -130,7 +127,6 @@ public function testControllerStringResponse(): void
$directFragmentRenderer = $this->getDirectFragmentRenderer($controllerResolver);
$response = $directFragmentRenderer->render('', new Request(), []);

$this->assertInstanceOf(Response::class, $response);
$this->assertSame('some_prerendered_response', $response->getContent());
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<?php

/**
* @copyright Copyright (C) Ibexa AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/
declare(strict_types=1);

namespace Ibexa\Tests\Core\MVC\Symfony\Templating;

use Ibexa\Contracts\Core\MVC\Templating\RenderStrategy;
use Ibexa\Core\MVC\Symfony\Templating\RenderOptions;
use PHPUnit\Framework\TestCase;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Controller\ControllerReference;

trait ForwardParamOptionsToFragmentRendererTrait
{
/**
* @param \Symfony\Component\HttpKernel\Fragment\FragmentRendererInterface|\PHPUnit\Framework\MockObject\MockObject $fragmentRendererMock
* @param \Ibexa\Contracts\Core\Repository\Values\ValueObject|\PHPUnit\Framework\MockObject\MockObject $valueObjectMock
* @param class-string<RenderStrategy> $renderStrategyClass
*/
public function forwardParamOptionsToFragmentRenderer(
object $fragmentRendererMock,
object $valueObjectMock,
string $renderStrategyClass
): void {
$params = [
'param1' => 'value1',
'param2' => 'value2',
];

$fragmentRendererMock
->method('getName')
->willReturn('fragment_render_mock');
$fragmentRendererMock->expects(self::once())
->method('render')
->with(
self::callback(static function ($controllerReference) use ($params) {
if (!$controllerReference instanceof ControllerReference) {
return false;
}

return $controllerReference->attributes['params'] === $params;
}),
self::anything(),
)
->willReturn(new Response('fragment_render_mock_rendered'));

$renderContentStrategy = self::createRenderStrategy(
$renderStrategyClass,
[
$fragmentRendererMock,
],
);

/** @var \Ibexa\Contracts\Core\Repository\Values\ValueObject&\PHPUnit\Framework\MockObject\MockObject $valueObjectMock */
TestCase::assertTrue($renderContentStrategy->supports($valueObjectMock));

TestCase::assertSame(
'fragment_render_mock_rendered',
$renderContentStrategy->render($valueObjectMock, new RenderOptions([
'method' => 'fragment_render_mock',
'viewType' => 'awesome',
'params' => $params,
]))
);
}
}
37 changes: 24 additions & 13 deletions tests/lib/MVC/Symfony/Templating/RenderContentStrategyTest.php
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<?php

/**
Expand All @@ -21,6 +21,8 @@

class RenderContentStrategyTest extends BaseRenderStrategyTest
{
use ForwardParamOptionsToFragmentRendererTrait;

public function testUnsupportedValueObject(): void
{
$renderContentStrategy = $this->createRenderStrategy(
Expand All @@ -32,7 +34,7 @@

$valueObject = new class() extends ValueObject {
};
$this->assertFalse($renderContentStrategy->supports($valueObject));
self::assertFalse($renderContentStrategy->supports($valueObject));

$this->expectException(InvalidArgumentException::class);
$renderContentStrategy->render($valueObject, new RenderOptions());
Expand All @@ -49,9 +51,9 @@
);

$contentMock = $this->createMock(Content::class);
$this->assertTrue($renderContentStrategy->supports($contentMock));
self::assertTrue($renderContentStrategy->supports($contentMock));

$this->assertSame(
self::assertSame(
'inline_rendered',
$renderContentStrategy->render($contentMock, new RenderOptions())
);
Expand All @@ -65,7 +67,7 @@
);

$contentMock = $this->createMock(Content::class);
$this->assertTrue($renderContentStrategy->supports($contentMock));
self::assertTrue($renderContentStrategy->supports($contentMock));

$this->expectException(InvalidArgumentException::class);
$renderContentStrategy->render($contentMock, new RenderOptions());
Expand All @@ -83,16 +85,25 @@
);

$contentMock = $this->createMock(Content::class);
$this->assertTrue($renderContentStrategy->supports($contentMock));
self::assertTrue($renderContentStrategy->supports($contentMock));

$this->assertSame(
self::assertSame(
'method_b_rendered',
$renderContentStrategy->render($contentMock, new RenderOptions([
'method' => 'method_b',
]))
);
}

public function testForwardParamOptionsToFragmentRenderer(): void

Check failure on line 98 in tests/lib/MVC/Symfony/Templating/RenderContentStrategyTest.php

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Add at least one assertion to this test case.

See more on https://sonarcloud.io/project/issues?id=ibexa_core&issues=AZraXN3ltQCaONsqrt6q&open=AZraXN3ltQCaONsqrt6q&pullRequest=674
{
$this->forwardParamOptionsToFragmentRenderer(
$this->createMock(FragmentRendererInterface::class),
$this->createMock(Content::class),
RenderContentStrategy::class,
);
}

public function testDuplicatedFragmentRenderers(): void
{
$renderContentStrategy = $this->createRenderStrategy(
Expand Down Expand Up @@ -127,19 +138,19 @@
->method('getName')
->willReturn('method_b');

$controllerReferenceCallback = $this->callback(function (ControllerReference $controllerReference) {
$this->assertInstanceOf(ControllerReference::class, $controllerReference);
$this->assertEquals('ibexa_content::viewAction', $controllerReference->controller);
$this->assertSame([
$controllerReferenceCallback = $this->callback(static function (ControllerReference $controllerReference) {
self::assertEquals('ibexa_content::viewAction', $controllerReference->controller);
self::assertSame([
'contentId' => 123,
'viewType' => 'awesome',
'params' => [],
], $controllerReference->attributes);

return true;
});

$requestCallback = $this->callback(function (Request $request) use ($siteAccess, $content): bool {
$this->assertSame('TEST/1.0', $request->headers->get('Surrogate-Capability'));
$requestCallback = $this->callback(static function (Request $request): bool {
self::assertSame('TEST/1.0', $request->headers->get('Surrogate-Capability'));

return true;
});
Expand All @@ -162,7 +173,7 @@
$request
);

$this->assertSame('some_rendered_content', $renderContentStrategy->render(
self::assertSame('some_rendered_content', $renderContentStrategy->render(
$content,
new RenderOptions([
'method' => 'method_b',
Expand Down
12 changes: 12 additions & 0 deletions tests/lib/MVC/Symfony/Templating/RenderLocationStrategyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@

class RenderLocationStrategyTest extends BaseRenderStrategyTest
{
use ForwardParamOptionsToFragmentRendererTrait;

public function testUnsupportedValueObject(): void
{
$renderLocationStrategy = $this->createRenderStrategy(
Expand Down Expand Up @@ -93,6 +95,15 @@
);
}

public function testForwardParamOptionsToFragmentRenderer(): void

Check failure on line 98 in tests/lib/MVC/Symfony/Templating/RenderLocationStrategyTest.php

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Add at least one assertion to this test case.

See more on https://sonarcloud.io/project/issues?id=ibexa_core&issues=AZpOuotvPAJ6APmmCTga&open=AZpOuotvPAJ6APmmCTga&pullRequest=674
{
$this->forwardParamOptionsToFragmentRenderer(
$this->createMock(FragmentRendererInterface::class),
$this->createMock(Location::class),
RenderLocationStrategy::class,
);
}

public function testExpectedMethodRenderRequestFormat(): void
{
$request = new Request();
Expand All @@ -114,6 +125,7 @@
'contentId' => 234,
'locationId' => 345,
'viewType' => 'awesome',
'params' => [],
], $controllerReference->attributes);

return true;
Expand Down
Loading