3
3
namespace Tests \Feature \Tasks ;
4
4
5
5
use PHPUnit \Framework \Attributes \Test ;
6
+ use Shift \Cli \Sdk \Facades \Reflector ;
6
7
use Shift \Cli \Sdk \Testing \InteractsWithProject ;
7
8
use Shift \Cli \Sdk \Testing \TestCase ;
8
9
use Shift \Cli \Tasks \ModelTableName ;
@@ -16,6 +17,26 @@ class ModelTableNameTest extends TestCase
16
17
17
18
private ModelTableName $ subject ;
18
19
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
+
19
40
protected function setUp (): void
20
41
{
21
42
parent ::setUp ();
@@ -45,6 +66,15 @@ public function it_replaces_arguments_with_explicit_methods()
45
66
'app/Models/RoleUser.php ' => 'tests/fixtures/table-name/pivot.php ' ,
46
67
]);
47
68
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
+
48
78
$ result = $ this ->subject ->perform ();
49
79
50
80
$ this ->assertSame (0 , $ result );
0 commit comments