Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
Signed-off-by: Mior Muhammad Zaki <[email protected]>
  • Loading branch information
crynobone committed Oct 8, 2023
1 parent 766f9ba commit d2ea00c
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 1 deletion.
24 changes: 24 additions & 0 deletions tests/Commands/GeneratorCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'), '<?php '.PHP_EOL);

$this->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'), '<?php '.PHP_EOL);

$this->artisan('make:code', ['name' => 'Value/Foo', '--force' => true])
->assertSuccessful();

$this->assertFileContains([
'namespace App\Value;',
'class Foo',
], 'app/Value/Foo.php');
}
}
2 changes: 2 additions & 0 deletions tests/PresetManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Orchestra\Canvas\Core\Tests;

use Illuminate\Support\Manager;
use Orchestra\Canvas\Core\PresetManager;
use Orchestra\Testbench\TestCase;

Expand All @@ -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());
}

Expand Down
14 changes: 13 additions & 1 deletion workbench/app/Console/CodeGeneratorCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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'],
];
}
}

0 comments on commit d2ea00c

Please sign in to comment.