Skip to content

Commit

Permalink
Fix test suite (#453)
Browse files Browse the repository at this point in the history
* Fix test suite

* phpcbf

* Revert "phpcbf"

This reverts commit b4b739d.

* phpcbf

* revert ci.yml

* remove old code
  • Loading branch information
bytestream authored Feb 12, 2025
1 parent f6cbdb9 commit 20a3e79
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 19 deletions.
7 changes: 1 addition & 6 deletions src/ServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -232,12 +232,7 @@ function () {
);

foreach ($this->app['config']->get('twigbridge.twig.safe_classes', []) as $safeClass => $strategy) {
// "Since twig/twig 3.10: The "Twig\Extension\EscaperExtension::addSafeClass()" method is deprecated, use the "Twig\Runtime\EscaperRuntime::addSafeClass()" method instead."
if (class_exists(EscaperRuntime::class)) {
$twig->getRuntime(EscaperRuntime::class)->addSafeClass($safeClass, $strategy);
} else {
$twig->getExtension(EscaperExtension::class)->addSafeClass($safeClass, $strategy);
}
$twig->getExtension(EscaperExtension::class)->addSafeClass($safeClass, $strategy);
}

// Instantiate and add extensions
Expand Down
6 changes: 3 additions & 3 deletions tests/Node/GetAttrTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,10 @@ public function getTests()
$node = $this->getNode($expr, $attr, $args, Template::ARRAY_CALL);
$tests[] = [
$node,
'(($__internal_%s = // line 1' . "\n"
'(($_v0 = // line 1' . "\n"
. '($context["foo"] ?? null))'
. ' && is_array($__internal_%s)'
. ' || $__internal_%s instanceof ArrayAccess ? ($__internal_%s["bar"] ?? null) : null)',
. ' && is_array($_v0)'
. ' || $_v0 instanceof ArrayAccess ? ($_v0["bar"] ?? null) : null)',
null,
true,
];
Expand Down
12 changes: 7 additions & 5 deletions tests/Node/TemplateForTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Twig\Environment;
use Twig\Source;
use Twig\Template;
use Twig\TemplateWrapper;

class TemplateForTest extends Template
{
Expand Down Expand Up @@ -36,31 +37,32 @@ public function getTrue()
return true;
}

public function getTemplateName()
public function getTemplateName(): string
{
return $this->name;
}

public function getDebugInfo()
public function getDebugInfo(): array
{
return [];
}

protected function doGetParent(array $context)
protected function doGetParent(array $context): bool|string|self|TemplateWrapper
{
return false;
}

protected function doDisplay(array $context, array $blocks = [])
protected function doDisplay(array $context, array $blocks = []): iterable
{
return [];
}

/**
* Returns information about the original template source code.
*
* @return Source
*/
public function getSourceContext()
public function getSourceContext(): Source
{
return new Source('', $this->getTemplateName());
}
Expand Down
5 changes: 0 additions & 5 deletions tests/TwigIntegrationTests/TwigIntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,6 @@ protected function doIntegrationTest(
$twig->addFunction($function);
}

// avoid using the same PHP class name for different cases
$p = new \ReflectionProperty(Environment::class, 'templateClassPrefix');
$p->setAccessible(true);
$p->setValue($twig, '__TwigTemplate_' . hash('sha256', uniqid(mt_rand(), true), false) . '_');

$deprecations = [];
try {
$prevHandler = set_error_handler(
Expand Down

0 comments on commit 20a3e79

Please sign in to comment.