Skip to content

Commit

Permalink
[DowngradePhp73] Handle heredoc new line stripped on multi rules
Browse files Browse the repository at this point in the history
  • Loading branch information
samsonasik committed Dec 12, 2024
1 parent 0ed4563 commit fe6ddfc
Show file tree
Hide file tree
Showing 3 changed files with 143 additions and 0 deletions.
28 changes: 28 additions & 0 deletions tests/Issues/DowngradeHeredoc/DowngradeHeredocTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

declare(strict_types=1);

namespace Rector\Tests\Issues\DowngradeHeredoc;

use Iterator;
use PHPUnit\Framework\Attributes\DataProvider;
use Rector\Testing\PHPUnit\AbstractRectorTestCase;

final class DowngradeHeredocTest extends AbstractRectorTestCase
{
#[DataProvider('provideData')]
public function test(string $filePath): void
{
$this->doTestFile($filePath);
}

public static function provideData(): Iterator
{
return self::yieldFilesFromDirectory(__DIR__ . '/Fixture');
}

public function provideConfigFilePath(): string
{
return __DIR__ . '/config/configured_rule.php';
}
}
105 changes: 105 additions & 0 deletions tests/Issues/DowngradeHeredoc/Fixture/fixture.php.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
<?php

namespace Rector\Tests\Issues\DowngradeNullJson\DowngradeHeredoc;

class Fixture
{
public function getDefinition(): FixerDefinitionInterface
{
return new FixerDefinition(
'Sorts attributes using the configured sort algorithm.',
[
new VersionSpecificCodeSample(
<<<'EOL'
<?php
#[Foo]
#[Bar(3)]
#[Qux(new Bar(5))]
#[Corge(a: 'test')]
class Sample1 {}
#[
Foo,
Bar(3),
Qux(new Bar(5)),
Corge(a: 'test'),
]
class Sample2 {}

EOL,
new VersionSpecification(8_00_00),
),
new VersionSpecificCodeSample(
<<<'EOL'
<?php
use A\B\Foo;
use A\B\Bar as BarAlias;
use A\B as AB;
#[Foo]
#[BarAlias(3)]
#[AB\Qux(new Bar(5))]
#[\A\B\Corge(a: 'test')]
class Sample1 {}

EOL,
new VersionSpecification(8_00_00),
['sort_algorithm' => self::ORDER_CUSTOM, 'order' => ['A\B\Qux', 'A\B\Bar', 'A\B\Corge']],
),
],
);
}
}

?>
-----
<?php

namespace Rector\Tests\Issues\DowngradeNullJson\DowngradeHeredoc;

class Fixture
{
public function getDefinition(): FixerDefinitionInterface
{
return new FixerDefinition('Sorts attributes using the configured sort algorithm.', [
new VersionSpecificCodeSample(<<<'EOL'
<?php
#[Foo]
#[Bar(3)]
#[Qux(new Bar(5))]
#[Corge(a: 'test')]
class Sample1 {}
#[
Foo,
Bar(3),
Qux(new Bar(5)),
Corge(a: 'test'),
]
class Sample2 {}

EOL
, new VersionSpecification(80000)),
new VersionSpecificCodeSample(<<<'EOL'
<?php
use A\B\Foo;
use A\B\Bar as BarAlias;
use A\B as AB;
#[Foo]
#[BarAlias(3)]
#[AB\Qux(new Bar(5))]
#[\A\B\Corge(a: 'test')]
class Sample1 {}

EOL
, new VersionSpecification(80000), ['sort_algorithm' => self::ORDER_CUSTOM, 'order' => ['A\B\Qux', 'A\B\Bar', 'A\B\Corge']]),
]);
}
}

?>
10 changes: 10 additions & 0 deletions tests/Issues/DowngradeHeredoc/config/configured_rule.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

declare(strict_types=1);

use Rector\Config\RectorConfig;
use Rector\Set\ValueObject\DowngradeLevelSetList;

return static function (RectorConfig $rectorConfig): void {
$rectorConfig->sets([DowngradeLevelSetList::DOWN_TO_PHP_72]);
};

0 comments on commit fe6ddfc

Please sign in to comment.