[Models] Fixed wrong imported name (#993)

* Fixes 992 (class names in phpdoc where using imported names incorrectly when writing to external file).
Disabled using imported name in external file, except for the models own name.

* Added missing declare strict types
This commit is contained in:
Gabriel Langer
2020-07-17 08:07:09 +02:00
committed by GitHub
parent 4ffda148ce
commit e8044dc920
5 changed files with 286 additions and 26 deletions
@@ -0,0 +1,54 @@
<?php declare(strict_types=1);
namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GeneratePhpdocWithFqnInExternalFile;
use Barryvdh\LaravelIdeHelper\Console\ModelsCommand;
use Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\AbstractModelsCommand;
use Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GeneratePhpdocWithFqn\Models\Post;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Filesystem\Filesystem;
use Mockery;
class Test extends AbstractModelsCommand
{
protected function getEnvironmentSetUp($app)
{
parent::getEnvironmentSetUp($app);
$app['config']->set('ide-helper', [
'model_locations' => [
// This is calculated from the base_path() which points to
// vendor/orchestra/testbench-core/laravel
'/../../../../tests/Console/ModelsCommand/GeneratePhpdocWithFqnInExternalFile/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());
$this->assertMatchesPhpSnapshot($actualContent);
}
}