diff --git a/tests/Console/ModelsCommand/AbstractModelsCommand.php b/tests/Console/ModelsCommand/AbstractModelsCommand.php new file mode 100644 index 0000000..4ea52ef --- /dev/null +++ b/tests/Console/ModelsCommand/AbstractModelsCommand.php @@ -0,0 +1,37 @@ +markTestSkipped('This test requires Laravel 6.0 or higher'); + return; + } + + $this->loadMigrationsFrom(__DIR__ . '/migrations'); + $this->artisan('migrate'); + } + + protected function getEnvironmentSetUp($app) + { + parent::getEnvironmentSetUp($app); + + $config = $app['config']; + + $config->set('database.default', 'sqlite'); + $config->set('database.connections.sqlite', [ + 'driver' => 'sqlite', + 'database' => ':memory:', + 'prefix' => '', + ]); + } +} diff --git a/tests/Console/ModelsCommand/CustomDate/Models/CustomDate.php b/tests/Console/ModelsCommand/CustomDate/Models/CustomDate.php new file mode 100644 index 0000000..615afb7 --- /dev/null +++ b/tests/Console/ModelsCommand/CustomDate/Models/CustomDate.php @@ -0,0 +1,9 @@ +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, [ + '--write' => true, + ]); + + $this->assertSame(0, $tester->getStatusCode()); + $this->assertEmpty($tester->getDisplay()); + + $expectedContent = <<<'PHP' +assertSame($expectedContent, $actualContent); + } +} diff --git a/tests/Console/ModelsCommand/GenerateBasicPhpdoc/Models/Post.php b/tests/Console/ModelsCommand/GenerateBasicPhpdoc/Models/Post.php new file mode 100644 index 0000000..3800e3d --- /dev/null +++ b/tests/Console/ModelsCommand/GenerateBasicPhpdoc/Models/Post.php @@ -0,0 +1,9 @@ +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, [ + '--write' => true, + ]); + + $this->assertSame(0, $tester->getStatusCode()); + $this->assertEmpty($tester->getDisplay()); + + $expectedContent = <<<'PHP' +assertSame($expectedContent, $actualContent); + } +} diff --git a/tests/Console/ModelsCommand/migrations/____custom_dates_table.php b/tests/Console/ModelsCommand/migrations/____custom_dates_table.php new file mode 100644 index 0000000..cf421fd --- /dev/null +++ b/tests/Console/ModelsCommand/migrations/____custom_dates_table.php @@ -0,0 +1,15 @@ +timestamps(); + }); + } +} diff --git a/tests/Console/ModelsCommand/migrations/____posts_table.php b/tests/Console/ModelsCommand/migrations/____posts_table.php new file mode 100644 index 0000000..81fb89c --- /dev/null +++ b/tests/Console/ModelsCommand/migrations/____posts_table.php @@ -0,0 +1,20 @@ +bigIncrements('id'); + $table->string('title'); + $table->string('body')->nullable(); + $table->boolean('visible')->default('true'); + $table->timestampTz('publicated_at'); + $table->timestamps(); + }); + } +}