Skip to content

Commit

Permalink
add test for double assign removal
Browse files Browse the repository at this point in the history
  • Loading branch information
TomasVotruba committed Nov 16, 2024
1 parent 9cd6376 commit 5b990b9
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 0 deletions.
49 changes: 49 additions & 0 deletions tests/Issues/KeepDoubleAssignParam/Fixture/fixture.php.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php

namespace Rector\Tests\Issues\KeepDoubleAssignParam\Fixture;

final class Fixture
{
private $items;

public function __construct($input)
{
if (! \is_array($input)) {
$this->items = [$input];
} else {
$this->items = $input;
}

$this->items = $this->getItems();
}

public function getItems()
{
return sort($this->items);
}
}

?>
-----
<?php

namespace Rector\Tests\Issues\KeepDoubleAssignParam\Fixture;

final class Fixture
{
private $items;

public function __construct($input)
{
$this->items = !\is_array($input) ? [$input] : $input;

$this->items = $this->getItems();
}

public function getItems()
{
return sort($this->items);
}
}

?>
28 changes: 28 additions & 0 deletions tests/Issues/KeepDoubleAssignParam/KeepDoubleAssignParamTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

declare(strict_types=1);

namespace Rector\Tests\Issues\KeepDoubleAssignParam;

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

final class KeepDoubleAssignParamTest 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';
}
}
12 changes: 12 additions & 0 deletions tests/Issues/KeepDoubleAssignParam/config/configured_rule.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

declare(strict_types=1);

use Rector\Config\RectorConfig;

return RectorConfig::configure()
->withRules([
\Rector\CodeQuality\Rector\If_\SimplifyIfElseToTernaryRector::class,
\Rector\DeadCode\Rector\Assign\RemoveDoubleAssignRector::class,
\Rector\DeadCode\Rector\ClassMethod\RemoveUnusedConstructorParamRector::class,
]);

0 comments on commit 5b990b9

Please sign in to comment.