1 | <?php |
||||||
2 | |||||||
3 | namespace Shamaseen\Repository\Tests\Feature; |
||||||
4 | |||||||
5 | use Illuminate\Support\Facades\Config; |
||||||
6 | use Shamaseen\Repository\Commands\Generator; |
||||||
7 | use Shamaseen\Repository\PathResolver; |
||||||
8 | use Shamaseen\Repository\Tests\TestCase; |
||||||
9 | |||||||
10 | class GenerateFilesTest extends TestCase |
||||||
11 | { |
||||||
12 | private array $filesToGenerate = ['Controller', 'Repository', 'Model', 'Request', 'Resource', 'Collection', 'Policy', 'Test']; |
||||||
13 | |||||||
14 | /** |
||||||
15 | * @param string $dataName |
||||||
16 | */ |
||||||
17 | public function __construct(?string $name = null, array $data = [], $dataName = '') |
||||||
18 | { |
||||||
19 | parent::__construct($name, $data, $dataName); |
||||||
0 ignored issues
–
show
Bug
introduced
by
![]() The call to
PHPUnit\Framework\TestCase::__construct() has too many arguments starting with $data .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue. If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above. ![]() |
|||||||
20 | } |
||||||
21 | |||||||
22 | public function testGenerate() |
||||||
23 | { |
||||||
24 | $this->artisan("generate:repository $this->userPath/$this->modelName -f"); |
||||||
25 | |||||||
26 | foreach ($this->filesToGenerate as $type) { |
||||||
27 | $absolutePath = $this->generator->absolutePath( |
||||||
28 | $this->pathResolver->outputPath($type) |
||||||
29 | ); |
||||||
30 | |||||||
31 | $this->assertFileExists($absolutePath); |
||||||
32 | } |
||||||
33 | } |
||||||
34 | |||||||
35 | public function testGenerateMCROnly() |
||||||
36 | { |
||||||
37 | $this->artisan("generate:repository $this->userPath/$this->modelName -f -mrc"); |
||||||
38 | |||||||
39 | $filesToGenerate = ['Controller', 'Repository', 'Model']; |
||||||
40 | foreach ($filesToGenerate as $type) { |
||||||
41 | $absolutePath = $this->generator->absolutePath( |
||||||
42 | $this->pathResolver->outputPath($type) |
||||||
43 | ); |
||||||
44 | |||||||
45 | $this->assertFileExists($absolutePath); |
||||||
46 | } |
||||||
47 | } |
||||||
48 | |||||||
49 | public static function defaultStubsConfigProvider(): array |
||||||
50 | { |
||||||
51 | return [ |
||||||
52 | // run 1 |
||||||
53 | [ |
||||||
54 | [ |
||||||
55 | Generator::RESOURCE_OPTION |
||||||
56 | ], |
||||||
57 | [ |
||||||
58 | 'Resource', |
||||||
59 | ] |
||||||
60 | ], |
||||||
61 | // run 2 |
||||||
62 | [ |
||||||
63 | [ |
||||||
64 | Generator::MODEL_OPTION, |
||||||
65 | Generator::CONTROLLER_OPTION, |
||||||
66 | ], |
||||||
67 | [ |
||||||
68 | 'Model', |
||||||
69 | 'Controller', |
||||||
70 | ], |
||||||
71 | ], |
||||||
72 | // running Request option should only generate Request |
||||||
73 | [ |
||||||
74 | [ |
||||||
75 | Generator::REQUEST_OPTION, |
||||||
76 | ], |
||||||
77 | [ |
||||||
78 | 'Request', |
||||||
79 | ] |
||||||
80 | ], |
||||||
81 | // running Collection option should only generate Collection |
||||||
82 | [ |
||||||
83 | [ |
||||||
84 | Generator::COLLECTION_OPTION, |
||||||
85 | ], |
||||||
86 | [ |
||||||
87 | 'Collection', |
||||||
88 | ] |
||||||
89 | ], |
||||||
90 | ]; |
||||||
91 | } |
||||||
92 | |||||||
93 | /** @dataProvider defaultStubsConfigProvider */ |
||||||
94 | public function testDefaultStubsConfig(array $config, array $generatedNames) |
||||||
95 | { |
||||||
96 | Config::set('repository.default_generated_files', $config); |
||||||
97 | $this->artisan("generate:repository $this->userPath/$this->modelName -f"); |
||||||
98 | |||||||
99 | foreach ($generatedNames as $generatedName) { |
||||||
100 | $this->assertFileExists($this->generator->absolutePath( |
||||||
101 | $this->pathResolver->outputPath($generatedName) |
||||||
102 | )); |
||||||
103 | } |
||||||
104 | |||||||
105 | $allGeneratedStubs = array_keys(PathResolver::$configTypePathMap); |
||||||
106 | $filesNotGenerated = array_diff($allGeneratedStubs, $generatedNames); |
||||||
107 | |||||||
108 | foreach ($filesNotGenerated as $fileNotGenerated) { |
||||||
109 | $this->assertFileDoesNotExist($this->generator->absolutePath( |
||||||
110 | $this->pathResolver->outputPath($fileNotGenerated) |
||||||
111 | )); |
||||||
112 | } |
||||||
113 | } |
||||||
114 | } |
||||||
115 |