-
-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #69 from DavoodGhanbarpour/customizable_stubs
Customizable stubs
- Loading branch information
Showing
4 changed files
with
189 additions
and
6 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace WendellAdriel\ValidatedDTO\Console\Commands; | ||
|
||
use Illuminate\Console\Command; | ||
use Symfony\Component\Console\Attribute\AsCommand; | ||
|
||
#[AsCommand(name: 'dto:stubs')] | ||
final class PublishStubsCommand extends Command | ||
{ | ||
/** | ||
* @var string | ||
*/ | ||
protected $name = 'dto:stubs'; | ||
|
||
/** | ||
* @var string|null | ||
* | ||
* @deprecated | ||
*/ | ||
protected static $defaultName = 'dto:stubs'; | ||
|
||
/** | ||
* The name and signature of the console command. | ||
* | ||
* @var string | ||
*/ | ||
protected $signature = 'dto:stubs {--force : Overwrite any existing files}'; | ||
|
||
/** | ||
* The console command description. | ||
* | ||
* @var string | ||
*/ | ||
protected $description = 'Publish all stubs that are available for customization'; | ||
|
||
/** | ||
* Execute the console command. | ||
*/ | ||
public function handle(): void | ||
{ | ||
$this->call('vendor:publish', [ | ||
'--tag' => 'validatedDTO-stubs', | ||
'--force' => $this->option('force'), | ||
]); | ||
} | ||
} |
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,114 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
it('publishes the package stubs', function () { | ||
$this->artisan('dto:stubs') | ||
->assertExitCode(0); | ||
|
||
expect(base_path('stubs/resource_dto.stub'))->toBeFile(); | ||
expect(base_path('stubs/simple_dto.stub'))->toBeFile(); | ||
expect(base_path('stubs/dto.stub'))->toBeFile(); | ||
}); | ||
|
||
it('publishes the package stubs with force flag', function () { | ||
$this->artisan('dto:stubs', ['--force' => true]) | ||
->assertExitCode(0); | ||
|
||
expect(base_path('stubs/resource_dto.stub'))->toBeFile(); | ||
expect(base_path('stubs/simple_dto.stub'))->toBeFile(); | ||
expect(base_path('stubs/dto.stub'))->toBeFile(); | ||
|
||
expect(base_path('stubs/dto.stub'))->toBeFileWithContent(UserStubDTO()); | ||
expect(base_path('stubs/simple_dto.stub'))->toBeFileWithContent(SimpleUserStubDTO()); | ||
expect(base_path('stubs/resource_dto.stub'))->toBeFileWithContent(UserResourceStubDTO()); | ||
}); | ||
|
||
/** | ||
* Content of the expected UserDTO class | ||
*/ | ||
function UserStubDTO(): string | ||
{ | ||
return <<<CLASS | ||
<?php | ||
namespace {{ namespace }}; | ||
use WendellAdriel\ValidatedDTO\ValidatedDTO; | ||
class {{ class }} extends ValidatedDTO | ||
{ | ||
protected function rules(): array | ||
{ | ||
return []; | ||
} | ||
protected function defaults(): array | ||
{ | ||
return []; | ||
} | ||
protected function casts(): array | ||
{ | ||
return []; | ||
} | ||
} | ||
CLASS; | ||
} | ||
|
||
/** | ||
* Content of the expected SimpleUserDTO class | ||
*/ | ||
function SimpleUserStubDTO(): string | ||
{ | ||
return <<<CLASS | ||
<?php | ||
namespace {{ namespace }}; | ||
use WendellAdriel\ValidatedDTO\SimpleDTO; | ||
class {{ class }} extends SimpleDTO | ||
{ | ||
protected function defaults(): array | ||
{ | ||
return []; | ||
} | ||
protected function casts(): array | ||
{ | ||
return []; | ||
} | ||
} | ||
CLASS; | ||
} | ||
|
||
/** | ||
* Content of the expected UserResourceDTO class | ||
*/ | ||
function UserResourceStubDTO(): string | ||
{ | ||
return <<<CLASS | ||
<?php | ||
namespace {{ namespace }}; | ||
use WendellAdriel\ValidatedDTO\ResourceDTO; | ||
class {{ class }} extends ResourceDTO | ||
{ | ||
protected function defaults(): array | ||
{ | ||
return []; | ||
} | ||
protected function casts(): array | ||
{ | ||
return []; | ||
} | ||
} | ||
CLASS; | ||
} |