diff --git a/src/Console/ModelsCommand.php b/src/Console/ModelsCommand.php index 2cb12b2..0b2c6cd 100644 --- a/src/Console/ModelsCommand.php +++ b/src/Console/ModelsCommand.php @@ -660,6 +660,10 @@ class ModelsCommand extends Command $classname = $reflection->getShortName(); $originalDoc = $reflection->getDocComment(); $keyword = $this->getClassKeyword($reflection); + $interfaceNames = array_diff_key( + $reflection->getInterfaceNames(), + $reflection->getParentClass()->getInterfaceNames() + ); if ($this->reset) { $phpdoc = new DocBlock('', new Context($namespace)); @@ -748,8 +752,14 @@ class ModelsCommand extends Command } } - $output = "namespace {$namespace}{\n{$docComment}\n\t{$keyword}class {$classname} extends \Eloquent {}\n}\n\n"; - return $output; + $output = "namespace {$namespace}{\n{$docComment}\n\t{$keyword}class {$classname} extends \Eloquent "; + + if ($interfaceNames) { + $interfaces = implode(', \\', $interfaceNames); + $output .= "implements \\{$interfaces} "; + } + + return $output . "{}\n}\n\n"; } /** diff --git a/tests/Console/ModelsCommand/Interfaces/Models/User.php b/tests/Console/ModelsCommand/Interfaces/Models/User.php new file mode 100644 index 0000000..8c3eba6 --- /dev/null +++ b/tests/Console/ModelsCommand/Interfaces/Models/User.php @@ -0,0 +1,39 @@ +set('ide-helper', [ + 'model_locations' => [ + // This is calculated from the base_path() which points to + // vendor/orchestra/testbench-core/laravel + '/../../../../tests/Console/ModelsCommand/Interfaces/Models', + ], + ]); + } + + public function test(): void + { + $actualContent = null; + $mockFilesystem = Mockery::mock(Filesystem::class); + + $mockFilesystem + ->shouldReceive('put') + ->with( + Mockery::any(), + Mockery::capture($actualContent) + ) + ->andReturn(1) // Simulate we wrote _something_ to the file + ->once(); + + $this->instance(Filesystem::class, $mockFilesystem); + + $command = $this->app->make(ModelsCommand::class); + + $tester = $this->runCommand($command, [ + '--nowrite' => true, + ]); + + $this->assertSame(0, $tester->getStatusCode()); + $this->assertEmpty($tester->getDisplay()); + + $expectedContent = <<<'PHP' + + */ + + +namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\Interfaces\Models{ +/** + * Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\Interfaces\Models\User + * + * @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\Interfaces\Models\User newModelQuery() + * @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\Interfaces\Models\User newQuery() + * @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\Interfaces\Models\User query() + */ + class User extends \Eloquent implements \Illuminate\Contracts\Auth\Authenticatable {} +} + + +PHP; + + $this->assertSame($expectedContent, $actualContent); + } +}