Skip to content

Commit

Permalink
Merge pull request #215 from apiato/API-1169-Tests-are-generated-in-t…
Browse files Browse the repository at this point in the history
…he-wrong-directory

fix(generator): tests are generated in wrong directory
  • Loading branch information
Mohammad-Alavi authored Dec 13, 2024
2 parents b67c1b8 + ac47c2b commit a634f3a
Show file tree
Hide file tree
Showing 35 changed files with 211 additions and 151 deletions.
65 changes: 42 additions & 23 deletions src/Generator/Commands/ContainerApiGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,35 +57,29 @@ public function getUserInputs(): array|null
{
$ui = 'api';

// section name as inputted and lower
$sectionName = $this->sectionName;
$_sectionName = Str::lower($this->sectionName);

// container name as inputted and lower
$containerName = $this->containerName;
$_containerName = Str::lower($this->containerName);

// name of the model (singular and plural)
$model = $this->containerName;
$models = Pluralizer::plural($model);

// add the README file
$this->printInfoMessage('Generating README File');
$this->call('apiato:generate:readme', [
'--section' => $sectionName,
'--container' => $containerName,
'--file' => 'README',
]);

// create the configuration file
$this->printInfoMessage('Generating Configuration File');
$this->call('apiato:generate:configuration', [
'--section' => $sectionName,
'--container' => $containerName,
'--file' => Str::camel($this->sectionName) . '-' . Str::camel($this->containerName),
]);

// create the MainServiceProvider for the container
$this->printInfoMessage('Generating MainServiceProvider');
$this->call('apiato:generate:provider', [
'--section' => $sectionName,
Expand All @@ -94,7 +88,6 @@ public function getUserInputs(): array|null
'--stub' => 'mainserviceprovider',
]);

// create the model and repository for this container
$this->printInfoMessage('Generating Model and Repository');
$this->call('apiato:generate:model', [
'--section' => $sectionName,
Expand All @@ -103,7 +96,6 @@ public function getUserInputs(): array|null
'--repository' => true,
]);

// create the migration file for the model
$this->printInfoMessage('Generating a basic Migration file');
$this->call('apiato:generate:migration', [
'--section' => $sectionName,
Expand All @@ -112,7 +104,6 @@ public function getUserInputs(): array|null
'--tablename' => Str::snake($models),
]);

// create a transformer for the model
$this->printInfoMessage('Generating Transformer for the Model');
$this->call('apiato:generate:transformer', [
'--section' => $sectionName,
Expand All @@ -122,7 +113,6 @@ public function getUserInputs(): array|null
'--full' => false,
]);

// create a factory for the model
$this->printInfoMessage('Generating Factory for the Model');
$this->call('apiato:generate:factory', [
'--section' => $sectionName,
Expand All @@ -131,7 +121,6 @@ public function getUserInputs(): array|null
'--model' => $model,
]);

// create the default routes for this container
$this->printInfoMessage('Generating Default Routes');
$version = $this->checkParameterOrAsk('docversion', 'Enter the version for all API endpoints (integer)', 1);
$doctype = $this->checkParameterOrChoice('doctype', 'Select the type for all API endpoints', ['private', 'public'], 0);
Expand All @@ -147,8 +136,7 @@ public function getUserInputs(): array|null
if ($generateEvents) {
$generateListeners = $this->checkParameterOrConfirm('listeners', 'Do you want to generate the corresponding Event Listeners for this Events?', false);
}

$generateTests = $this->checkParameterOrConfirm('tests', 'Do you want to generate the corresponding Tests for this Container?', false);
$generateTests = $this->checkParameterOrConfirm('tests', 'Do you want to generate the corresponding Tests for this Container?', true);

$generateEvents ?: $this->printInfoMessage('Generating CRUD Events');
$generateListeners ?: $this->printInfoMessage('Generating Event Listeners');
Expand All @@ -168,7 +156,13 @@ public function getUserInputs(): array|null
'action' => 'List' . $models . 'Action',
'request' => 'List' . $models . 'Request',
'task' => 'List' . $models . 'Task',
'unittest' => 'List' . $models . 'TaskTest',
'unittest' => [
'task' => [
'stubfoldername' => 'tasks',
'foldername' => 'Tasks',
'filename' => 'List' . $models . 'TaskTest',
],
],
'functionaltest' => 'List' . $models . 'Test',
'event' => $models . 'ListedEvent',
'controller' => 'List' . $models . 'Controller',
Expand All @@ -182,7 +176,13 @@ public function getUserInputs(): array|null
'action' => 'Find' . $model . 'ByIdAction',
'request' => 'Find' . $model . 'ByIdRequest',
'task' => 'Find' . $model . 'ByIdTask',
'unittest' => 'Find' . $model . 'ByIdTaskTest',
'unittest' => [
'task' => [
'stubfoldername' => 'tasks',
'foldername' => 'Tasks',
'filename' => 'Find' . $model . 'ByIdTaskTest',
],
],
'functionaltest' => 'Find' . $model . 'ByIdTest',
'event' => $model . 'FoundByIdEvent',
'controller' => 'Find' . $model . 'ByIdController',
Expand All @@ -196,7 +196,13 @@ public function getUserInputs(): array|null
'action' => 'Create' . $model . 'Action',
'request' => 'Create' . $model . 'Request',
'task' => 'Create' . $model . 'Task',
'unittest' => 'Create' . $model . 'TaskTest',
'unittest' => [
'task' => [
'stubfoldername' => 'tasks',
'foldername' => 'Tasks',
'filename' => 'Create' . $model . 'TaskTest',
],
],
'functionaltest' => 'Create' . $model . 'Test',
'event' => $model . 'CreatedEvent',
'controller' => 'Create' . $model . 'Controller',
Expand All @@ -210,7 +216,13 @@ public function getUserInputs(): array|null
'action' => 'Update' . $model . 'Action',
'request' => 'Update' . $model . 'Request',
'task' => 'Update' . $model . 'Task',
'unittest' => 'Update' . $model . 'TaskTest',
'unittest' => [
'task' => [
'stubfoldername' => 'tasks',
'foldername' => 'Tasks',
'filename' => 'Update' . $model . 'TaskTest',
],
],
'functionaltest' => 'Update' . $model . 'Test',
'event' => $model . 'UpdatedEvent',
'controller' => 'Update' . $model . 'Controller',
Expand All @@ -224,7 +236,13 @@ public function getUserInputs(): array|null
'action' => 'Delete' . $model . 'Action',
'request' => 'Delete' . $model . 'Request',
'task' => 'Delete' . $model . 'Task',
'unittest' => 'Delete' . $model . 'TaskTest',
'unittest' => [
'task' => [
'stubfoldername' => 'tasks',
'foldername' => 'Tasks',
'filename' => 'Delete' . $model . 'TaskTest',
],
],
'functionaltest' => 'Delete' . $model . 'Test',
'event' => $model . 'DeletedEvent',
'controller' => 'Delete' . $model . 'Controller',
Expand Down Expand Up @@ -268,7 +286,6 @@ public function getUserInputs(): array|null
'--listener' => $generateListeners,
]);

// create the EventServiceProvider for the container
$this->printInfoMessage('Generating EventServiceProvider');
$this->call('apiato:generate:provider', [
'--section' => $sectionName,
Expand All @@ -282,7 +299,9 @@ public function getUserInputs(): array|null
$this->call('apiato:generate:test:unit', [
'--section' => $sectionName,
'--container' => $containerName,
'--file' => $route['unittest'],
'--file' => $route['unittest']['task']['filename'],
'--stubfoldername' => $route['unittest']['task']['stubfoldername'],
'--foldername' => $route['unittest']['task']['foldername'],
'--model' => $model,
'--stub' => $route['stub'],
'--event' => $generateEvents ? $route['event'] : false,
Expand All @@ -292,6 +311,7 @@ public function getUserInputs(): array|null
'--section' => $sectionName,
'--container' => $containerName,
'--file' => $model . 'FactoryTest',
'--foldername' => 'Factories',
'--model' => $model,
'--stub' => 'factory',
'--event' => false,
Expand All @@ -301,6 +321,8 @@ public function getUserInputs(): array|null
'--section' => $sectionName,
'--container' => $containerName,
'--file' => $models . 'MigrationTest',
'--stubfoldername' => 'data',
'--foldername' => 'Data/Migrations',
'--model' => $model,
'--stub' => 'migration',
'--event' => false,
Expand Down Expand Up @@ -394,9 +416,6 @@ public function getUserInputs(): array|null
return null;
}

/**
* Get the default file name for this component to be generated.
*/
public function getDefaultFileName(): string
{
return 'composer';
Expand Down
63 changes: 58 additions & 5 deletions src/Generator/Commands/ContainerGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ class ContainerGenerator extends GeneratorCommand implements ComponentsGenerator
*/
public array $inputs = [
['ui', null, InputOption::VALUE_OPTIONAL, 'The user-interface to generate the Controller for.'],
['events', null, InputOption::VALUE_OPTIONAL, 'Generate Events for this Container?'],
['listeners', null, InputOption::VALUE_OPTIONAL, 'Generate Event Listeners for Events of this Container?'],
['tests', null, InputOption::VALUE_OPTIONAL, 'Generate Tests for this Container?'],
];
/**
* The console command name.
Expand Down Expand Up @@ -48,20 +51,70 @@ class ContainerGenerator extends GeneratorCommand implements ComponentsGenerator
public function getUserInputs(): array|null
{
$ui = Str::lower($this->checkParameterOrChoice('ui', 'Select the UI for this container', ['API', 'WEB', 'BOTH'], 0));
$generateEvents = $this->checkParameterOrConfirm('events', 'Do you want to generate the corresponding CRUD Events for this Container?', false);
$generateListeners = false;
if ($generateEvents) {
$generateListeners = $this->checkParameterOrConfirm('listeners', 'Do you want to generate the corresponding Event Listeners for this Events?', false);
}
$generateTests = $this->checkParameterOrConfirm('tests', 'Do you want to generate the corresponding Tests for this Container?', true);
if ($generateTests) {
$this->call('apiato:generate:test:testcase', [
'--section' => $this->sectionName,
'--container' => $this->containerName,
'--file' => 'TestCase',
'--type' => 'container',
]);
$this->call('apiato:generate:test:testcase', [
'--section' => $this->sectionName,
'--container' => $this->containerName,
'--file' => 'TestCase',
'--type' => 'unit',
]);
$this->call('apiato:generate:test:testcase', [
'--section' => $this->sectionName,
'--container' => $this->containerName,
'--file' => 'TestCase',
'--type' => 'functional',
]);
// $this->call('apiato:generate:test:testcase', [
// '--section' => $this->sectionName,
// '--container' => $this->containerName,
// '--file' => 'TestCase',
// '--type' => 'e2e',
// ]);
$this->call('apiato:generate:test:testcase', [
'--section' => $this->sectionName,
'--container' => $this->containerName,
'--file' => 'TestCase',
'--type' => 'api',
]);
// $this->call('apiato:generate:test:testcase', [
// '--section' => $this->sectionName,
// '--container' => $this->containerName,
// '--file' => 'TestCase',
// '--type' => 'cli',
// ]);
// $this->call('apiato:generate:test:testcase', [
// '--section' => $this->sectionName,
// '--container' => $this->containerName,
// '--file' => 'TestCase',
// '--type' => 'web',
// ]);
}

// container name as inputted and lower
$sectionName = $this->sectionName;
$_sectionName = Str::lower($this->sectionName);

// container name as inputted and lower
$containerName = $this->containerName;
$_containerName = Str::lower($this->containerName);
$sectionName = $this->sectionName;
$_sectionName = Str::lower($this->sectionName);

if ('api' === $ui || 'both' === $ui) {
$this->call('apiato:generate:container:api', [
'--section' => $sectionName,
'--container' => $containerName,
'--file' => 'composer',
'--events' => $generateEvents,
'--listeners' => $generateListeners,
'--tests' => $generateTests,
'--maincalled' => true,
]);
}
Expand Down
13 changes: 0 additions & 13 deletions src/Generator/Commands/ContainerWebGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,35 +52,29 @@ public function getUserInputs(): array|null
{
$ui = 'web';

// container name as inputted and lower
$sectionName = $this->sectionName;
$_sectionName = Str::lower($this->sectionName);

// container name as inputted and lower
$containerName = $this->containerName;
$_containerName = Str::lower($this->containerName);

// name of the model (singular and plural)
$model = $this->containerName;
$models = Pluralizer::plural($model);

// add the README file
$this->printInfoMessage('Generating README File');
$this->call('apiato:generate:readme', [
'--section' => $sectionName,
'--container' => $containerName,
'--file' => 'README',
]);

// create the configuration file
$this->printInfoMessage('Generating Configuration File');
$this->call('apiato:generate:configuration', [
'--section' => $sectionName,
'--container' => $containerName,
'--file' => Str::camel($this->sectionName) . '-' . Str::camel($this->containerName),
]);

// create the MainServiceProvider for the container
$this->printInfoMessage('Generating MainServiceProvider');
$this->call('apiato:generate:provider', [
'--section' => $sectionName,
Expand All @@ -89,7 +83,6 @@ public function getUserInputs(): array|null
'--stub' => 'mainserviceprovider',
]);

// create the model and repository for this container
$this->printInfoMessage('Generating Model and Repository');
$this->call('apiato:generate:model', [
'--section' => $sectionName,
Expand All @@ -98,7 +91,6 @@ public function getUserInputs(): array|null
'--repository' => true,
]);

// create the migration file for the model
$this->printInfoMessage('Generating a basic Migration file');
$this->call('apiato:generate:migration', [
'--section' => $sectionName,
Expand All @@ -107,12 +99,10 @@ public function getUserInputs(): array|null
'--tablename' => Str::snake($models),
]);

// create the default routes for this container
$this->printInfoMessage('Generating Default Routes');
$version = 1;
$doctype = 'private';

// get the URI and remove the first trailing slash
$url = Str::lower($this->checkParameterOrAsk('url', 'Enter the base URI for all WEB endpoints (foo/bar/{id})', Str::kebab($models)));
$url = ltrim($url, '/');

Expand Down Expand Up @@ -309,9 +299,6 @@ public function getUserInputs(): array|null
return null;
}

/**
* Get the default file name for this component to be generated.
*/
public function getDefaultFileName(): string
{
return 'composer';
Expand Down
Loading

0 comments on commit a634f3a

Please sign in to comment.