Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test examples for include to render #327

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 2 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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor detail, but this file shoud be named IncludeToRenderFunctionRuleTest.fixed.twig (the Test suffix is missing)

tests/Rules/Function/IncludeToRender/IncludeToRenderFunctionRuleTest.fixed.twig

Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{{ render('template.html', _context) }}
{{ render('template.html', {..._context, 'foo': 'bar'}) }}
{{ render('template.html', {..._context, 'foo': 'bar'}, true) }}
{{ render('template.html', {..._context, 'foo': 'bar'}, true, true) }}
{{ render('template.html', _context) }}

{{ render(['template_a.html', 'template_b.html'], _context) }}
{{ render(['template_a.html', 'template_b.html'], {..._context, 'foo': 'bar'}) }}
{{ render(['template_a.html', 'template_b.html'], {..._context, 'foo': 'bar'}, true) }}
{{ render(['template_a.html', 'template_b.html'], {..._context, 'foo': 'bar'}, true, true) }}
{{ render(['template_a.html', 'template_b.html'], _context) }}

{{ render(['template_a.html', 'template_b.html']) }}
{{ render(['template_a.html', 'template_b.html'], {'foo': 'bar'}) }}
{{ render(['template_a.html', 'template_b.html'], {'foo': 'bar'}, true) }}
{{ render(['template_a.html', 'template_b.html'], {'foo': 'bar'}, true, true) }}
{{ render(['template_a.html', 'template_b.html']) }}
alexander-schranz marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

declare(strict_types=1);

namespace TwigCsFixer\Tests\Rules\Function\RenderFunction;

use TwigCsFixer\Rules\Function\IncludeToRenderFunctionRule;
use TwigCsFixer\Rules\Punctuation\PunctuationSpacingRule;
use TwigCsFixer\Test\AbstractRuleTestCase;

final class IncludeToRenderFunctionRuleTest extends AbstractRuleTestCase
{
public function testRule(): void
{
$this->checkRule(
[

Check failure on line 16 in tests/Rules/Function/IncludeToRender/IncludeToRenderFunctionRuleTest.php

View workflow job for this annotation

GitHub Actions / PHPStan

Parameter #1 $rules of method TwigCsFixer\Test\AbstractRuleTestCase::checkRule() expects array<TwigCsFixer\Rules\Node\NodeRuleInterface|TwigCsFixer\Rules\RuleInterface>|TwigCsFixer\Rules\Node\NodeRuleInterface|TwigCsFixer\Rules\RuleInterface, array<int, TwigCsFixer\Rules\Function\IncludeToRenderFunctionRule|TwigCsFixer\Rules\Punctuation\PunctuationSpacingRule> given.

Check failure on line 16 in tests/Rules/Function/IncludeToRender/IncludeToRenderFunctionRuleTest.php

View workflow job for this annotation

GitHub Actions / Psalm

MixedArgumentTypeCoercion

tests/Rules/Function/IncludeToRender/IncludeToRenderFunctionRuleTest.php:16:13: MixedArgumentTypeCoercion: Argument 1 of TwigCsFixer\Tests\Rules\Function\RenderFunction\IncludeToRenderFunctionRuleTest::checkRule expects TwigCsFixer\Rules\Node\NodeRuleInterface|TwigCsFixer\Rules\RuleInterface|array<array-key, TwigCsFixer\Rules\Node\NodeRuleInterface|TwigCsFixer\Rules\RuleInterface>, but parent type list{mixed, TwigCsFixer\Rules\Punctuation\PunctuationSpacingRule} provided (see https://psalm.dev/194)
new IncludeToRenderFunctionRule(),

Check failure on line 17 in tests/Rules/Function/IncludeToRender/IncludeToRenderFunctionRuleTest.php

View workflow job for this annotation

GitHub Actions / PHPStan

Instantiated class TwigCsFixer\Rules\Function\IncludeToRenderFunctionRule not found.

Check failure on line 17 in tests/Rules/Function/IncludeToRender/IncludeToRenderFunctionRuleTest.php

View workflow job for this annotation

GitHub Actions / Psalm

UndefinedClass

tests/Rules/Function/IncludeToRender/IncludeToRenderFunctionRuleTest.php:17:21: UndefinedClass: Class, interface or enum named TwigCsFixer\Rules\Function\IncludeToRenderFunctionRule does not exist (see https://psalm.dev/019)
// Extra rule for a better diff
new PunctuationSpacingRule(),
],
[
'IncludeToRender.Error:13:4' => 'Include function must be used instead of include tag.',
'IncludeToRender.Error:14:4' => 'Include function must be used instead of include tag.',
'IncludeToRender.Error:15:5' => 'Include function must be used instead of include tag.',
'IncludeToRender.Error:16:5' => 'Include function must be used instead of include tag.',
]
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{{ include('template.html') }}
{{ include('template.html', {'foo': 'bar'}, true) }}
{{ include('template.html', {'foo': 'bar'}, true, true) }}
{{ include('template.html', {'foo': 'bar'}, true, true, true) }}
{{ include('template.html', with_context = true) }}

{{ include(['template_a.html', 'template_b.html']) }}
{{ include(['template_a.html', 'template_b.html'], {'foo': 'bar'}, true) }}
{{ include(['template_a.html', 'template_b.html'], {'foo': 'bar'}, true, true) }}
{{ include(['template_a.html', 'template_b.html'], {'foo': 'bar'}, true, true, true) }}
{{ include(['template_a.html', 'template_b.html'], with_context = true) }}

{{ include(['template_a.html', 'template_b.html'], with_context = false) }}
{{ include(['template_a.html', 'template_b.html'], {'foo': 'bar'}, false) }}
{{ include(['template_a.html', 'template_b.html'], {'foo': 'bar'}, false, true) }}
{{ include(['template_a.html', 'template_b.html'], {'foo': 'bar'}, false, true, true) }}
{{ include(['template_a.html', 'template_b.html'], with_context = true) }}
Loading