Skip to content

Commit f01474e

Browse files
committed
[TASK] Cover TypoScript reformatting with a CodeFormatRule test
- Assert a pure TypoScript reformat is attributed to the CodeFormatRule while a rule change stays attributed to its own rule
1 parent b177c5f commit f01474e

5 files changed

Lines changed: 84 additions & 0 deletions

File tree

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
page = PAGE
2+
page.10 = TEXT
3+
page.10.value = Hello
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
page = PAGE
2+
page.10 = TEXT
3+
page.10.value = Hello
4+
-----
5+
page = PAGE
6+
page.10 = TEXT
7+
page.10.value = Hello
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
page = PAGE
2+
config.spamProtectEmailAddresses = ascii
3+
-----
4+
page = PAGE
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace a9f\FractorTypoScript\Tests\TypoScriptProcessResult;
6+
7+
use a9f\Fractor\Application\ValueObject\AppliedRule;
8+
use a9f\Fractor\Testing\PHPUnit\AbstractFractorTestCase;
9+
use a9f\FractorTypoScript\Tests\Fixtures\DummyTypoScriptFractorRule;
10+
use PHPUnit\Framework\Attributes\DataProvider;
11+
12+
/**
13+
* The TypoScript pretty-printer re-formats files it touches, so a formatting-only
14+
* reformat must be attributed to the virtual CodeFormatRule (and count toward the
15+
* exit code), while a real transformation stays attributed to its own rule.
16+
*/
17+
final class TypoScriptProcessResultTest extends AbstractFractorTestCase
18+
{
19+
/**
20+
* @param list<string> $expectedAppliedRules
21+
*/
22+
#[DataProvider('provideData')]
23+
public function test(string $fixture, array $expectedAppliedRules): void
24+
{
25+
$fractorTestResult = $this->doTestFile(__DIR__ . '/Fixtures/' . $fixture);
26+
27+
self::assertSame($expectedAppliedRules, $fractorTestResult->getAppliedFractorRules());
28+
}
29+
30+
/**
31+
* @return \Iterator<string, array{string, list<string>}>
32+
*/
33+
public static function provideData(): \Iterator
34+
{
35+
yield 'rule change is attributed to the real rule' => [
36+
'rule-change.typoscript.fixture',
37+
[DummyTypoScriptFractorRule::class],
38+
];
39+
yield 'pure reformat is attributed to the virtual code-format rule' => [
40+
'reformatting.typoscript.fixture',
41+
[AppliedRule::CODE_FORMAT_RULE],
42+
];
43+
yield 'already formatted file reports no change' => ['already-formatted.typoscript.fixture', []];
44+
}
45+
46+
public function provideConfigFilePath(): string
47+
{
48+
return __DIR__ . '/config/fractor.php';
49+
}
50+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use a9f\Fractor\Configuration\FractorConfiguration;
6+
use a9f\FractorTypoScript\Configuration\TypoScriptProcessorOption;
7+
use a9f\FractorTypoScript\Tests\Fixtures\DummyTypoScriptFractorRule;
8+
use Helmich\TypoScriptParser\Parser\Printer\PrettyPrinterConditionTermination;
9+
use Helmich\TypoScriptParser\Parser\Printer\PrettyPrinterConfiguration;
10+
11+
return FractorConfiguration::configure()
12+
->withOptions([
13+
TypoScriptProcessorOption::INDENT_SIZE => 4,
14+
TypoScriptProcessorOption::INDENT_CHARACTER => PrettyPrinterConfiguration::INDENTATION_STYLE_SPACES,
15+
TypoScriptProcessorOption::ADD_CLOSING_GLOBAL => false,
16+
TypoScriptProcessorOption::INCLUDE_EMPTY_LINE_BREAKS => true,
17+
TypoScriptProcessorOption::INDENT_CONDITIONS => true,
18+
TypoScriptProcessorOption::CONDITION_TERMINATION => PrettyPrinterConditionTermination::Keep,
19+
])
20+
->withRules([DummyTypoScriptFractorRule::class]);

0 commit comments

Comments
 (0)