Skip to content

Commit d57fa8b

Browse files
authored
Handle Carbon setTestNow with no arguments (#242)
1 parent 8d39c5b commit d57fa8b

File tree

2 files changed

+43
-1
lines changed

2 files changed

+43
-1
lines changed

src/Rector/StaticCall/CarbonSetTestNowToTravelToRector.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace RectorLaravel\Rector\StaticCall;
44

55
use PhpParser\Node;
6+
use PhpParser\Node\Arg;
67
use PhpParser\Node\Expr\MethodCall;
78
use PhpParser\Node\Expr\StaticCall;
89
use PhpParser\Node\Expr\Variable;
@@ -87,7 +88,15 @@ public function refactorWithScope(Node $node, Scope $scope): ?MethodCall
8788
return null;
8889
}
8990

90-
return $this->nodeFactory->createMethodCall(new Variable('this'), 'travelTo', $node->args);
91+
$args = $node->args === []
92+
? [new Arg($this->nodeFactory->createNull())]
93+
: $node->args;
94+
95+
return $this->nodeFactory->createMethodCall(
96+
new Variable('this'),
97+
'travelTo',
98+
$args,
99+
);
91100
}
92101

93102
private function isCarbon(Node $node): bool
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
3+
namespace RectorLaravel\Tests\Rector\StaticCall\CarbonSetTestNowToTravelToRector\Fixture;
4+
5+
use Illuminate\Foundation\Testing\TestCase;
6+
use Carbon\Carbon;
7+
8+
class SomeTest extends TestCase
9+
{
10+
public function test()
11+
{
12+
Carbon::setTestNow();
13+
}
14+
}
15+
16+
?>
17+
-----
18+
<?php
19+
20+
namespace RectorLaravel\Tests\Rector\StaticCall\CarbonSetTestNowToTravelToRector\Fixture;
21+
22+
use Illuminate\Foundation\Testing\TestCase;
23+
use Carbon\Carbon;
24+
25+
class SomeTest extends TestCase
26+
{
27+
public function test()
28+
{
29+
$this->travelTo(null);
30+
}
31+
}
32+
33+
?>

0 commit comments

Comments
 (0)