-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
creating models within a domain command
- Loading branch information
1 parent
447c4f4
commit 7e7d630
Showing
5 changed files
with
81 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php | ||
|
||
namespace Salehhashemi\LaravelDomainExpert\Console; | ||
|
||
use Illuminate\Foundation\Console\ModelMakeCommand; | ||
|
||
class ExtendedModelMakeCommand extends ModelMakeCommand | ||
{ | ||
use HandlesDomainOption; | ||
|
||
protected string $folder = 'Models'; | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function handle(): bool|null | ||
{ | ||
$this->handleDomainOption(); | ||
|
||
return parent::handle(); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected function getOptions(): array | ||
{ | ||
$options = parent::getOptions(); | ||
$options[] = $this->getDomainOption(); | ||
|
||
return $options; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
|
||
namespace Salehhashemi\LaravelDomainExpert\Tests; | ||
|
||
use Illuminate\Support\Facades\File; | ||
use Salehhashemi\LaravelDomainExpert\Console\ExtendedModelMakeCommand; | ||
use Salehhashemi\LaravelDomainExpert\LaravelDomainExpertServiceProvider; | ||
|
||
class ExtendedModelMakeCommandConsoleTest extends ConsoleTestCase | ||
{ | ||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected function getPackageProviders($app): array | ||
{ | ||
return [LaravelDomainExpertServiceProvider::class]; | ||
} | ||
|
||
/** @test */ | ||
public function test_creates_a_model_in_the_selected_domain() | ||
{ | ||
// Set the expected domain | ||
$expectedDomain = 'SampleDomain'; | ||
|
||
$tester = $this->runCommand(ExtendedModelMakeCommand::class, [ | ||
'name' => 'SampleModel', | ||
'--domain' => $expectedDomain, | ||
], [0]); | ||
|
||
$tester->assertCommandIsSuccessful(); | ||
|
||
// Check if the model file has been created | ||
$this->assertTrue(File::exists(app_path("Domains/{$expectedDomain}/Models/SampleModel.php"))); | ||
} | ||
} |