diff --git a/tests/Expectations.php b/tests/Expectations.php index ce57889..f2cdd6d 100644 --- a/tests/Expectations.php +++ b/tests/Expectations.php @@ -1,5 +1,6 @@ extend('toContainFilepath', function ($path) { return $this->toContain(Path::normalize($path)); }); + +expect()->extend('toGenerateFileWithNamespace', function ($expectedPath, $expectedNamespace) { + $command = $this->value; + + $expectedFullPath = Path::normalize(base_path($expectedPath)); + + if (file_exists($expectedFullPath)) { + unlink($expectedFullPath); + } + + Artisan::call($command); + + $output = Artisan::output(); + + expect($output)->toContainFilepath($expectedPath); + + expect(file_exists($expectedFullPath))->toBeTrue(); + + $contents = file_get_contents($expectedFullPath); + + expect($contents)->toContain("namespace {$expectedNamespace};"); + + return $this; +}); diff --git a/tests/Generator/NestedNameTest.php b/tests/Generator/NestedNameTest.php new file mode 100644 index 0000000..5c4403f --- /dev/null +++ b/tests/Generator/NestedNameTest.php @@ -0,0 +1,35 @@ +toGenerateFileWithNamespace($expectedPath, $expectedNamespace); +})->with([ + 'model Invoicing:Deep/Nested/Model' => ['model', 'Models', 'Invoicing:Deep/Nested/Model', 'Domain\Invoicing\Models\Deep\Nested', 'src/Domain/Invoicing/Models/Deep/Nested/Model.php'], + 'action Invoicing:Deep/Nested/SomeAction' => ['action', 'Actions', 'Invoicing:Deep/Nested/SomeAction', 'Domain\Invoicing\Actions\Deep\Nested', 'src/Domain/Invoicing/Actions/Deep/Nested/SomeAction.php'], + 'dto Invoicing:Deep/Nested/InvoiceData' => ['dto', 'Data', 'Invoicing:Deep/Nested/InvoiceData', 'Domain\Invoicing\Data\Deep\Nested', 'src/Domain/Invoicing/Data/Deep/Nested/InvoiceData.php'], + 'view_model Invoicing:Deep/Nested/InvoiceViewModel' => ['view_model', 'ViewModels', 'Invoicing:Deep/Nested/InvoiceViewModel', 'Domain\Invoicing\ViewModels\Deep\Nested', 'src/Domain/Invoicing/ViewModels/Deep/Nested/InvoiceViewModel.php'], + 'value_object Invoicing:Deep/Nested/InvoiceNumber' => ['value_object', 'ValueObjects', 'Invoicing:Deep/Nested/InvoiceNumber', 'Domain\Invoicing\ValueObjects\Deep\Nested', 'src/Domain/Invoicing/ValueObjects/Deep/Nested/InvoiceNumber.php'], + 'provider Invoicing:Deep/Nested/InvoiceProvider' => ['provider', 'Providers', 'Invoicing:Deep/Nested/InvoiceProvider', 'Domain\Invoicing\Providers\Deep\Nested', 'src/Domain/Invoicing/Providers/Deep/Nested/InvoiceProvider.php'], + 'exception Deep/Nested/InvoiceNotFoundException' => ['exception', 'Exceptions', 'Invoicing:Deep/Nested/InvoiceNotFoundException', 'Domain\Invoicing\Exceptions\Deep\Nested', 'src/Domain/Invoicing/Exceptions/Deep/Nested/InvoiceNotFoundException.php'], + 'cast Invoicing:Deep/Nested/InvoiceCast' => ['cast', 'Casts', 'Invoicing:Deep/Nested/InvoiceCast', 'Domain\Invoicing\Casts\Deep\Nested', 'src/Domain/Invoicing/Casts/Deep/Nested/InvoiceCast.php'], + 'channel Invoicing:Deep/Nested/InvoiceChannel' => ['channel', 'Channels', 'Invoicing:Deep/Nested/InvoiceChannel', 'Domain\Invoicing\Channels\Deep\Nested', 'src/Domain/Invoicing/Channels/Deep/Nested/InvoiceChannel.php'], + 'command Invoicing:Deep/Nested/InvoiceCommand' => ['command', 'Commands', 'Invoicing:Deep/Nested/InvoiceCommand', 'Domain\Invoicing\Commands\Deep\Nested', 'src/Domain/Invoicing/Commands/Deep/Nested/InvoiceCommand.php'], + 'class Invoicing:Deep/Nested/InvoiceClass' => ['class', '', 'Invoicing:Deep/Nested/InvoiceClass', 'Domain\Invoicing\Deep\Nested', 'src/Domain/Invoicing/Deep/Nested/InvoiceClass.php'], +]);