Skip to content

Commit fe6ddfc

Browse files
committed
[DowngradePhp73] Handle heredoc new line stripped on multi rules
1 parent 0ed4563 commit fe6ddfc

File tree

3 files changed

+143
-0
lines changed

3 files changed

+143
-0
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Rector\Tests\Issues\DowngradeHeredoc;
6+
7+
use Iterator;
8+
use PHPUnit\Framework\Attributes\DataProvider;
9+
use Rector\Testing\PHPUnit\AbstractRectorTestCase;
10+
11+
final class DowngradeHeredocTest extends AbstractRectorTestCase
12+
{
13+
#[DataProvider('provideData')]
14+
public function test(string $filePath): void
15+
{
16+
$this->doTestFile($filePath);
17+
}
18+
19+
public static function provideData(): Iterator
20+
{
21+
return self::yieldFilesFromDirectory(__DIR__ . '/Fixture');
22+
}
23+
24+
public function provideConfigFilePath(): string
25+
{
26+
return __DIR__ . '/config/configured_rule.php';
27+
}
28+
}
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
<?php
2+
3+
namespace Rector\Tests\Issues\DowngradeNullJson\DowngradeHeredoc;
4+
5+
class Fixture
6+
{
7+
public function getDefinition(): FixerDefinitionInterface
8+
{
9+
return new FixerDefinition(
10+
'Sorts attributes using the configured sort algorithm.',
11+
[
12+
new VersionSpecificCodeSample(
13+
<<<'EOL'
14+
<?php
15+
16+
#[Foo]
17+
#[Bar(3)]
18+
#[Qux(new Bar(5))]
19+
#[Corge(a: 'test')]
20+
class Sample1 {}
21+
22+
#[
23+
Foo,
24+
Bar(3),
25+
Qux(new Bar(5)),
26+
Corge(a: 'test'),
27+
]
28+
class Sample2 {}
29+
30+
EOL,
31+
new VersionSpecification(8_00_00),
32+
),
33+
new VersionSpecificCodeSample(
34+
<<<'EOL'
35+
<?php
36+
37+
use A\B\Foo;
38+
use A\B\Bar as BarAlias;
39+
use A\B as AB;
40+
41+
#[Foo]
42+
#[BarAlias(3)]
43+
#[AB\Qux(new Bar(5))]
44+
#[\A\B\Corge(a: 'test')]
45+
class Sample1 {}
46+
47+
EOL,
48+
new VersionSpecification(8_00_00),
49+
['sort_algorithm' => self::ORDER_CUSTOM, 'order' => ['A\B\Qux', 'A\B\Bar', 'A\B\Corge']],
50+
),
51+
],
52+
);
53+
}
54+
}
55+
56+
?>
57+
-----
58+
<?php
59+
60+
namespace Rector\Tests\Issues\DowngradeNullJson\DowngradeHeredoc;
61+
62+
class Fixture
63+
{
64+
public function getDefinition(): FixerDefinitionInterface
65+
{
66+
return new FixerDefinition('Sorts attributes using the configured sort algorithm.', [
67+
new VersionSpecificCodeSample(<<<'EOL'
68+
<?php
69+
70+
#[Foo]
71+
#[Bar(3)]
72+
#[Qux(new Bar(5))]
73+
#[Corge(a: 'test')]
74+
class Sample1 {}
75+
76+
#[
77+
Foo,
78+
Bar(3),
79+
Qux(new Bar(5)),
80+
Corge(a: 'test'),
81+
]
82+
class Sample2 {}
83+
84+
EOL
85+
, new VersionSpecification(80000)),
86+
new VersionSpecificCodeSample(<<<'EOL'
87+
<?php
88+
89+
use A\B\Foo;
90+
use A\B\Bar as BarAlias;
91+
use A\B as AB;
92+
93+
#[Foo]
94+
#[BarAlias(3)]
95+
#[AB\Qux(new Bar(5))]
96+
#[\A\B\Corge(a: 'test')]
97+
class Sample1 {}
98+
99+
EOL
100+
, new VersionSpecification(80000), ['sort_algorithm' => self::ORDER_CUSTOM, 'order' => ['A\B\Qux', 'A\B\Bar', 'A\B\Corge']]),
101+
]);
102+
}
103+
}
104+
105+
?>
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use Rector\Config\RectorConfig;
6+
use Rector\Set\ValueObject\DowngradeLevelSetList;
7+
8+
return static function (RectorConfig $rectorConfig): void {
9+
$rectorConfig->sets([DowngradeLevelSetList::DOWN_TO_PHP_72]);
10+
};

0 commit comments

Comments
 (0)