Skip to content

Commit 9c1f2e5

Browse files
authored
Add missing renames for dispatchNow method on Jobs (#219)
* Add missing renames for dispatchNow method on Jobs * Add tests for the Laravel 10 Set * Add missing test for the Laravel 10 Set
1 parent 50dd0cf commit 9c1f2e5

File tree

7 files changed

+128
-2
lines changed

7 files changed

+128
-2
lines changed

config/sets/laravel100.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,15 @@
3535
$rectorConfig
3636
->ruleWithConfiguration(RenamePropertyRector::class, [
3737
// https://github.com/laravel/laravel/commit/edcbe6de7c3f17070bf0ccaa2e2b785158ae5ceb
38-
new RenameProperty('App\Http\Kernel', 'routeMiddleware', 'middlewareAliases'),
38+
new RenameProperty('Illuminate\Foundation\Http\Kernel', 'routeMiddleware', 'middlewareAliases'),
3939
]);
4040

4141
$rectorConfig
4242
->ruleWithConfiguration(RenameMethodRector::class, [
4343
// https://github.com/laravel/framework/pull/42591/files
4444
new MethodCallRename('Illuminate\Support\Facades\Bus', 'dispatchNow', 'dispatchSync'),
45+
new MethodCallRename('Illuminate\Foundation\Bus\Dispatchable', 'dispatchNow', 'dispatchSync'),
46+
new MethodCallRename('Illuminate\Foundation\Bus\DispatchesJobs', 'dispatchNow', 'dispatchSync'),
4547
]);
4648

4749
$rectorConfig

duster.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"src"
66
],
77
"exclude": [
8-
"tests/Rector/**/**/Fixture"
8+
"tests/Rector/**/**/Fixture",
9+
"tests/Sets/**/Fixture"
910
]
1011
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
namespace Illuminate\Foundation\Bus;
4+
5+
if (class_exists('Illuminate\Foundation\Bus\DispatchesJobs')) {
6+
return;
7+
}
8+
9+
trait DispatchesJobs
10+
{
11+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Illuminate\Foundation\Http;
6+
7+
if (class_exists('Illuminate\Foundation\Http\Kernel')) {
8+
return;
9+
}
10+
11+
class Kernel
12+
{
13+
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
<?php
2+
3+
namespace RectorLaravel\Tests\Sets\Laravel100;
4+
5+
use Illuminate\Foundation\Bus\Dispatchable;
6+
use Illuminate\Foundation\Bus\DispatchesJobs;
7+
use Illuminate\Support\Facades\Bus;
8+
9+
class DispatchableJobClass
10+
{
11+
use Dispatchable;
12+
}
13+
14+
class DispatchesJobsClass
15+
{
16+
use DispatchesJobs;
17+
}
18+
19+
class Kernel extends \Illuminate\Foundation\Http\Kernel
20+
{
21+
protected $routeMiddleware = [];
22+
}
23+
24+
Bus::dispatchNow(fn () => null);
25+
DispatchableJobClass::dispatchNow(fn () => null);
26+
DispatchesJobsClass::dispatchNow(fn () => null);
27+
dispatch_now(fn () => null);
28+
29+
?>
30+
-----
31+
<?php
32+
33+
namespace RectorLaravel\Tests\Sets\Laravel100;
34+
35+
use Illuminate\Foundation\Bus\Dispatchable;
36+
use Illuminate\Foundation\Bus\DispatchesJobs;
37+
use Illuminate\Support\Facades\Bus;
38+
39+
class DispatchableJobClass
40+
{
41+
use Dispatchable;
42+
}
43+
44+
class DispatchesJobsClass
45+
{
46+
use DispatchesJobs;
47+
}
48+
49+
class Kernel extends \Illuminate\Foundation\Http\Kernel
50+
{
51+
protected $middlewareAliases = [];
52+
}
53+
54+
Bus::dispatchSync(fn () => null);
55+
DispatchableJobClass::dispatchSync(fn () => null);
56+
DispatchesJobsClass::dispatchSync(fn () => null);
57+
dispatch_sync(fn () => null);
58+
59+
?>
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace RectorLaravel\Tests\Sets\Laravel100;
6+
7+
use Iterator;
8+
use PHPUnit\Framework\Attributes\DataProvider;
9+
use Rector\Testing\PHPUnit\AbstractRectorTestCase;
10+
11+
final class Laravel100Test extends AbstractRectorTestCase
12+
{
13+
public static function provideData(): Iterator
14+
{
15+
return self::yieldFilesFromDirectory(__DIR__ . '/Fixture');
16+
}
17+
18+
/**
19+
* @test
20+
*/
21+
#[DataProvider('provideData')]
22+
public function test(string $filePath): void
23+
{
24+
$this->doTestFile($filePath);
25+
}
26+
27+
public function provideConfigFilePath(): string
28+
{
29+
return __DIR__ . '/config/configured_rule.php';
30+
}
31+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use Rector\Config\RectorConfig;
6+
7+
return static function (RectorConfig $rectorConfig): void {
8+
$rectorConfig->import(__DIR__ . '/../../../../config/sets/laravel100.php');
9+
};

0 commit comments

Comments
 (0)