Skip to content
This repository was archived by the owner on Mar 20, 2025. It is now read-only.

Commit a11954e

Browse files
committed
Fix failing tests
1 parent 91b7ecf commit a11954e

File tree

8 files changed

+41
-13
lines changed

8 files changed

+41
-13
lines changed

src/Tasks/DebugCalls.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
namespace Shift\Cli\Tasks;
44

55
use Shift\Cli\Sdk\Contracts\Task;
6-
use Shift\Cli\Sdk\Parsers\NikicParser;
76
use Shift\Cli\Sdk\Facades\Comment;
7+
use Shift\Cli\Sdk\Parsers\NikicParser;
88
use Shift\Cli\Sdk\Traits\FindsFiles;
99

1010
class DebugCalls implements Task

src/Tasks/ExplicitOrderBy.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
namespace Shift\Cli\Tasks;
44

55
use Shift\Cli\Sdk\Contracts\Task;
6+
use Shift\Cli\Sdk\Models\File;
67
use Shift\Cli\Sdk\Parsers\Finders\QueryOrderByFinder;
78
use Shift\Cli\Sdk\Parsers\NikicParser;
8-
use Shift\Cli\Sdk\Models\File;
99
use Shift\Cli\Sdk\Traits\FindsFiles;
1010

1111
class ExplicitOrderBy implements Task

src/Tasks/LatestOldest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
namespace Shift\Cli\Tasks;
44

55
use Shift\Cli\Sdk\Contracts\Task;
6+
use Shift\Cli\Sdk\Models\File;
67
use Shift\Cli\Sdk\Parsers\Finders\QueryOrderByFinder;
78
use Shift\Cli\Sdk\Parsers\NikicParser;
8-
use Shift\Cli\Sdk\Models\File;
99
use Shift\Cli\Sdk\Traits\FindsFiles;
1010

1111
class LatestOldest implements Task

src/Tasks/ModelTableName.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@ public function perform(): int
2121
continue;
2222
}
2323

24-
var_dump('here');
25-
2624
$conventional_name = $this->tableNameFromClassName($model->getShortName(), $this->isPivotModel($model));
2725

2826
if ($model->getProperty('table')->getDefaultValue() !== $conventional_name) {
@@ -33,8 +31,8 @@ public function perform(): int
3331
$class = $this->parseClass($file->contents());
3432

3533
$start = $class['properties']['table']['comment'] ? $class['properties']['table']['comment']['line']['start'] : $class['properties']['table']['line']['start'];
36-
$file->removeBlankLinesAfter($class['properties']['table']['line']['end']);
3734
$file->removeSegment($start, $class['properties']['table']['line']['end']);
35+
$file->removeBlankLinesAround($start);
3836

3937
file_put_contents($path, $file->contents());
4038
}

tests/Feature/Tasks/ModelTableNameTest.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Tests\Feature\Tasks;
44

55
use PHPUnit\Framework\Attributes\Test;
6+
use Shift\Cli\Sdk\Facades\Reflector;
67
use Shift\Cli\Sdk\Testing\InteractsWithProject;
78
use Shift\Cli\Sdk\Testing\TestCase;
89
use Shift\Cli\Tasks\ModelTableName;
@@ -16,6 +17,26 @@ class ModelTableNameTest extends TestCase
1617

1718
private ModelTableName $subject;
1819

20+
private function mockReflectionClass(string $name, string $table, bool $pivot = false)
21+
{
22+
$mock = \Mockery::mock(\ReflectionClass::class);
23+
$mock->expects('isSubclassOf')
24+
->with('Illuminate\\Database\\Eloquent\\Model')
25+
->andReturn(true);
26+
$mock->expects('getDefaultProperties')
27+
->andReturn(['table' => $table]);
28+
$mock->expects('isSubclassOf')
29+
->with('Illuminate\\Database\\Eloquent\\Relations\\Pivot')
30+
->andReturn($pivot);
31+
$mock->expects('getShortName')
32+
->withNoArgs()
33+
->andReturn($name);
34+
$mock->expects('getProperty->getDefaultValue')
35+
->andReturn($table);
36+
37+
return $mock;
38+
}
39+
1940
protected function setUp(): void
2041
{
2142
parent::setUp();
@@ -45,6 +66,15 @@ public function it_replaces_arguments_with_explicit_methods()
4566
'app/Models/RoleUser.php' => 'tests/fixtures/table-name/pivot.php',
4667
]);
4768

69+
$reflector = \Mockery::mock('Reflector');
70+
$reflector->expects('classFromPath')
71+
->with($this->currentSnapshotPath() . '/app/Models/User.php')
72+
->andReturn($this->mockReflectionClass('User', 'users'));
73+
$reflector->expects('classFromPath')
74+
->with($this->currentSnapshotPath() . '/app/Models/RoleUser.php')
75+
->andReturn($this->mockReflectionClass('RoleUser', 'role_user', true));
76+
Reflector::swap($reflector);
77+
4878
$result = $this->subject->perform();
4979

5080
$this->assertSame(0, $result);

tests/fixtures/class-strings/complex.after.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ class RouteServiceProvider extends ServiceProvider
1212

1313
public function boot(): void
1414
{
15-
Route::bind('user', \Shift\Cli\Models\User::class);
16-
Route::bind('comment', \Shift\Cli\Models\Comment::class);
17-
Route::bind('post', \Shift\Cli\Models\Post::class);
15+
Route::bind('user', \App\Models\User::class);
16+
Route::bind('comment', \App\Models\Comment::class);
17+
Route::bind('post', \App\Models\Post::class);
1818

1919
Route::bind('foo', \Modules\Foo::class);
2020
Route::bind('bar', \Modules\Bar::class);

tests/fixtures/class-strings/complex.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ class RouteServiceProvider extends ServiceProvider
1313
public function boot(): void
1414
{
1515
Route::bind('user', 'App\Models\User');
16-
Route::bind('comment', '\\Shift\Cli\\Models\\Comment');
17-
Route::bind('post', "\Shift\Cli\Models\Post");
16+
Route::bind('comment', '\\App\\Models\\Comment');
17+
Route::bind('post', "\App\Models\Post");
1818

1919
Route::bind('foo', "Modules\Foo");
2020
Route::bind('bar', '\Modules\Bar');

tests/fixtures/class-strings/simple.after.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ class Post extends Model
88
{
99
public function user()
1010
{
11-
return $this->belongsTo(\Shift\Cli\Models\User::class);
11+
return $this->belongsTo(\App\Models\User::class);
1212
}
1313

1414
public function comments()
1515
{
16-
return $this->hasMany(\Shift\Cli\Models\Comment::class);
16+
return $this->hasMany(\App\Models\Comment::class);
1717
}
1818
}

0 commit comments

Comments
 (0)