Skip to content

Commit

Permalink
Migrate the deprecated lists method in Laravel 5.3
Browse files Browse the repository at this point in the history
  • Loading branch information
GeniJaho committed Oct 17, 2024
1 parent 84edb4a commit 5d07152
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 0 deletions.
9 changes: 9 additions & 0 deletions config/sets/laravel53.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

use Rector\Config\RectorConfig;
use Rector\Removing\Rector\Class_\RemoveTraitUseRector;
use Rector\Renaming\Rector\MethodCall\RenameMethodRector;
use Rector\Renaming\ValueObject\MethodCallRename;

return static function (RectorConfig $rectorConfig): void {
$rectorConfig->import(__DIR__ . '/../config.php');
Expand All @@ -12,4 +14,11 @@
// see https://laravel.com/docs/5.3/upgrade
'Illuminate\Foundation\Auth\Access\AuthorizesResources',
]);

$rectorConfig
->ruleWithConfiguration(RenameMethodRector::class, [
// https://laravel.com/docs/5.3/upgrade#5.2-deprecations
new MethodCallRename('Illuminate\Support\Collection', 'lists', 'pluck'),
new MethodCallRename('Illuminate\Database\Query\Builder', 'lists', 'pluck'),
]);
};
23 changes: 23 additions & 0 deletions tests/Sets/Laravel53/Fixture/fixture.php.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

namespace RectorLaravel\Tests\Sets\Laravel53;

use Illuminate\Support\Collection;

(new Collection())->lists('id');
(new \Illuminate\Database\Eloquent\Builder())->lists('id');
(new \Illuminate\Database\Query\Builder())->lists('id');

?>
-----
<?php

namespace RectorLaravel\Tests\Sets\Laravel53;

use Illuminate\Support\Collection;

(new Collection())->pluck('id');
(new \Illuminate\Database\Eloquent\Builder())->pluck('id');
(new \Illuminate\Database\Query\Builder())->pluck('id');

?>
31 changes: 31 additions & 0 deletions tests/Sets/Laravel53/Laravel53Test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

declare(strict_types=1);

namespace RectorLaravel\Tests\Sets\Laravel53;

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

final class Laravel53Test extends AbstractRectorTestCase
{
public static function provideData(): Iterator
{
return self::yieldFilesFromDirectory(__DIR__ . '/Fixture');
}

/**
* @test
*/
#[DataProvider('provideData')]
public function test(string $filePath): void
{
$this->doTestFile($filePath);
}

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

declare(strict_types=1);

use Rector\Config\RectorConfig;

return static function (RectorConfig $rectorConfig): void {
$rectorConfig->import(__DIR__ . '/../../../../config/sets/laravel53.php');
};

0 comments on commit 5d07152

Please sign in to comment.