comparison src/Generator/Test/TestGenerator.php @ 37:116b36f5e73b ls_dev_2025_09

Adding support for tests. It's pretty basic but we can improve later.
author Luka Sitas <sitas.luka.97@gmail.com>
date Thu, 25 Sep 2025 19:58:01 -0400
parents
children
comparison
equal deleted inserted replaced
36:76584181267a 37:116b36f5e73b
1 <?php
2
3 namespace Wizard\MagicForger\Generator\Test;
4
5 use Symfony\Component\Console\Attribute\AsCommand;
6 use Wizard\MagicForger\Generator\BaseGenerator;
7 use Wizard\MagicForger\Replacer;
8 use Illuminate\Support\Str;
9
10 #[AsCommand(name: 'mf:test')]
11 class TestGenerator extends BaseGenerator
12 {
13 /**
14 * The name and signature of the console command.
15 *
16 * @var string
17 */
18 protected $name = 'mf:test';
19
20 /**
21 * The console command description.
22 *
23 * @var string
24 */
25 protected $description = 'Generates the Test File for a table.';
26
27 /**
28 * The type of class being generated.
29 *
30 * @var string
31 */
32 protected $type = 'Test';
33
34 /**
35 * Execute the console command.
36 */
37 public function handle()
38 {
39 parent::handle();
40 }
41
42 /**
43 * Get the stub file for the generator.
44 *
45 * @return string
46 */
47 protected function getStub()
48 {
49 return $this->resolveStubPath('/stubs/test.stub');
50 }
51
52 /**
53 * Resolve the fully-qualified path to the stub.
54 *
55 * @param string $stub
56 * @return string
57 */
58 protected function resolveStubPath($stub)
59 {
60 return is_file($customPath = $this->laravel->basePath(trim($stub, '/')))
61 ? $customPath
62 : __DIR__.$stub;
63 }
64
65 protected function getClassName($name)
66 {
67 return $this->test_name($name);
68 }
69
70 /**
71 * Get the stub file for the generator.
72 *
73 * @return string
74 */
75 protected function getPath($name = null)
76 {
77 return str_replace(['App\\', '\\'], ['app/', '/'], $this->getTestNamespace() . '/' . $this->test_name($this->getTableInput()) . '.php');
78 }
79 }