diff --git a/src/Console/ModelsCommand.php b/src/Console/ModelsCommand.php index a7e8081..b56e6a2 100644 --- a/src/Console/ModelsCommand.php +++ b/src/Console/ModelsCommand.php @@ -97,7 +97,7 @@ class ModelsCommand extends Command $filename = $this->option('filename'); $this->write = $this->option('write'); $this->dirs = array_merge( - $this->laravel['config']->get('ide-helper.model_locations'), + $this->laravel['config']->get('ide-helper.model_locations', []), $this->option('dir') ); $model = $this->argument('model'); @@ -272,7 +272,15 @@ class ModelsCommand extends Command { $models = array(); 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); foreach ($dirs as $dir) { if (file_exists($dir)) { diff --git a/tests/Console/ModelsCommand/AbstractModelsCommand.php b/tests/Console/ModelsCommand/AbstractModelsCommand.php index d2fce45..1a9c1c3 100644 --- a/tests/Console/ModelsCommand/AbstractModelsCommand.php +++ b/tests/Console/ModelsCommand/AbstractModelsCommand.php @@ -4,11 +4,18 @@ declare(strict_types=1); 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 Illuminate\Filesystem\Filesystem; use Illuminate\Foundation\Application; +use Mockery; abstract class AbstractModelsCommand extends TestCase { + protected $mockFilesystemOutput; + protected function setUp(): void { parent::setUp(); @@ -21,6 +28,22 @@ abstract class AbstractModelsCommand extends TestCase $this->loadMigrationsFrom(__DIR__ . '/migrations'); $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) @@ -35,5 +58,45 @@ abstract class AbstractModelsCommand extends TestCase 'database' => ':memory:', '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()); } } diff --git a/tests/Console/ModelsCommand/CustomCollection/Test.php b/tests/Console/ModelsCommand/CustomCollection/Test.php index fc5e98b..ee8c145 100644 --- a/tests/Console/ModelsCommand/CustomCollection/Test.php +++ b/tests/Console/ModelsCommand/CustomCollection/Test.php @@ -12,38 +12,8 @@ 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/CustomCollection/Models', - ], - ]); - } - 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); $tester = $this->runCommand($command, [ @@ -52,6 +22,6 @@ class Test extends AbstractModelsCommand $this->assertSame(0, $tester->getStatusCode()); $this->assertStringContainsString('Written new phpDocBlock to', $tester->getDisplay()); - $this->assertMatchesPhpSnapshot($actualContent); + $this->assertMatchesMockedSnapshot(); } } diff --git a/tests/Console/ModelsCommand/CustomDate/Test.php b/tests/Console/ModelsCommand/CustomDate/Test.php index b378df1..23934ba 100644 --- a/tests/Console/ModelsCommand/CustomDate/Test.php +++ b/tests/Console/ModelsCommand/CustomDate/Test.php @@ -28,38 +28,8 @@ class Test extends AbstractModelsCommand 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 { - $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); $tester = $this->runCommand($command, [ @@ -68,6 +38,6 @@ class Test extends AbstractModelsCommand $this->assertSame(0, $tester->getStatusCode()); $this->assertStringContainsString('Written new phpDocBlock to', $tester->getDisplay()); - $this->assertMatchesPhpSnapshot($actualContent); + $this->assertMatchesMockedSnapshot(); } } diff --git a/tests/Console/ModelsCommand/DynamicRelations/Test.php b/tests/Console/ModelsCommand/DynamicRelations/Test.php index 5cf1023..36e0b45 100644 --- a/tests/Console/ModelsCommand/DynamicRelations/Test.php +++ b/tests/Console/ModelsCommand/DynamicRelations/Test.php @@ -6,43 +6,11 @@ namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\DynamicRelations use Barryvdh\LaravelIdeHelper\Console\ModelsCommand; use Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\AbstractModelsCommand; -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/DynamicRelations/Models', - ], - ]); - } - 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); $tester = $this->runCommand($command, [ @@ -51,6 +19,6 @@ class Test extends AbstractModelsCommand $this->assertSame(0, $tester->getStatusCode()); $this->assertStringContainsString('Written new phpDocBlock to', $tester->getDisplay()); - $this->assertMatchesPhpSnapshot($actualContent); + $this->assertMatchesMockedSnapshot(); } } diff --git a/tests/Console/ModelsCommand/GenerateBasicPhpdoc/Test.php b/tests/Console/ModelsCommand/GenerateBasicPhpdoc/Test.php index 72ff210..02b9a5f 100644 --- a/tests/Console/ModelsCommand/GenerateBasicPhpdoc/Test.php +++ b/tests/Console/ModelsCommand/GenerateBasicPhpdoc/Test.php @@ -11,38 +11,8 @@ 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/GenerateBasicPhpdoc/Models', - ], - ]); - } - 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); $tester = $this->runCommand($command, [ @@ -51,6 +21,6 @@ class Test extends AbstractModelsCommand $this->assertSame(0, $tester->getStatusCode()); $this->assertStringContainsString('Written new phpDocBlock to', $tester->getDisplay()); - $this->assertMatchesPhpSnapshot($actualContent); + $this->assertMatchesMockedSnapshot(); } } diff --git a/tests/Console/ModelsCommand/GenerateBasicPhpdocCamel/Test.php b/tests/Console/ModelsCommand/GenerateBasicPhpdocCamel/Test.php index b43318f..4f86407 100644 --- a/tests/Console/ModelsCommand/GenerateBasicPhpdocCamel/Test.php +++ b/tests/Console/ModelsCommand/GenerateBasicPhpdocCamel/Test.php @@ -15,36 +15,11 @@ class Test extends AbstractModelsCommand { 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/GenerateBasicPhpdocCamel/Models', - ], - // Activate the camel_case mode - 'model_camel_case_properties' => true, - ]); + $app['config']->set('ide-helper.model_camel_case_properties', true); } 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); $tester = $this->runCommand($command, [ @@ -53,6 +28,6 @@ class Test extends AbstractModelsCommand $this->assertSame(0, $tester->getStatusCode()); $this->assertStringContainsString('Written new phpDocBlock to', $tester->getDisplay()); - $this->assertMatchesPhpSnapshot($actualContent); + $this->assertMatchesMockedSnapshot(); } } diff --git a/tests/Console/ModelsCommand/GenerateBasicPhpdocFinal/Test.php b/tests/Console/ModelsCommand/GenerateBasicPhpdocFinal/Test.php index d162bf8..8aa174b 100644 --- a/tests/Console/ModelsCommand/GenerateBasicPhpdocFinal/Test.php +++ b/tests/Console/ModelsCommand/GenerateBasicPhpdocFinal/Test.php @@ -11,38 +11,8 @@ 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/GenerateBasicPhpdocFinal/Models', - ], - ]); - } - 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); $tester = $this->runCommand($command, [ @@ -51,6 +21,6 @@ class Test extends AbstractModelsCommand $this->assertSame(0, $tester->getStatusCode()); $this->assertStringContainsString('Written new phpDocBlock to', $tester->getDisplay()); - $this->assertMatchesPhpSnapshot($actualContent); + $this->assertMatchesMockedSnapshot(); } } diff --git a/tests/Console/ModelsCommand/GeneratePhpdocWithFqn/Test.php b/tests/Console/ModelsCommand/GeneratePhpdocWithFqn/Test.php index aa33da2..83532e3 100644 --- a/tests/Console/ModelsCommand/GeneratePhpdocWithFqn/Test.php +++ b/tests/Console/ModelsCommand/GeneratePhpdocWithFqn/Test.php @@ -15,38 +15,8 @@ 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/GeneratePhpdocWithFqn/Models', - ], - ]); - } - 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); $tester = $this->runCommand($command, [ @@ -55,6 +25,6 @@ class Test extends AbstractModelsCommand $this->assertSame(0, $tester->getStatusCode()); $this->assertStringContainsString('Written new phpDocBlock to', $tester->getDisplay()); - $this->assertMatchesPhpSnapshot($actualContent); + $this->assertMatchesMockedSnapshot(); } } diff --git a/tests/Console/ModelsCommand/GeneratePhpdocWithFqnInExternalFile/Test.php b/tests/Console/ModelsCommand/GeneratePhpdocWithFqnInExternalFile/Test.php index 3742a05..d02e0a4 100644 --- a/tests/Console/ModelsCommand/GeneratePhpdocWithFqnInExternalFile/Test.php +++ b/tests/Console/ModelsCommand/GeneratePhpdocWithFqnInExternalFile/Test.php @@ -15,34 +15,8 @@ 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, [ @@ -51,6 +25,6 @@ class Test extends AbstractModelsCommand $this->assertSame(0, $tester->getStatusCode()); $this->assertStringContainsString('Model information was written to _ide_helper_models.php', $tester->getDisplay()); - $this->assertMatchesPhpSnapshot($actualContent); + $this->assertMatchesMockedSnapshot(); } } diff --git a/tests/Console/ModelsCommand/Getter/Test.php b/tests/Console/ModelsCommand/Getter/Test.php index 4f7e7f9..224b69c 100644 --- a/tests/Console/ModelsCommand/Getter/Test.php +++ b/tests/Console/ModelsCommand/Getter/Test.php @@ -11,38 +11,8 @@ 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/Getter/Models', - ], - ]); - } - 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); $tester = $this->runCommand($command, [ @@ -51,6 +21,6 @@ class Test extends AbstractModelsCommand $this->assertSame(0, $tester->getStatusCode()); $this->assertStringContainsString('Written new phpDocBlock to', $tester->getDisplay()); - $this->assertMatchesPhpSnapshot($actualContent); + $this->assertMatchesMockedSnapshot(); } } diff --git a/tests/Console/ModelsCommand/Ignored/Test.php b/tests/Console/ModelsCommand/Ignored/Test.php index 7c2f58e..d5c3c6b 100644 --- a/tests/Console/ModelsCommand/Ignored/Test.php +++ b/tests/Console/ModelsCommand/Ignored/Test.php @@ -16,38 +16,13 @@ class Test extends AbstractModelsCommand { 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/Ignored/Models', - ], - 'ignored_models' => [ - Ignored::class - ] + $app['config']->set('ide-helper.ignored_models', [ + Ignored::class ]); } 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); $tester = $this->runCommand($command, [ @@ -56,6 +31,6 @@ class Test extends AbstractModelsCommand $this->assertSame(0, $tester->getStatusCode()); $this->assertStringContainsString('Written new phpDocBlock to', $tester->getDisplay()); - $this->assertMatchesPhpSnapshot($actualContent); + $this->assertMatchesMockedSnapshot(); } } diff --git a/tests/Console/ModelsCommand/Interfaces/Test.php b/tests/Console/ModelsCommand/Interfaces/Test.php index 043e765..8ab7df6 100644 --- a/tests/Console/ModelsCommand/Interfaces/Test.php +++ b/tests/Console/ModelsCommand/Interfaces/Test.php @@ -11,35 +11,8 @@ use Mockery; 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 { - $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, [ @@ -48,6 +21,6 @@ final class Test extends AbstractModelsCommand $this->assertSame(0, $tester->getStatusCode()); $this->assertStringContainsString('Model information was written to _ide_helper_models.php', $tester->getDisplay()); - $this->assertMatchesPhpSnapshot($actualContent); + $this->assertMatchesMockedSnapshot(); } } diff --git a/tests/Console/ModelsCommand/LaravelCustomCasts/Test.php b/tests/Console/ModelsCommand/LaravelCustomCasts/Test.php index e8baa7a..522d887 100644 --- a/tests/Console/ModelsCommand/LaravelCustomCasts/Test.php +++ b/tests/Console/ModelsCommand/LaravelCustomCasts/Test.php @@ -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); $tester = $this->runCommand($command, [ @@ -62,6 +32,6 @@ class Test extends AbstractModelsCommand $this->assertSame(0, $tester->getStatusCode()); $this->assertStringContainsString('Written new phpDocBlock to', $tester->getDisplay()); - $this->assertMatchesPhpSnapshot($actualContent); + $this->assertMatchesMockedSnapshot(); } } diff --git a/tests/Console/ModelsCommand/LaravelCustomCasts/__snapshots__/Test__test_it_parses_casted_properties_correctly__1.php b/tests/Console/ModelsCommand/LaravelCustomCasts/__snapshots__/Test__test__1.php similarity index 100% rename from tests/Console/ModelsCommand/LaravelCustomCasts/__snapshots__/Test__test_it_parses_casted_properties_correctly__1.php rename to tests/Console/ModelsCommand/LaravelCustomCasts/__snapshots__/Test__test__1.php diff --git a/tests/Console/ModelsCommand/MagicWhere/Test.php b/tests/Console/ModelsCommand/MagicWhere/Test.php index d996cfb..4bf7617 100644 --- a/tests/Console/ModelsCommand/MagicWhere/Test.php +++ b/tests/Console/ModelsCommand/MagicWhere/Test.php @@ -15,35 +15,11 @@ class Test extends AbstractModelsCommand { 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/MagicWhere/Models', - ], - 'write_model_magic_where' => false - ]); + $app['config']->set('ide-helper.write_model_magic_where', false); } 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); $tester = $this->runCommand($command, [ @@ -52,6 +28,6 @@ class Test extends AbstractModelsCommand $this->assertSame(0, $tester->getStatusCode()); $this->assertStringContainsString('Written new phpDocBlock to', $tester->getDisplay()); - $this->assertMatchesPhpSnapshot($actualContent); + $this->assertMatchesMockedSnapshot(); } } diff --git a/tests/Console/ModelsCommand/PHPStormNoInspection/Test.php b/tests/Console/ModelsCommand/PHPStormNoInspection/Test.php index fc32a7d..4ec27d7 100644 --- a/tests/Console/ModelsCommand/PHPStormNoInspection/Test.php +++ b/tests/Console/ModelsCommand/PHPStormNoInspection/Test.php @@ -13,38 +13,8 @@ use function file_get_contents; 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 { - $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); $tester = $this->runCommand($command, [ @@ -53,28 +23,11 @@ class Test extends AbstractModelsCommand $this->assertSame(0, $tester->getStatusCode()); $this->assertStringContainsString('Written new phpDocBlock to', $tester->getDisplay()); - $this->assertMatchesPhpSnapshot($actualContent); + $this->assertMatchesMockedSnapshot(); } 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); $tester = $this->runCommand($command, [ @@ -84,6 +37,6 @@ class Test extends AbstractModelsCommand $this->assertSame(0, $tester->getStatusCode()); $this->assertStringContainsString('Written new phpDocBlock to', $tester->getDisplay()); - $this->assertMatchesPhpSnapshot($actualContent); + $this->assertMatchesMockedSnapshot(); } } diff --git a/tests/Console/ModelsCommand/RelationCountProperties/Test.php b/tests/Console/ModelsCommand/RelationCountProperties/Test.php index 1e923b0..ba6a43e 100644 --- a/tests/Console/ModelsCommand/RelationCountProperties/Test.php +++ b/tests/Console/ModelsCommand/RelationCountProperties/Test.php @@ -17,35 +17,11 @@ class Test extends AbstractModelsCommand { 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/RelationCountProperties/Models', - ], - 'write_model_relation_count_properties' => false - ]); + $app['config']->set('ide-helper.write_model_relation_count_properties', false); } 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); $tester = $this->runCommand($command, [ @@ -54,6 +30,6 @@ class Test extends AbstractModelsCommand $this->assertSame(0, $tester->getStatusCode()); $this->assertStringContainsString('Written new phpDocBlock to', $tester->getDisplay()); - $this->assertMatchesPhpSnapshot($actualContent); + $this->assertMatchesMockedSnapshot(); } } diff --git a/tests/Console/ModelsCommand/Relations/Test.php b/tests/Console/ModelsCommand/Relations/Test.php index 6e6b5b8..aa0ee5b 100644 --- a/tests/Console/ModelsCommand/Relations/Test.php +++ b/tests/Console/ModelsCommand/Relations/Test.php @@ -11,38 +11,8 @@ 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/Relations/Models', - ], - ]); - } - 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); $tester = $this->runCommand($command, [ @@ -51,6 +21,6 @@ class Test extends AbstractModelsCommand $this->assertSame(0, $tester->getStatusCode()); $this->assertStringContainsString('Written new phpDocBlock to', $tester->getDisplay()); - $this->assertMatchesPhpSnapshot($actualContent); + $this->assertMatchesMockedSnapshot(); } } diff --git a/tests/Console/ModelsCommand/ResetAndSmartReset/Test.php b/tests/Console/ModelsCommand/ResetAndSmartReset/Test.php index 7876b10..74c3181 100644 --- a/tests/Console/ModelsCommand/ResetAndSmartReset/Test.php +++ b/tests/Console/ModelsCommand/ResetAndSmartReset/Test.php @@ -11,38 +11,8 @@ 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/ResetAndSmartReset/Models', - ], - ]); - } - 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); $tester = $this->runCommand($command, [ @@ -51,28 +21,11 @@ class Test extends AbstractModelsCommand $this->assertSame(0, $tester->getStatusCode()); $this->assertStringContainsString('Written new phpDocBlock to', $tester->getDisplay()); - $this->assertMatchesPhpSnapshot($actualContent); + $this->assertMatchesMockedSnapshot(); } 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); $tester = $this->runCommand($command, [ @@ -82,28 +35,11 @@ class Test extends AbstractModelsCommand $this->assertSame(0, $tester->getStatusCode()); $this->assertStringContainsString('Written new phpDocBlock to', $tester->getDisplay()); - $this->assertMatchesPhpSnapshot($actualContent); + $this->assertMatchesMockedSnapshot(); } 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); $tester = $this->runCommand($command, [ @@ -113,6 +49,6 @@ class Test extends AbstractModelsCommand $this->assertSame(0, $tester->getStatusCode()); $this->assertStringContainsString('Written new phpDocBlock to', $tester->getDisplay()); - $this->assertMatchesPhpSnapshot($actualContent); + $this->assertMatchesMockedSnapshot(); } } diff --git a/tests/Console/ModelsCommand/SoftDeletes/Test.php b/tests/Console/ModelsCommand/SoftDeletes/Test.php index 578f0cb..eb5e401 100644 --- a/tests/Console/ModelsCommand/SoftDeletes/Test.php +++ b/tests/Console/ModelsCommand/SoftDeletes/Test.php @@ -11,38 +11,8 @@ 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/SoftDeletes/Models', - ], - ]); - } - 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); $tester = $this->runCommand($command, [ @@ -51,6 +21,6 @@ class Test extends AbstractModelsCommand $this->assertSame(0, $tester->getStatusCode()); $this->assertStringContainsString('Written new phpDocBlock to', $tester->getDisplay()); - $this->assertMatchesPhpSnapshot($actualContent); + $this->assertMatchesMockedSnapshot(); } }