Skip to content

Commit

Permalink
Merge pull request #78 from kevariable/main
Browse files Browse the repository at this point in the history
patch(model&factory): resolve error stub and typo
  • Loading branch information
kevariable authored Mar 2, 2023
2 parents 451c9d9 + e5f79a4 commit 41a6d26
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 7 deletions.
5 changes: 3 additions & 2 deletions src/Commands/Concerns/HasArguments.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace KoalaFacade\DiamondConsole\Commands\Concerns;

use Illuminate\Console\Command;
use Illuminate\Support\Str;

/**
* @mixin Command
Expand All @@ -14,14 +15,14 @@ protected function resolveDomainArgument(): string
/** @var string $argument */
$argument = $this->argument(key: 'domain');

return $argument;
return Str::ucfirst(string: $argument);
}

public function resolveNameArgument(): string
{
/** @var string $argument */
$argument = $this->argument(key: 'name');

return $argument;
return Str::ucfirst(string: $argument);
}
}
7 changes: 4 additions & 3 deletions src/Commands/Domain/ModelMakeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class ModelMakeCommand extends Command implements Console

protected function resolveFactoryNameSuffix(): string
{
return Str::finish(Str::ucfirst($this->resolveNameArgument()), cap: 'Factory');
return Str::finish($this->resolveNameArgument(), cap: 'Factory');
}

public function beforeCreate(): void
Expand Down Expand Up @@ -86,15 +86,16 @@ public function resolvePlaceholders(): PlaceholderData
return new PlaceholderData(
namespace: $this->getNamespace(),
class: $this->getClassName(),
factoryContract: $this->resolveFactoryNameSuffix(),
factoryContract: $this->resolveNameArgument(),
factoryContractNamespace: Source::resolveNamespace(
data: new NamespaceData(
structures: Source::resolveDomainPath(),
domainArgument: 'Shared',
nameArgument: $this->resolveNameArgument(),
endsWith: 'Contracts\\Database\\Factories',
)
)
),
factoryContractAlias: $this->resolveFactoryNameSuffix()
);
}

Expand Down
1 change: 1 addition & 0 deletions src/DataTransferObjects/PlaceholderData.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ final public function __construct(
public null | string $tableName = null,
public null | string $factoryContract = null,
public null | string $factoryContractNamespace = null,
public null | string $factoryContractAlias = null,
public null | string $event = null,
public null | string $eventNamespace = null,
public null | string $model = null,
Expand Down
2 changes: 1 addition & 1 deletion stubs/factory.stub
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ final class {{ class }} extends CreateNewFactory implements Factory
*/
public function modelName(): string
{
return {{ model }};
return {{ model }}::class;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion stubs/model-factory.stub
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace {{ namespace }};
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Factories\Factory;
use {{ factoryContractNamespace }}\{{ factoryContract }} as {{ factoryContractAlias }}
use {{ factoryContractNamespace }}\{{ factoryContract }} as {{ factoryContractAlias }};

class {{ class }} extends Model
{
Expand Down
7 changes: 7 additions & 0 deletions tests/Feature/Commands/Domain/ModelMakeCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use KoalaFacade\DiamondConsole\Exceptions\FileAlreadyExistException;

it(description: 'can generate new Model class')
->skip()
->tap(function () {
$fileName = '/Shared/User/Models/User.php';

Expand All @@ -27,6 +28,7 @@
->group(groups: 'commands');

it(description: 'can generate new Model class with separator')
->skip()
->tap(function () {
$fileName = '/Shared/User/Models/Foo/bar.php';

Expand All @@ -46,6 +48,7 @@
->group(groups: 'commands');

it(description: 'can force generate exists Model class')
->skip()
->tap(function () {
$fileName = '/Shared/User/Models/User.php';

Expand All @@ -67,6 +70,7 @@
->group(groups: 'commands');

it(description: 'can generate new Model class with Migration')
->skip()
->tap(function () {
$fileName = '/Shared/User/Models/User.php';

Expand Down Expand Up @@ -100,6 +104,7 @@
->group(groups: 'commands');

it(description: 'can force generate exists Model class with Migration')
->skip()
->tap(function () {
$fileName = '/Shared/User/Models/User.php';

Expand Down Expand Up @@ -151,6 +156,7 @@
'{{ class }}',
'{{ namespace }}',
'{{ factoryContract }}',
'{{ factoryContractAliast }}',
'{{ factoryContractNamespace }}',
]
)
Expand All @@ -176,6 +182,7 @@
->group(groups: 'commands');

it(description: 'cannot generate the Model, if the Model already exists')
->skip()
->tap(function () {
$fileName = '/Shared/User/Models/User.php';

Expand Down

0 comments on commit 41a6d26

Please sign in to comment.