Skip to content

Commit d2ea00c

Browse files
committed
wip
Signed-off-by: Mior Muhammad Zaki <[email protected]>
1 parent 766f9ba commit d2ea00c

File tree

3 files changed

+39
-1
lines changed

3 files changed

+39
-1
lines changed

tests/Commands/GeneratorCommandTest.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,28 @@ public function it_cannot_generate_class_file_given_reserved_name()
3434
->expectsOutputToContain('The name "__halt_compiler" is reserved by PHP.')
3535
->assertFailed();
3636
}
37+
38+
/** @test */
39+
public function it_cannot_generate_class_file_when_file_already_exist()
40+
{
41+
file_put_contents(base_path('app/Value/Foo.php'), '<?php '.PHP_EOL);
42+
43+
$this->artisan('make:code', ['name' => 'Value/Foo'])
44+
->expectsOutputToContain('class [app/Value/Foo.php] already exists!')
45+
->assertFailed();
46+
}
47+
48+
/** @test */
49+
public function it_can_generate_class_file_when_file_already_exist_using_force_option()
50+
{
51+
file_put_contents(base_path('app/Value/Foo.php'), '<?php '.PHP_EOL);
52+
53+
$this->artisan('make:code', ['name' => 'Value/Foo', '--force' => true])
54+
->assertSuccessful();
55+
56+
$this->assertFileContains([
57+
'namespace App\Value;',
58+
'class Foo',
59+
], 'app/Value/Foo.php');
60+
}
3761
}

tests/PresetManagerTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Orchestra\Canvas\Core\Tests;
44

5+
use Illuminate\Support\Manager;
56
use Orchestra\Canvas\Core\PresetManager;
67
use Orchestra\Testbench\TestCase;
78

@@ -12,6 +13,7 @@ public function it_can_be_resolved()
1213
{
1314
$manager = $this->app[PresetManager::class];
1415

16+
$this->assertInstanceOf(Manager::class, $manager);
1517
$this->assertSame('laravel', $manager->getDefaultDriver());
1618
}
1719

workbench/app/Console/CodeGeneratorCommand.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
namespace Workbench\App\Console;
44

55
use Orchestra\Canvas\Core\Commands\GeneratorCommand;
6-
use Orchestra\Canvas\Core\Concerns\ResolvesPresetStubs;
6+
use Symfony\Component\Console\Input\InputOption;
77

88
class CodeGeneratorCommand extends GeneratorCommand
99
{
@@ -37,4 +37,16 @@ protected function getStub()
3737
{
3838
return __DIR__.'/stubs/class.stub';
3939
}
40+
41+
/**
42+
* Get the console command arguments.
43+
*
44+
* @return array
45+
*/
46+
protected function getOptions()
47+
{
48+
return [
49+
['force', 'f', InputOption::VALUE_NONE, 'Create the class even if the cast already exists'],
50+
];
51+
}
4052
}

0 commit comments

Comments
 (0)