Skip to content

Commit 7328397

Browse files
author
MateuszKolankowski
committed
Simplified render arguments normalization in Twig integration tests.
1 parent 0529031 commit 7328397

10 files changed

+102
-77
lines changed

tests/lib/MVC/Symfony/Templating/Twig/Extension/FileSystemTwigIntegrationTestCase.php

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,6 @@
2323
*/
2424
abstract class FileSystemTwigIntegrationTestCase extends IntegrationTestCase
2525
{
26-
private function normalizeOutput(string $value): string
27-
{
28-
return preg_replace(
29-
'/(^|[\s(])\\\\([A-Za-z_\\\\][A-Za-z0-9_\\\\]*::__set_state\()/m',
30-
'$1$2',
31-
$value
32-
) ?? $value;
33-
}
34-
3526
/**
3627
* Overrides the default implementation to use the chain loader so that
3728
* templates used internally are correctly loaded.
@@ -124,8 +115,7 @@ protected function doIntegrationTest($file, $message, $condition, $templates, $e
124115
);
125116
}
126117

127-
$expected = $this->normalizeOutput(trim($match[3], "\n "));
128-
$output = $this->normalizeOutput($output);
118+
$expected = trim($match[3], "\n ");
129119

130120
if ($expected != $output) {
131121
echo 'Compiled template that failed:';

tests/lib/MVC/Symfony/Templating/Twig/Extension/QueryRenderingExtensionTest.php

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,52 @@
99
namespace Ibexa\Tests\Core\MVC\Symfony\Templating\Twig\Extension;
1010

1111
use Ibexa\Core\MVC\Symfony\Templating\Twig\Extension\QueryRenderingExtension;
12+
use Symfony\Component\HttpKernel\Controller\ControllerReference;
1213
use Symfony\Component\HttpKernel\Fragment\FragmentHandler;
1314

1415
final class QueryRenderingExtensionTest extends FileSystemTwigIntegrationTestCase
1516
{
17+
/**
18+
* @param array<mixed> $options
19+
*
20+
* @return array{
21+
* reference: array{
22+
* controller: string,
23+
* attributes: array<mixed>,
24+
* query: array<mixed>,
25+
* },
26+
* renderer: string,
27+
* options: array<mixed>,
28+
* }
29+
*/
30+
private static function normalizeRenderArguments(
31+
ControllerReference $reference,
32+
string $renderer,
33+
array $options
34+
): array
35+
{
36+
return [
37+
'reference' => [
38+
'controller' => $reference->controller,
39+
'attributes' => $reference->attributes,
40+
'query' => $reference->query,
41+
],
42+
'renderer' => $renderer,
43+
'options' => $options,
44+
];
45+
}
46+
1647
protected function getExtensions(): array
1748
{
1849
$fragmentHandler = $this->createMock(FragmentHandler::class);
1950
$fragmentHandler
2051
->method('render')
21-
->willReturnCallback(static function (...$args): string {
22-
return var_export($args, true);
52+
->willReturnCallback(static function (
53+
ControllerReference $reference,
54+
string $renderer,
55+
array $options
56+
): string {
57+
return var_export(self::normalizeRenderArguments($reference, $renderer, $options), true);
2358
});
2459

2560
return [

tests/lib/MVC/Symfony/Templating/Twig/Extension/_fixtures/query_rendering_functions/ez_render_content_query.test

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@
1111
return array()
1212
--EXPECT--
1313
array (
14-
0 =>
15-
Symfony\Component\HttpKernel\Controller\ControllerReference::__set_state(array(
16-
'controller' => 'ibexa_query_render::renderQuery',
17-
'attributes' =>
14+
'reference' =>
15+
array (
16+
'controller' => 'ibexa_query_render::renderQuery',
17+
'attributes' =>
1818
array (
1919
'options' =>
2020
array (
@@ -25,12 +25,12 @@ array (
2525
'template' => 'latest_blog_post.html.twig',
2626
),
2727
),
28-
'query' =>
28+
'query' =>
2929
array (
3030
),
31-
)),
32-
1 => 'inline',
33-
2 =>
31+
),
32+
'renderer' => 'inline',
33+
'options' =>
3434
array (
3535
),
3636
)

tests/lib/MVC/Symfony/Templating/Twig/Extension/_fixtures/query_rendering_functions/ez_render_content_query_esi.test

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@
1111
return array()
1212
--EXPECT--
1313
array (
14-
0 =>
15-
Symfony\Component\HttpKernel\Controller\ControllerReference::__set_state(array(
16-
'controller' => 'ibexa_query_render::renderQuery',
17-
'attributes' =>
14+
'reference' =>
15+
array (
16+
'controller' => 'ibexa_query_render::renderQuery',
17+
'attributes' =>
1818
array (
1919
'options' =>
2020
array (
@@ -25,12 +25,12 @@ array (
2525
'template' => 'latest_blog_post.html.twig',
2626
),
2727
),
28-
'query' =>
28+
'query' =>
2929
array (
3030
),
31-
)),
32-
1 => 'esi',
33-
2 =>
31+
),
32+
'renderer' => 'esi',
33+
'options' =>
3434
array (
3535
),
3636
)

tests/lib/MVC/Symfony/Templating/Twig/Extension/_fixtures/query_rendering_functions/ez_render_location_query.test

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@
1111
return array()
1212
--EXPECT--
1313
array (
14-
0 =>
15-
Symfony\Component\HttpKernel\Controller\ControllerReference::__set_state(array(
16-
'controller' => 'ibexa_query_render::renderQuery',
17-
'attributes' =>
14+
'reference' =>
15+
array (
16+
'controller' => 'ibexa_query_render::renderQuery',
17+
'attributes' =>
1818
array (
1919
'options' =>
2020
array (
@@ -25,12 +25,12 @@ array (
2525
'template' => 'latest_blog_post.html.twig',
2626
),
2727
),
28-
'query' =>
28+
'query' =>
2929
array (
3030
),
31-
)),
32-
1 => 'inline',
33-
2 =>
31+
),
32+
'renderer' => 'inline',
33+
'options' =>
3434
array (
3535
),
3636
)

tests/lib/MVC/Symfony/Templating/Twig/Extension/_fixtures/query_rendering_functions/ez_render_location_query_esi.test

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@
1111
return array()
1212
--EXPECT--
1313
array (
14-
0 =>
15-
Symfony\Component\HttpKernel\Controller\ControllerReference::__set_state(array(
16-
'controller' => 'ibexa_query_render::renderQuery',
17-
'attributes' =>
14+
'reference' =>
15+
array (
16+
'controller' => 'ibexa_query_render::renderQuery',
17+
'attributes' =>
1818
array (
1919
'options' =>
2020
array (
@@ -25,12 +25,12 @@ array (
2525
'template' => 'latest_blog_post.html.twig',
2626
),
2727
),
28-
'query' =>
28+
'query' =>
2929
array (
3030
),
31-
)),
32-
1 => 'esi',
33-
2 =>
31+
),
32+
'renderer' => 'esi',
33+
'options' =>
3434
array (
3535
),
3636
)

tests/lib/MVC/Symfony/Templating/Twig/Extension/_fixtures/query_rendering_functions/ibexa_render_content_query.test

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@
1111
return array()
1212
--EXPECT--
1313
array (
14-
0 =>
15-
Symfony\Component\HttpKernel\Controller\ControllerReference::__set_state(array(
16-
'controller' => 'ibexa_query_render::renderQuery',
17-
'attributes' =>
14+
'reference' =>
15+
array (
16+
'controller' => 'ibexa_query_render::renderQuery',
17+
'attributes' =>
1818
array (
1919
'options' =>
2020
array (
@@ -25,12 +25,12 @@ array (
2525
'template' => 'latest_blog_post.html.twig',
2626
),
2727
),
28-
'query' =>
28+
'query' =>
2929
array (
3030
),
31-
)),
32-
1 => 'inline',
33-
2 =>
31+
),
32+
'renderer' => 'inline',
33+
'options' =>
3434
array (
3535
),
3636
)

tests/lib/MVC/Symfony/Templating/Twig/Extension/_fixtures/query_rendering_functions/ibexa_render_content_query_esi.test

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@
1111
return array()
1212
--EXPECT--
1313
array (
14-
0 =>
15-
Symfony\Component\HttpKernel\Controller\ControllerReference::__set_state(array(
16-
'controller' => 'ibexa_query_render::renderQuery',
17-
'attributes' =>
14+
'reference' =>
15+
array (
16+
'controller' => 'ibexa_query_render::renderQuery',
17+
'attributes' =>
1818
array (
1919
'options' =>
2020
array (
@@ -25,12 +25,12 @@ array (
2525
'template' => 'latest_blog_post.html.twig',
2626
),
2727
),
28-
'query' =>
28+
'query' =>
2929
array (
3030
),
31-
)),
32-
1 => 'esi',
33-
2 =>
31+
),
32+
'renderer' => 'esi',
33+
'options' =>
3434
array (
3535
),
3636
)

tests/lib/MVC/Symfony/Templating/Twig/Extension/_fixtures/query_rendering_functions/ibexa_render_location_query.test

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@
1111
return array()
1212
--EXPECT--
1313
array (
14-
0 =>
15-
Symfony\Component\HttpKernel\Controller\ControllerReference::__set_state(array(
16-
'controller' => 'ibexa_query_render::renderQuery',
17-
'attributes' =>
14+
'reference' =>
15+
array (
16+
'controller' => 'ibexa_query_render::renderQuery',
17+
'attributes' =>
1818
array (
1919
'options' =>
2020
array (
@@ -25,12 +25,12 @@ array (
2525
'template' => 'latest_blog_post.html.twig',
2626
),
2727
),
28-
'query' =>
28+
'query' =>
2929
array (
3030
),
31-
)),
32-
1 => 'inline',
33-
2 =>
31+
),
32+
'renderer' => 'inline',
33+
'options' =>
3434
array (
3535
),
3636
)

tests/lib/MVC/Symfony/Templating/Twig/Extension/_fixtures/query_rendering_functions/ibexa_render_location_query_esi.test

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@
1111
return array()
1212
--EXPECT--
1313
array (
14-
0 =>
15-
Symfony\Component\HttpKernel\Controller\ControllerReference::__set_state(array(
16-
'controller' => 'ibexa_query_render::renderQuery',
17-
'attributes' =>
14+
'reference' =>
15+
array (
16+
'controller' => 'ibexa_query_render::renderQuery',
17+
'attributes' =>
1818
array (
1919
'options' =>
2020
array (
@@ -25,12 +25,12 @@ array (
2525
'template' => 'latest_blog_post.html.twig',
2626
),
2727
),
28-
'query' =>
28+
'query' =>
2929
array (
3030
),
31-
)),
32-
1 => 'esi',
33-
2 =>
31+
),
32+
'renderer' => 'esi',
33+
'options' =>
3434
array (
3535
),
3636
)

0 commit comments

Comments
 (0)