diff --git a/tests/Commands/GeneratorCommandTest.php b/tests/Commands/GeneratorCommandTest.php index d6310f9..4c71938 100644 --- a/tests/Commands/GeneratorCommandTest.php +++ b/tests/Commands/GeneratorCommandTest.php @@ -34,4 +34,28 @@ public function it_cannot_generate_class_file_given_reserved_name() ->expectsOutputToContain('The name "__halt_compiler" is reserved by PHP.') ->assertFailed(); } + + /** @test */ + public function it_cannot_generate_class_file_when_file_already_exist() + { + file_put_contents(base_path('app/Value/Foo.php'), 'artisan('make:code', ['name' => 'Value/Foo']) + ->expectsOutputToContain('class [app/Value/Foo.php] already exists!') + ->assertFailed(); + } + + /** @test */ + public function it_can_generate_class_file_when_file_already_exist_using_force_option() + { + file_put_contents(base_path('app/Value/Foo.php'), 'artisan('make:code', ['name' => 'Value/Foo', '--force' => true]) + ->assertSuccessful(); + + $this->assertFileContains([ + 'namespace App\Value;', + 'class Foo', + ], 'app/Value/Foo.php'); + } } diff --git a/tests/PresetManagerTest.php b/tests/PresetManagerTest.php index 9104f9b..13074fb 100644 --- a/tests/PresetManagerTest.php +++ b/tests/PresetManagerTest.php @@ -2,6 +2,7 @@ namespace Orchestra\Canvas\Core\Tests; +use Illuminate\Support\Manager; use Orchestra\Canvas\Core\PresetManager; use Orchestra\Testbench\TestCase; @@ -12,6 +13,7 @@ public function it_can_be_resolved() { $manager = $this->app[PresetManager::class]; + $this->assertInstanceOf(Manager::class, $manager); $this->assertSame('laravel', $manager->getDefaultDriver()); } diff --git a/workbench/app/Console/CodeGeneratorCommand.php b/workbench/app/Console/CodeGeneratorCommand.php index 41c444e..762bdd6 100644 --- a/workbench/app/Console/CodeGeneratorCommand.php +++ b/workbench/app/Console/CodeGeneratorCommand.php @@ -3,7 +3,7 @@ namespace Workbench\App\Console; use Orchestra\Canvas\Core\Commands\GeneratorCommand; -use Orchestra\Canvas\Core\Concerns\ResolvesPresetStubs; +use Symfony\Component\Console\Input\InputOption; class CodeGeneratorCommand extends GeneratorCommand { @@ -37,4 +37,16 @@ protected function getStub() { return __DIR__.'/stubs/class.stub'; } + + /** + * Get the console command arguments. + * + * @return array + */ + protected function getOptions() + { + return [ + ['force', 'f', InputOption::VALUE_NONE, 'Create the class even if the cast already exists'], + ]; + } }