-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathGenerateApiTestCommand.php
44 lines (31 loc) · 1.42 KB
/
GenerateApiTestCommand.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
<?php
namespace Javaabu\Generators\Commands;
use Javaabu\Generators\Generators\ApiTestGenerator;
use Javaabu\GeneratorHelpers\StringCaser;
class GenerateApiTestCommand extends BaseGenerateCommand
{
protected $name = 'generate:api_test';
protected $description = 'Generate model api controller test based on your database table schema';
protected string $generator_class = ApiTestGenerator::class;
protected function createOutput(string $table, array $columns): void
{
$generator = $this->getGenerator($table, $columns);
$output = $generator->render();
if (app()->runningInConsole()) {
$this->info("Schema-based model api controller test for table \"$table\" have been generated!");
$this->info('Copy & paste these to your api controller test file:');
}
$this->line($output);
}
protected function createFiles(string $table, array $columns, bool $force = false, string $path = ''): void
{
$path = $this->getPath(base_path('tests/Feature/Controllers/Api'), $path);
$file_name = StringCaser::pluralStudly($table) . 'ControllerTest.php';
$file_path = $this->getFullFilePath($path, $file_name);
$generator = $this->getGenerator($table, $columns);
$output = $generator->render();
if ($this->putContent($file_path, $output, $force)) {
$this->info("$file_name created!");
}
}
}