Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 1 addition & 37 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -30462,12 +30462,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 @@ -58567,23 +58561,11 @@ parameters:
path: tests/lib/MVC/Symfony/Templating/BaseRenderStrategyTest.php

-
message: '#^Method Symfony\\Component\\HttpKernel\\Fragment\\FragmentRendererInterface@anonymous/tests/lib/MVC/Symfony/Templating/BaseRenderStrategyTest\.php\:51\:\:render\(\) has parameter \$options with no value type specified in iterable type array\.$#'
message: '#^Method Symfony\\Component\\HttpKernel\\Fragment\\FragmentRendererInterface@anonymous/tests/lib/MVC/Symfony/Templating/BaseRenderStrategyTest\.php\:53\:\:render\(\) has parameter \$options with no value type specified in iterable type array\.$#'
identifier: missingType.iterableValue
count: 1
path: tests/lib/MVC/Symfony/Templating/BaseRenderStrategyTest.php

-
message: '#^Property Symfony\\Component\\HttpKernel\\Fragment\\FragmentRendererInterface@anonymous/tests/lib/MVC/Symfony/Templating/BaseRenderStrategyTest\.php\:51\:\:\$rendered \(string\) does not accept string\|null\.$#'
identifier: assign.propertyType
count: 1
path: tests/lib/MVC/Symfony/Templating/BaseRenderStrategyTest.php

-
message: '#^Property Symfony\\Component\\HttpKernel\\Fragment\\FragmentRendererInterface@anonymous/tests/lib/MVC/Symfony/Templating/BaseRenderStrategyTest\.php\:51\:\:\$rendered \(string\) on left side of \?\? is not nullable\.$#'
identifier: nullCoalesce.property
count: 1
path: tests/lib/MVC/Symfony/Templating/BaseRenderStrategyTest.php

-
message: '#^Method Ibexa\\Tests\\Core\\MVC\\Symfony\\Templating\\GlobalHelperTest\:\:testGetAvailableLanguages\(\) has no return type specified\.$#'
identifier: missingType.return
Expand Down Expand Up @@ -58644,24 +58626,6 @@ parameters:
count: 1
path: tests/lib/MVC/Symfony/Templating/GlobalHelperTest.php

-
message: '#^Anonymous function has an unused use \$content\.$#'
identifier: closure.unusedUse
count: 1
path: tests/lib/MVC/Symfony/Templating/RenderContentStrategyTest.php

-
message: '#^Anonymous function has an unused use \$siteAccess\.$#'
identifier: closure.unusedUse
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
56 changes: 55 additions & 1 deletion tests/lib/MVC/Symfony/Templating/BaseRenderStrategyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,15 @@
use Ibexa\Contracts\Core\Repository\Values\Content\ContentInfo;
use Ibexa\Contracts\Core\Repository\Values\Content\Location as APILocation;
use Ibexa\Core\MVC\Symfony\SiteAccess;
use Ibexa\Core\MVC\Symfony\Templating\RenderOptions;
use Ibexa\Core\Repository\Values\Content\Content;
use Ibexa\Core\Repository\Values\Content\Location;
use Ibexa\Core\Repository\Values\Content\VersionInfo;
use Ibexa\Tests\Core\Search\TestCase;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Controller\ControllerReference;
use Symfony\Component\HttpKernel\Fragment\FragmentRendererInterface;

abstract class BaseRenderStrategyTest extends TestCase
Expand Down Expand Up @@ -52,7 +54,7 @@ public function createFragmentRenderer(
/** @var string */
private $name;

/** @var string */
/** @var string|null */
private $rendered;

public function __construct(
Expand Down Expand Up @@ -97,6 +99,58 @@ public function createContent(int $id): APIContent
]),
]);
}

/**
* @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): bool {
if (!$controllerReference instanceof ControllerReference) {
return false;
}

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

$renderContentStrategy = $this->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,
]))
);
}
}

class_alias(BaseRenderStrategyTest::class, 'eZ\Publish\Core\MVC\Symfony\Templating\Tests\BaseRenderStrategyTest');
35 changes: 22 additions & 13 deletions tests/lib/MVC/Symfony/Templating/RenderContentStrategyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public function testUnsupportedValueObject(): void

$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 +49,9 @@ public function testDefaultFragmentRenderer(): void
);

$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 +65,7 @@ public function testUnknownFragmentRenderer(): void
);

$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 +83,25 @@ public function testMultipleFragmentRenderers(): void
);

$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
{
$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 +136,19 @@ public function testExpectedMethodRenderArgumentsFormat(): void
->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): bool {
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 +171,7 @@ public function testExpectedMethodRenderArgumentsFormat(): void
$request
);

$this->assertSame('some_rendered_content', $renderContentStrategy->render(
self::assertSame('some_rendered_content', $renderContentStrategy->render(
$content,
new RenderOptions([
'method' => 'method_b',
Expand Down
10 changes: 10 additions & 0 deletions tests/lib/MVC/Symfony/Templating/RenderLocationStrategyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,15 @@ public function testMultipleFragmentRenderers(): void
);
}

public function testForwardParamOptionsToFragmentRenderer(): void
{
$this->forwardParamOptionsToFragmentRenderer(
$this->createMock(FragmentRendererInterface::class),
$this->createMock(Location::class),
RenderLocationStrategy::class,
);
}

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

return true;
Expand Down
Loading