Skip to content

Commit

Permalink
bug #4187 Fix integration tests when a test has more than on data/exp…
Browse files Browse the repository at this point in the history
…ect section and deprecations (fabpot)

This PR was merged into the 3.x branch.

Discussion
----------

Fix integration tests when a test has more than on data/expect section and deprecations

Fixes #4186

As deprecations are emitted at compile time, we need to make sure templates are always compiled even when we have more than one data/expect section (in which case the templates are the same). The trick here is to add some whitespace at the end of the template.

Commits
-------

a5dc02b Fix integration tests when a test has more than on data/expect section and deprecations
  • Loading branch information
fabpot committed Aug 9, 2024
2 parents 5550140 + a5dc02b commit b3f953c
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 3 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# 3.11.1 (2024-XX-XX)

* n/a
* Fix integration tests when a test has more than on data/expect section and deprecations

# 3.11.0 (2024-08-08)

Expand Down
7 changes: 5 additions & 2 deletions src/Test/IntegrationTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -156,13 +156,16 @@ protected function doIntegrationTest($file, $message, $condition, $templates, $e
}
}

$loader = new ArrayLoader($templates);

foreach ($outputs as $i => $match) {
$config = array_merge([
'cache' => false,
'strict_variables' => true,
], $match[2] ? eval($match[2].';') : []);
// make sure that template are always compiled even if they are the same (useful when testing with more than one data/expect sections)
foreach ($templates as $j => $template) {
$templates[$j] = $template.str_repeat(' ', $i);
}
$loader = new ArrayLoader($templates);
$twig = new Environment($loader, $config);
$twig->addGlobal('global', 'global');
foreach ($this->getRuntimeLoaders() as $runtimeLoader) {
Expand Down
21 changes: 21 additions & 0 deletions tests/Fixtures/functions/deprecated.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
--TEST--
Functions can be deprecated_function
--DEPRECATION--
Since foo/bar 1.1: Twig Function "deprecated_function" is deprecated. Use "not_deprecated_function" instead in index.twig at line 2.
Since foo/bar 1.1: Twig Function "deprecated_function" is deprecated. Use "not_deprecated_function" instead in index.twig at line 4.
--TEMPLATE--
{{ deprecated_function() }}

{{ deprecated_function() }}
--DATA--
return []
--EXPECT--
foo

foo
--DATA--
return []
--EXPECT--
foo

foo
1 change: 1 addition & 0 deletions tests/IntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ public function getFunctions(): array
new TwigFunction('*_path', [$this, 'dynamic_path']),
new TwigFunction('*_foo_*_bar', [$this, 'dynamic_foo']),
new TwigFunction('anon_foo', function ($name) { return '*'.$name.'*'; }),
new TwigFunction('deprecated_function', function () { return 'foo'; }, ['deprecated' => '1.1', 'deprecating_package' => 'foo/bar', 'alternative' => 'not_deprecated_function']),
];
}

Expand Down

0 comments on commit b3f953c

Please sign in to comment.