1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Shamaseen\Repository\Tests\Feature; |
4
|
|
|
|
5
|
|
|
use Illuminate\Support\Facades\Config; |
6
|
|
|
use PHPUnit\Framework\Attributes\DataProvider; |
|
|
|
|
7
|
|
|
use Shamaseen\Repository\Commands\Generator; |
8
|
|
|
use Shamaseen\Repository\PathResolver; |
9
|
|
|
use Shamaseen\Repository\Tests\TestCase; |
10
|
|
|
|
11
|
|
|
class GenerateFilesTest extends TestCase |
12
|
|
|
{ |
13
|
|
|
private array $filesToGenerate = ['Controller', 'Repository', 'Model', 'Request', 'Resource', 'Collection', 'Policy', 'Test']; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* @param string $dataName |
17
|
|
|
*/ |
18
|
|
|
public function __construct(?string $name = null, array $data = [], $dataName = '') |
19
|
|
|
{ |
20
|
|
|
parent::__construct($name, $data, $dataName); |
|
|
|
|
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
public function testGenerate() |
24
|
|
|
{ |
25
|
|
|
$this->artisan("generate:repository $this->userPath/$this->modelName -f"); |
26
|
|
|
|
27
|
|
|
foreach ($this->filesToGenerate as $type) { |
28
|
|
|
$absolutePath = $this->generator->absolutePath( |
29
|
|
|
$this->pathResolver->outputPath($type) |
30
|
|
|
); |
31
|
|
|
|
32
|
|
|
$this->assertFileExists($absolutePath); |
33
|
|
|
} |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
public function testGenerateMCROnly() |
37
|
|
|
{ |
38
|
|
|
$this->artisan("generate:repository $this->userPath/$this->modelName -f -mrc"); |
39
|
|
|
|
40
|
|
|
$filesToGenerate = ['Controller', 'Repository', 'Model']; |
41
|
|
|
foreach ($filesToGenerate as $type) { |
42
|
|
|
$absolutePath = $this->generator->absolutePath( |
43
|
|
|
$this->pathResolver->outputPath($type) |
44
|
|
|
); |
45
|
|
|
|
46
|
|
|
$this->assertFileExists($absolutePath); |
47
|
|
|
} |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
public static function defaultStubsConfigProvider(): array |
51
|
|
|
{ |
52
|
|
|
return [ |
53
|
|
|
// run 1 |
54
|
|
|
[ |
55
|
|
|
[ |
56
|
|
|
Generator::RESOURCE_OPTION |
57
|
|
|
], |
58
|
|
|
[ |
59
|
|
|
'Resource', |
60
|
|
|
] |
61
|
|
|
], |
62
|
|
|
// run 2 |
63
|
|
|
[ |
64
|
|
|
[ |
65
|
|
|
Generator::MODEL_OPTION, |
66
|
|
|
Generator::CONTROLLER_OPTION, |
67
|
|
|
], |
68
|
|
|
[ |
69
|
|
|
'Model', |
70
|
|
|
'Controller', |
71
|
|
|
], |
72
|
|
|
], |
73
|
|
|
// running Request option should only generate Request |
74
|
|
|
[ |
75
|
|
|
[ |
76
|
|
|
Generator::REQUEST_OPTION, |
77
|
|
|
], |
78
|
|
|
[ |
79
|
|
|
'Request', |
80
|
|
|
] |
81
|
|
|
], |
82
|
|
|
// running Collection option should only generate Collection |
83
|
|
|
[ |
84
|
|
|
[ |
85
|
|
|
Generator::COLLECTION_OPTION, |
86
|
|
|
], |
87
|
|
|
[ |
88
|
|
|
'Collection', |
89
|
|
|
] |
90
|
|
|
], |
91
|
|
|
]; |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
#[DataProvider('defaultStubsConfigProvider')] |
95
|
|
|
public function testDefaultStubsConfig(array $config, array $generatedNames) |
96
|
|
|
{ |
97
|
|
|
Config::set('repository.default_generated_files', $config); |
98
|
|
|
$this->artisan("generate:repository $this->userPath/$this->modelName -f"); |
99
|
|
|
|
100
|
|
|
foreach ($generatedNames as $generatedName) { |
101
|
|
|
$this->assertFileExists($this->generator->absolutePath( |
102
|
|
|
$this->pathResolver->outputPath($generatedName) |
103
|
|
|
)); |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
$allGeneratedStubs = array_keys(PathResolver::$configTypePathMap); |
107
|
|
|
$filesNotGenerated = array_diff($allGeneratedStubs, $generatedNames); |
108
|
|
|
|
109
|
|
|
foreach ($filesNotGenerated as $fileNotGenerated) { |
110
|
|
|
$this->assertFileDoesNotExist($this->generator->absolutePath( |
111
|
|
|
$this->pathResolver->outputPath($fileNotGenerated) |
112
|
|
|
)); |
113
|
|
|
} |
114
|
|
|
} |
115
|
|
|
} |
116
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths