mirror of
https://github.com/barryvdh/laravel-ide-helper.git
synced 2026-08-18 01:57:13 +00:00
Simplify test by mocking filesystem always (#1019)
This commit is contained in:
@@ -97,7 +97,7 @@ class ModelsCommand extends Command
|
|||||||
$filename = $this->option('filename');
|
$filename = $this->option('filename');
|
||||||
$this->write = $this->option('write');
|
$this->write = $this->option('write');
|
||||||
$this->dirs = array_merge(
|
$this->dirs = array_merge(
|
||||||
$this->laravel['config']->get('ide-helper.model_locations'),
|
$this->laravel['config']->get('ide-helper.model_locations', []),
|
||||||
$this->option('dir')
|
$this->option('dir')
|
||||||
);
|
);
|
||||||
$model = $this->argument('model');
|
$model = $this->argument('model');
|
||||||
@@ -272,7 +272,15 @@ class ModelsCommand extends Command
|
|||||||
{
|
{
|
||||||
$models = array();
|
$models = array();
|
||||||
foreach ($this->dirs as $dir) {
|
foreach ($this->dirs as $dir) {
|
||||||
$dir = base_path() . '/' . $dir;
|
if (is_dir(base_path($dir))) {
|
||||||
|
$dir = base_path($dir);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!is_dir($dir)) {
|
||||||
|
$this->error("Cannot locate directory '{'$dir}'");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
$dirs = glob($dir, GLOB_ONLYDIR);
|
$dirs = glob($dir, GLOB_ONLYDIR);
|
||||||
foreach ($dirs as $dir) {
|
foreach ($dirs as $dir) {
|
||||||
if (file_exists($dir)) {
|
if (file_exists($dir)) {
|
||||||
|
|||||||
@@ -4,11 +4,18 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand;
|
namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand;
|
||||||
|
|
||||||
|
use Barryvdh\LaravelIdeHelper\IdeHelperServiceProvider;
|
||||||
|
use Barryvdh\LaravelIdeHelper\Tests\SnapshotPhpDriver;
|
||||||
|
use Barryvdh\LaravelIdeHelper\Tests\SnapshotTxtDriver;
|
||||||
use Barryvdh\LaravelIdeHelper\Tests\TestCase;
|
use Barryvdh\LaravelIdeHelper\Tests\TestCase;
|
||||||
|
use Illuminate\Filesystem\Filesystem;
|
||||||
use Illuminate\Foundation\Application;
|
use Illuminate\Foundation\Application;
|
||||||
|
use Mockery;
|
||||||
|
|
||||||
abstract class AbstractModelsCommand extends TestCase
|
abstract class AbstractModelsCommand extends TestCase
|
||||||
{
|
{
|
||||||
|
protected $mockFilesystemOutput;
|
||||||
|
|
||||||
protected function setUp(): void
|
protected function setUp(): void
|
||||||
{
|
{
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
@@ -21,6 +28,22 @@ abstract class AbstractModelsCommand extends TestCase
|
|||||||
|
|
||||||
$this->loadMigrationsFrom(__DIR__ . '/migrations');
|
$this->loadMigrationsFrom(__DIR__ . '/migrations');
|
||||||
$this->artisan('migrate');
|
$this->artisan('migrate');
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
$this->mockFilesystem();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get package providers.
|
||||||
|
*
|
||||||
|
* @param \Illuminate\Foundation\Application $app
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
protected function getPackageProviders($app)
|
||||||
|
{
|
||||||
|
return [IdeHelperServiceProvider::class];
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function getEnvironmentSetUp($app)
|
protected function getEnvironmentSetUp($app)
|
||||||
@@ -35,5 +58,45 @@ abstract class AbstractModelsCommand extends TestCase
|
|||||||
'database' => ':memory:',
|
'database' => ':memory:',
|
||||||
'prefix' => '',
|
'prefix' => '',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
// Load the Models from the Test dir
|
||||||
|
$config->set('ide-helper.model_locations', [
|
||||||
|
dirname((new \ReflectionClass(static::class))->getFileName()) . '/Models',
|
||||||
|
]);
|
||||||
|
|
||||||
|
// Don't override integer -> int for tests
|
||||||
|
$config->set('ide-helper.type_overrides', []);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function mockFilesystem()
|
||||||
|
{
|
||||||
|
$this->mockOutput = '';
|
||||||
|
|
||||||
|
$mockFilesystem = Mockery::mock(Filesystem::class);
|
||||||
|
|
||||||
|
$mockFilesystem
|
||||||
|
->shouldReceive('get')
|
||||||
|
->andReturnUsing(function ($file) {
|
||||||
|
return file_get_contents($file);
|
||||||
|
});
|
||||||
|
|
||||||
|
$mockFilesystem
|
||||||
|
->shouldReceive('put')
|
||||||
|
->with(
|
||||||
|
Mockery::any(),
|
||||||
|
Mockery::any()
|
||||||
|
)
|
||||||
|
->andReturnUsing(function ($path, $contents) {
|
||||||
|
$this->mockFilesystemOutput .= $contents;
|
||||||
|
|
||||||
|
return strlen($contents);
|
||||||
|
});
|
||||||
|
|
||||||
|
$this->instance(Filesystem::class, $mockFilesystem);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function assertMatchesMockedSnapshot()
|
||||||
|
{
|
||||||
|
$this->assertMatchesSnapshot($this->mockFilesystemOutput, new SnapshotPhpDriver());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,38 +12,8 @@ use Mockery;
|
|||||||
|
|
||||||
class Test extends AbstractModelsCommand
|
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/CustomCollection/Models',
|
|
||||||
],
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function test(): void
|
public function test(): void
|
||||||
{
|
{
|
||||||
$actualContent = null;
|
|
||||||
$mockFilesystem = Mockery::mock(Filesystem::class);
|
|
||||||
$mockFilesystem
|
|
||||||
->shouldReceive('get')
|
|
||||||
->andReturn(file_get_contents(__DIR__ . '/Models/Simple.php'))
|
|
||||||
->once();
|
|
||||||
$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);
|
$command = $this->app->make(ModelsCommand::class);
|
||||||
|
|
||||||
$tester = $this->runCommand($command, [
|
$tester = $this->runCommand($command, [
|
||||||
@@ -52,6 +22,6 @@ class Test extends AbstractModelsCommand
|
|||||||
|
|
||||||
$this->assertSame(0, $tester->getStatusCode());
|
$this->assertSame(0, $tester->getStatusCode());
|
||||||
$this->assertStringContainsString('Written new phpDocBlock to', $tester->getDisplay());
|
$this->assertStringContainsString('Written new phpDocBlock to', $tester->getDisplay());
|
||||||
$this->assertMatchesPhpSnapshot($actualContent);
|
$this->assertMatchesMockedSnapshot();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,38 +28,8 @@ class Test extends AbstractModelsCommand
|
|||||||
parent::tearDown();
|
parent::tearDown();
|
||||||
}
|
}
|
||||||
|
|
||||||
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/CustomDate/Models',
|
|
||||||
],
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function test(): void
|
public function test(): void
|
||||||
{
|
{
|
||||||
$actualContent = null;
|
|
||||||
$mockFilesystem = Mockery::mock(Filesystem::class);
|
|
||||||
$mockFilesystem
|
|
||||||
->shouldReceive('get')
|
|
||||||
->andReturn(file_get_contents(__DIR__ . '/Models/CustomDate.php'))
|
|
||||||
->once();
|
|
||||||
$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);
|
$command = $this->app->make(ModelsCommand::class);
|
||||||
|
|
||||||
$tester = $this->runCommand($command, [
|
$tester = $this->runCommand($command, [
|
||||||
@@ -68,6 +38,6 @@ class Test extends AbstractModelsCommand
|
|||||||
|
|
||||||
$this->assertSame(0, $tester->getStatusCode());
|
$this->assertSame(0, $tester->getStatusCode());
|
||||||
$this->assertStringContainsString('Written new phpDocBlock to', $tester->getDisplay());
|
$this->assertStringContainsString('Written new phpDocBlock to', $tester->getDisplay());
|
||||||
$this->assertMatchesPhpSnapshot($actualContent);
|
$this->assertMatchesMockedSnapshot();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,43 +6,11 @@ namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\DynamicRelations
|
|||||||
|
|
||||||
use Barryvdh\LaravelIdeHelper\Console\ModelsCommand;
|
use Barryvdh\LaravelIdeHelper\Console\ModelsCommand;
|
||||||
use Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\AbstractModelsCommand;
|
use Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\AbstractModelsCommand;
|
||||||
use Illuminate\Filesystem\Filesystem;
|
|
||||||
use Mockery;
|
|
||||||
|
|
||||||
class Test extends AbstractModelsCommand
|
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/DynamicRelations/Models',
|
|
||||||
],
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function test(): void
|
public function test(): void
|
||||||
{
|
{
|
||||||
$actualContent = null;
|
|
||||||
$mockFilesystem = Mockery::mock(Filesystem::class);
|
|
||||||
$mockFilesystem
|
|
||||||
->shouldReceive('get')
|
|
||||||
->andReturn(file_get_contents(__DIR__ . '/Models/Dynamic.php'))
|
|
||||||
->once();
|
|
||||||
$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);
|
$command = $this->app->make(ModelsCommand::class);
|
||||||
|
|
||||||
$tester = $this->runCommand($command, [
|
$tester = $this->runCommand($command, [
|
||||||
@@ -51,6 +19,6 @@ class Test extends AbstractModelsCommand
|
|||||||
|
|
||||||
$this->assertSame(0, $tester->getStatusCode());
|
$this->assertSame(0, $tester->getStatusCode());
|
||||||
$this->assertStringContainsString('Written new phpDocBlock to', $tester->getDisplay());
|
$this->assertStringContainsString('Written new phpDocBlock to', $tester->getDisplay());
|
||||||
$this->assertMatchesPhpSnapshot($actualContent);
|
$this->assertMatchesMockedSnapshot();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,38 +11,8 @@ use Mockery;
|
|||||||
|
|
||||||
class Test extends AbstractModelsCommand
|
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/GenerateBasicPhpdoc/Models',
|
|
||||||
],
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function test(): void
|
public function test(): void
|
||||||
{
|
{
|
||||||
$actualContent = null;
|
|
||||||
$mockFilesystem = Mockery::mock(Filesystem::class);
|
|
||||||
$mockFilesystem
|
|
||||||
->shouldReceive('get')
|
|
||||||
->andReturn(file_get_contents(__DIR__ . '/Models/Post.php'))
|
|
||||||
->once();
|
|
||||||
$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);
|
$command = $this->app->make(ModelsCommand::class);
|
||||||
|
|
||||||
$tester = $this->runCommand($command, [
|
$tester = $this->runCommand($command, [
|
||||||
@@ -51,6 +21,6 @@ class Test extends AbstractModelsCommand
|
|||||||
|
|
||||||
$this->assertSame(0, $tester->getStatusCode());
|
$this->assertSame(0, $tester->getStatusCode());
|
||||||
$this->assertStringContainsString('Written new phpDocBlock to', $tester->getDisplay());
|
$this->assertStringContainsString('Written new phpDocBlock to', $tester->getDisplay());
|
||||||
$this->assertMatchesPhpSnapshot($actualContent);
|
$this->assertMatchesMockedSnapshot();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,36 +15,11 @@ class Test extends AbstractModelsCommand
|
|||||||
{
|
{
|
||||||
parent::getEnvironmentSetUp($app);
|
parent::getEnvironmentSetUp($app);
|
||||||
|
|
||||||
$app['config']->set('ide-helper', [
|
$app['config']->set('ide-helper.model_camel_case_properties', true);
|
||||||
'model_locations' => [
|
|
||||||
// This is calculated from the base_path() which points to
|
|
||||||
// vendor/orchestra/testbench-core/laravel
|
|
||||||
'/../../../../tests/Console/ModelsCommand/GenerateBasicPhpdocCamel/Models',
|
|
||||||
],
|
|
||||||
// Activate the camel_case mode
|
|
||||||
'model_camel_case_properties' => true,
|
|
||||||
]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function test(): void
|
public function test(): void
|
||||||
{
|
{
|
||||||
$actualContent = null;
|
|
||||||
$mockFilesystem = Mockery::mock(Filesystem::class);
|
|
||||||
$mockFilesystem
|
|
||||||
->shouldReceive('get')
|
|
||||||
->andReturn(file_get_contents(__DIR__ . '/Models/Post.php'))
|
|
||||||
->once();
|
|
||||||
$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);
|
$command = $this->app->make(ModelsCommand::class);
|
||||||
|
|
||||||
$tester = $this->runCommand($command, [
|
$tester = $this->runCommand($command, [
|
||||||
@@ -53,6 +28,6 @@ class Test extends AbstractModelsCommand
|
|||||||
|
|
||||||
$this->assertSame(0, $tester->getStatusCode());
|
$this->assertSame(0, $tester->getStatusCode());
|
||||||
$this->assertStringContainsString('Written new phpDocBlock to', $tester->getDisplay());
|
$this->assertStringContainsString('Written new phpDocBlock to', $tester->getDisplay());
|
||||||
$this->assertMatchesPhpSnapshot($actualContent);
|
$this->assertMatchesMockedSnapshot();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,38 +11,8 @@ use Mockery;
|
|||||||
|
|
||||||
class Test extends AbstractModelsCommand
|
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/GenerateBasicPhpdocFinal/Models',
|
|
||||||
],
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function test(): void
|
public function test(): void
|
||||||
{
|
{
|
||||||
$actualContent = null;
|
|
||||||
$mockFilesystem = Mockery::mock(Filesystem::class);
|
|
||||||
$mockFilesystem
|
|
||||||
->shouldReceive('get')
|
|
||||||
->andReturn(file_get_contents(__DIR__ . '/Models/Post.php'))
|
|
||||||
->once();
|
|
||||||
$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);
|
$command = $this->app->make(ModelsCommand::class);
|
||||||
|
|
||||||
$tester = $this->runCommand($command, [
|
$tester = $this->runCommand($command, [
|
||||||
@@ -51,6 +21,6 @@ class Test extends AbstractModelsCommand
|
|||||||
|
|
||||||
$this->assertSame(0, $tester->getStatusCode());
|
$this->assertSame(0, $tester->getStatusCode());
|
||||||
$this->assertStringContainsString('Written new phpDocBlock to', $tester->getDisplay());
|
$this->assertStringContainsString('Written new phpDocBlock to', $tester->getDisplay());
|
||||||
$this->assertMatchesPhpSnapshot($actualContent);
|
$this->assertMatchesMockedSnapshot();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,38 +15,8 @@ use Mockery;
|
|||||||
|
|
||||||
class Test extends AbstractModelsCommand
|
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/GeneratePhpdocWithFqn/Models',
|
|
||||||
],
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function test(): void
|
public function test(): void
|
||||||
{
|
{
|
||||||
$actualContent = null;
|
|
||||||
$mockFilesystem = Mockery::mock(Filesystem::class);
|
|
||||||
$mockFilesystem
|
|
||||||
->shouldReceive('get')
|
|
||||||
->andReturn(file_get_contents(__DIR__ . '/Models/Post.php'))
|
|
||||||
->once();
|
|
||||||
$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);
|
$command = $this->app->make(ModelsCommand::class);
|
||||||
|
|
||||||
$tester = $this->runCommand($command, [
|
$tester = $this->runCommand($command, [
|
||||||
@@ -55,6 +25,6 @@ class Test extends AbstractModelsCommand
|
|||||||
|
|
||||||
$this->assertSame(0, $tester->getStatusCode());
|
$this->assertSame(0, $tester->getStatusCode());
|
||||||
$this->assertStringContainsString('Written new phpDocBlock to', $tester->getDisplay());
|
$this->assertStringContainsString('Written new phpDocBlock to', $tester->getDisplay());
|
||||||
$this->assertMatchesPhpSnapshot($actualContent);
|
$this->assertMatchesMockedSnapshot();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,34 +15,8 @@ use Mockery;
|
|||||||
|
|
||||||
class Test extends AbstractModelsCommand
|
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
|
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);
|
$command = $this->app->make(ModelsCommand::class);
|
||||||
|
|
||||||
$tester = $this->runCommand($command, [
|
$tester = $this->runCommand($command, [
|
||||||
@@ -51,6 +25,6 @@ class Test extends AbstractModelsCommand
|
|||||||
|
|
||||||
$this->assertSame(0, $tester->getStatusCode());
|
$this->assertSame(0, $tester->getStatusCode());
|
||||||
$this->assertStringContainsString('Model information was written to _ide_helper_models.php', $tester->getDisplay());
|
$this->assertStringContainsString('Model information was written to _ide_helper_models.php', $tester->getDisplay());
|
||||||
$this->assertMatchesPhpSnapshot($actualContent);
|
$this->assertMatchesMockedSnapshot();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,38 +11,8 @@ use Mockery;
|
|||||||
|
|
||||||
class Test extends AbstractModelsCommand
|
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/Getter/Models',
|
|
||||||
],
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function test(): void
|
public function test(): void
|
||||||
{
|
{
|
||||||
$actualContent = null;
|
|
||||||
$mockFilesystem = Mockery::mock(Filesystem::class);
|
|
||||||
$mockFilesystem
|
|
||||||
->shouldReceive('get')
|
|
||||||
->andReturn(file_get_contents(__DIR__ . '/Models/Simple.php'))
|
|
||||||
->once();
|
|
||||||
$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);
|
$command = $this->app->make(ModelsCommand::class);
|
||||||
|
|
||||||
$tester = $this->runCommand($command, [
|
$tester = $this->runCommand($command, [
|
||||||
@@ -51,6 +21,6 @@ class Test extends AbstractModelsCommand
|
|||||||
|
|
||||||
$this->assertSame(0, $tester->getStatusCode());
|
$this->assertSame(0, $tester->getStatusCode());
|
||||||
$this->assertStringContainsString('Written new phpDocBlock to', $tester->getDisplay());
|
$this->assertStringContainsString('Written new phpDocBlock to', $tester->getDisplay());
|
||||||
$this->assertMatchesPhpSnapshot($actualContent);
|
$this->assertMatchesMockedSnapshot();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,38 +16,13 @@ class Test extends AbstractModelsCommand
|
|||||||
{
|
{
|
||||||
parent::getEnvironmentSetUp($app);
|
parent::getEnvironmentSetUp($app);
|
||||||
|
|
||||||
$app['config']->set('ide-helper', [
|
$app['config']->set('ide-helper.ignored_models', [
|
||||||
'model_locations' => [
|
|
||||||
// This is calculated from the base_path() which points to
|
|
||||||
// vendor/orchestra/testbench-core/laravel
|
|
||||||
'/../../../../tests/Console/ModelsCommand/Ignored/Models',
|
|
||||||
],
|
|
||||||
'ignored_models' => [
|
|
||||||
Ignored::class
|
Ignored::class
|
||||||
]
|
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function test(): void
|
public function test(): void
|
||||||
{
|
{
|
||||||
$actualContent = null;
|
|
||||||
$mockFilesystem = Mockery::mock(Filesystem::class);
|
|
||||||
$mockFilesystem
|
|
||||||
->shouldReceive('get')
|
|
||||||
->andReturn(file_get_contents(__DIR__ . '/Models/Ignored.php'))
|
|
||||||
->andReturn(file_get_contents(__DIR__ . '/Models/NotIgnored.php'))
|
|
||||||
->once();
|
|
||||||
$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);
|
$command = $this->app->make(ModelsCommand::class);
|
||||||
|
|
||||||
$tester = $this->runCommand($command, [
|
$tester = $this->runCommand($command, [
|
||||||
@@ -56,6 +31,6 @@ class Test extends AbstractModelsCommand
|
|||||||
|
|
||||||
$this->assertSame(0, $tester->getStatusCode());
|
$this->assertSame(0, $tester->getStatusCode());
|
||||||
$this->assertStringContainsString('Written new phpDocBlock to', $tester->getDisplay());
|
$this->assertStringContainsString('Written new phpDocBlock to', $tester->getDisplay());
|
||||||
$this->assertMatchesPhpSnapshot($actualContent);
|
$this->assertMatchesMockedSnapshot();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,35 +11,8 @@ use Mockery;
|
|||||||
|
|
||||||
final class Test extends AbstractModelsCommand
|
final 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/Interfaces/Models',
|
|
||||||
],
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function test(): void
|
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);
|
$command = $this->app->make(ModelsCommand::class);
|
||||||
|
|
||||||
$tester = $this->runCommand($command, [
|
$tester = $this->runCommand($command, [
|
||||||
@@ -48,6 +21,6 @@ final class Test extends AbstractModelsCommand
|
|||||||
|
|
||||||
$this->assertSame(0, $tester->getStatusCode());
|
$this->assertSame(0, $tester->getStatusCode());
|
||||||
$this->assertStringContainsString('Model information was written to _ide_helper_models.php', $tester->getDisplay());
|
$this->assertStringContainsString('Model information was written to _ide_helper_models.php', $tester->getDisplay());
|
||||||
$this->assertMatchesPhpSnapshot($actualContent);
|
$this->assertMatchesMockedSnapshot();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,38 +22,8 @@ class Test extends AbstractModelsCommand
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function getEnvironmentSetUp($app)
|
public function test(): void
|
||||||
{
|
{
|
||||||
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/LaravelCustomCasts/Models',
|
|
||||||
],
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function test_it_parses_casted_properties_correctly(): void
|
|
||||||
{
|
|
||||||
$actualContent = null;
|
|
||||||
$mockFilesystem = Mockery::mock(Filesystem::class);
|
|
||||||
$mockFilesystem
|
|
||||||
->shouldReceive('get')
|
|
||||||
->andReturn(file_get_contents(__DIR__ . '/Models/CustomCast.php'))
|
|
||||||
->once();
|
|
||||||
$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);
|
$command = $this->app->make(ModelsCommand::class);
|
||||||
|
|
||||||
$tester = $this->runCommand($command, [
|
$tester = $this->runCommand($command, [
|
||||||
@@ -62,6 +32,6 @@ class Test extends AbstractModelsCommand
|
|||||||
|
|
||||||
$this->assertSame(0, $tester->getStatusCode());
|
$this->assertSame(0, $tester->getStatusCode());
|
||||||
$this->assertStringContainsString('Written new phpDocBlock to', $tester->getDisplay());
|
$this->assertStringContainsString('Written new phpDocBlock to', $tester->getDisplay());
|
||||||
$this->assertMatchesPhpSnapshot($actualContent);
|
$this->assertMatchesMockedSnapshot();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,35 +15,11 @@ class Test extends AbstractModelsCommand
|
|||||||
{
|
{
|
||||||
parent::getEnvironmentSetUp($app);
|
parent::getEnvironmentSetUp($app);
|
||||||
|
|
||||||
$app['config']->set('ide-helper', [
|
$app['config']->set('ide-helper.write_model_magic_where', false);
|
||||||
'model_locations' => [
|
|
||||||
// This is calculated from the base_path() which points to
|
|
||||||
// vendor/orchestra/testbench-core/laravel
|
|
||||||
'/../../../../tests/Console/ModelsCommand/MagicWhere/Models',
|
|
||||||
],
|
|
||||||
'write_model_magic_where' => false
|
|
||||||
]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function test(): void
|
public function test(): void
|
||||||
{
|
{
|
||||||
$actualContent = null;
|
|
||||||
$mockFilesystem = Mockery::mock(Filesystem::class);
|
|
||||||
$mockFilesystem
|
|
||||||
->shouldReceive('get')
|
|
||||||
->andReturn(file_get_contents(__DIR__ . '/Models/Post.php'))
|
|
||||||
->once();
|
|
||||||
$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);
|
$command = $this->app->make(ModelsCommand::class);
|
||||||
|
|
||||||
$tester = $this->runCommand($command, [
|
$tester = $this->runCommand($command, [
|
||||||
@@ -52,6 +28,6 @@ class Test extends AbstractModelsCommand
|
|||||||
|
|
||||||
$this->assertSame(0, $tester->getStatusCode());
|
$this->assertSame(0, $tester->getStatusCode());
|
||||||
$this->assertStringContainsString('Written new phpDocBlock to', $tester->getDisplay());
|
$this->assertStringContainsString('Written new phpDocBlock to', $tester->getDisplay());
|
||||||
$this->assertMatchesPhpSnapshot($actualContent);
|
$this->assertMatchesMockedSnapshot();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,38 +13,8 @@ use function file_get_contents;
|
|||||||
|
|
||||||
class Test extends AbstractModelsCommand
|
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/PHPStormNoInspection/Models',
|
|
||||||
],
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testNoinspectionNotPresent(): void
|
public function testNoinspectionNotPresent(): void
|
||||||
{
|
{
|
||||||
$actualContent = null;
|
|
||||||
$mockFilesystem = Mockery::mock(Filesystem::class);
|
|
||||||
$mockFilesystem
|
|
||||||
->shouldReceive('get')
|
|
||||||
->andReturn(file_get_contents(__DIR__ . '/Models/Simple.php'))
|
|
||||||
->once();
|
|
||||||
$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);
|
$command = $this->app->make(ModelsCommand::class);
|
||||||
|
|
||||||
$tester = $this->runCommand($command, [
|
$tester = $this->runCommand($command, [
|
||||||
@@ -53,28 +23,11 @@ class Test extends AbstractModelsCommand
|
|||||||
|
|
||||||
$this->assertSame(0, $tester->getStatusCode());
|
$this->assertSame(0, $tester->getStatusCode());
|
||||||
$this->assertStringContainsString('Written new phpDocBlock to', $tester->getDisplay());
|
$this->assertStringContainsString('Written new phpDocBlock to', $tester->getDisplay());
|
||||||
$this->assertMatchesPhpSnapshot($actualContent);
|
$this->assertMatchesMockedSnapshot();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testNoinspectionPresent(): void
|
public function testNoinspectionPresent(): void
|
||||||
{
|
{
|
||||||
$actualContent = null;
|
|
||||||
$mockFilesystem = Mockery::mock(Filesystem::class);
|
|
||||||
$mockFilesystem
|
|
||||||
->shouldReceive('get')
|
|
||||||
->andReturn(file_get_contents(__DIR__ . '/Models/Simple.php'))
|
|
||||||
->once();
|
|
||||||
$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);
|
$command = $this->app->make(ModelsCommand::class);
|
||||||
|
|
||||||
$tester = $this->runCommand($command, [
|
$tester = $this->runCommand($command, [
|
||||||
@@ -84,6 +37,6 @@ class Test extends AbstractModelsCommand
|
|||||||
|
|
||||||
$this->assertSame(0, $tester->getStatusCode());
|
$this->assertSame(0, $tester->getStatusCode());
|
||||||
$this->assertStringContainsString('Written new phpDocBlock to', $tester->getDisplay());
|
$this->assertStringContainsString('Written new phpDocBlock to', $tester->getDisplay());
|
||||||
$this->assertMatchesPhpSnapshot($actualContent);
|
$this->assertMatchesMockedSnapshot();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,35 +17,11 @@ class Test extends AbstractModelsCommand
|
|||||||
{
|
{
|
||||||
parent::getEnvironmentSetUp($app);
|
parent::getEnvironmentSetUp($app);
|
||||||
|
|
||||||
$app['config']->set('ide-helper', [
|
$app['config']->set('ide-helper.write_model_relation_count_properties', false);
|
||||||
'model_locations' => [
|
|
||||||
// This is calculated from the base_path() which points to
|
|
||||||
// vendor/orchestra/testbench-core/laravel
|
|
||||||
'/../../../../tests/Console/ModelsCommand/RelationCountProperties/Models',
|
|
||||||
],
|
|
||||||
'write_model_relation_count_properties' => false
|
|
||||||
]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function test(): void
|
public function test(): void
|
||||||
{
|
{
|
||||||
$actualContent = null;
|
|
||||||
$mockFilesystem = Mockery::mock(Filesystem::class);
|
|
||||||
$mockFilesystem
|
|
||||||
->shouldReceive('get')
|
|
||||||
->andReturn(file_get_contents(__DIR__ . '/Models/Post.php'))
|
|
||||||
->once();
|
|
||||||
$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);
|
$command = $this->app->make(ModelsCommand::class);
|
||||||
|
|
||||||
$tester = $this->runCommand($command, [
|
$tester = $this->runCommand($command, [
|
||||||
@@ -54,6 +30,6 @@ class Test extends AbstractModelsCommand
|
|||||||
|
|
||||||
$this->assertSame(0, $tester->getStatusCode());
|
$this->assertSame(0, $tester->getStatusCode());
|
||||||
$this->assertStringContainsString('Written new phpDocBlock to', $tester->getDisplay());
|
$this->assertStringContainsString('Written new phpDocBlock to', $tester->getDisplay());
|
||||||
$this->assertMatchesPhpSnapshot($actualContent);
|
$this->assertMatchesMockedSnapshot();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,38 +11,8 @@ use Mockery;
|
|||||||
|
|
||||||
class Test extends AbstractModelsCommand
|
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/Relations/Models',
|
|
||||||
],
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function test(): void
|
public function test(): void
|
||||||
{
|
{
|
||||||
$actualContent = null;
|
|
||||||
$mockFilesystem = Mockery::mock(Filesystem::class);
|
|
||||||
$mockFilesystem
|
|
||||||
->shouldReceive('get')
|
|
||||||
->andReturn(file_get_contents(__DIR__ . '/Models/Simple.php'))
|
|
||||||
->once();
|
|
||||||
$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);
|
$command = $this->app->make(ModelsCommand::class);
|
||||||
|
|
||||||
$tester = $this->runCommand($command, [
|
$tester = $this->runCommand($command, [
|
||||||
@@ -51,6 +21,6 @@ class Test extends AbstractModelsCommand
|
|||||||
|
|
||||||
$this->assertSame(0, $tester->getStatusCode());
|
$this->assertSame(0, $tester->getStatusCode());
|
||||||
$this->assertStringContainsString('Written new phpDocBlock to', $tester->getDisplay());
|
$this->assertStringContainsString('Written new phpDocBlock to', $tester->getDisplay());
|
||||||
$this->assertMatchesPhpSnapshot($actualContent);
|
$this->assertMatchesMockedSnapshot();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,38 +11,8 @@ use Mockery;
|
|||||||
|
|
||||||
class Test extends AbstractModelsCommand
|
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/ResetAndSmartReset/Models',
|
|
||||||
],
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testNoReset(): void
|
public function testNoReset(): void
|
||||||
{
|
{
|
||||||
$actualContent = null;
|
|
||||||
$mockFilesystem = Mockery::mock(Filesystem::class);
|
|
||||||
$mockFilesystem
|
|
||||||
->shouldReceive('get')
|
|
||||||
->andReturn(file_get_contents(__DIR__ . '/Models/Simple.php'))
|
|
||||||
->once();
|
|
||||||
$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);
|
$command = $this->app->make(ModelsCommand::class);
|
||||||
|
|
||||||
$tester = $this->runCommand($command, [
|
$tester = $this->runCommand($command, [
|
||||||
@@ -51,28 +21,11 @@ class Test extends AbstractModelsCommand
|
|||||||
|
|
||||||
$this->assertSame(0, $tester->getStatusCode());
|
$this->assertSame(0, $tester->getStatusCode());
|
||||||
$this->assertStringContainsString('Written new phpDocBlock to', $tester->getDisplay());
|
$this->assertStringContainsString('Written new phpDocBlock to', $tester->getDisplay());
|
||||||
$this->assertMatchesPhpSnapshot($actualContent);
|
$this->assertMatchesMockedSnapshot();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testReset(): void
|
public function testReset(): void
|
||||||
{
|
{
|
||||||
$actualContent = null;
|
|
||||||
$mockFilesystem = Mockery::mock(Filesystem::class);
|
|
||||||
$mockFilesystem
|
|
||||||
->shouldReceive('get')
|
|
||||||
->andReturn(file_get_contents(__DIR__ . '/Models/Simple.php'))
|
|
||||||
->once();
|
|
||||||
$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);
|
$command = $this->app->make(ModelsCommand::class);
|
||||||
|
|
||||||
$tester = $this->runCommand($command, [
|
$tester = $this->runCommand($command, [
|
||||||
@@ -82,28 +35,11 @@ class Test extends AbstractModelsCommand
|
|||||||
|
|
||||||
$this->assertSame(0, $tester->getStatusCode());
|
$this->assertSame(0, $tester->getStatusCode());
|
||||||
$this->assertStringContainsString('Written new phpDocBlock to', $tester->getDisplay());
|
$this->assertStringContainsString('Written new phpDocBlock to', $tester->getDisplay());
|
||||||
$this->assertMatchesPhpSnapshot($actualContent);
|
$this->assertMatchesMockedSnapshot();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testSmartReset(): void
|
public function testSmartReset(): void
|
||||||
{
|
{
|
||||||
$actualContent = null;
|
|
||||||
$mockFilesystem = Mockery::mock(Filesystem::class);
|
|
||||||
$mockFilesystem
|
|
||||||
->shouldReceive('get')
|
|
||||||
->andReturn(file_get_contents(__DIR__ . '/Models/Simple.php'))
|
|
||||||
->once();
|
|
||||||
$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);
|
$command = $this->app->make(ModelsCommand::class);
|
||||||
|
|
||||||
$tester = $this->runCommand($command, [
|
$tester = $this->runCommand($command, [
|
||||||
@@ -113,6 +49,6 @@ class Test extends AbstractModelsCommand
|
|||||||
|
|
||||||
$this->assertSame(0, $tester->getStatusCode());
|
$this->assertSame(0, $tester->getStatusCode());
|
||||||
$this->assertStringContainsString('Written new phpDocBlock to', $tester->getDisplay());
|
$this->assertStringContainsString('Written new phpDocBlock to', $tester->getDisplay());
|
||||||
$this->assertMatchesPhpSnapshot($actualContent);
|
$this->assertMatchesMockedSnapshot();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,38 +11,8 @@ use Mockery;
|
|||||||
|
|
||||||
class Test extends AbstractModelsCommand
|
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/SoftDeletes/Models',
|
|
||||||
],
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function test(): void
|
public function test(): void
|
||||||
{
|
{
|
||||||
$actualContent = null;
|
|
||||||
$mockFilesystem = Mockery::mock(Filesystem::class);
|
|
||||||
$mockFilesystem
|
|
||||||
->shouldReceive('get')
|
|
||||||
->andReturn(file_get_contents(__DIR__ . '/Models/Simple.php'))
|
|
||||||
->once();
|
|
||||||
$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);
|
$command = $this->app->make(ModelsCommand::class);
|
||||||
|
|
||||||
$tester = $this->runCommand($command, [
|
$tester = $this->runCommand($command, [
|
||||||
@@ -51,6 +21,6 @@ class Test extends AbstractModelsCommand
|
|||||||
|
|
||||||
$this->assertSame(0, $tester->getStatusCode());
|
$this->assertSame(0, $tester->getStatusCode());
|
||||||
$this->assertStringContainsString('Written new phpDocBlock to', $tester->getDisplay());
|
$this->assertStringContainsString('Written new phpDocBlock to', $tester->getDisplay());
|
||||||
$this->assertMatchesPhpSnapshot($actualContent);
|
$this->assertMatchesMockedSnapshot();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user