Skip to content

Commit 16d5d20

Browse files
authored
Merge pull request #205 from RonasIT/140-use-NovaResource-class-in-NovaTestGenerator-instead-of-Model
fix: use relative nova path for check nova resource namespace
2 parents d9dbf86 + 5b6c000 commit 16d5d20

File tree

2 files changed

+4
-20
lines changed

2 files changed

+4
-20
lines changed

src/Generators/NovaTestGenerator.php

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,8 @@
1717

1818
class NovaTestGenerator extends AbstractTestsGenerator
1919
{
20-
protected string $novaPath;
21-
2220
protected string $novaResourceClassName;
2321

24-
public function __construct()
25-
{
26-
parent::__construct();
27-
28-
$this->novaPath = base_path($this->paths['nova']);
29-
}
30-
3122
public function generate(): void
3223
{
3324
if (class_exists(NovaServiceProvider::class)) {
@@ -116,7 +107,7 @@ protected function getActions(): array
116107

117108
protected function getNovaFiles(): Generator
118109
{
119-
$iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($this->novaPath));
110+
$iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator(base_path($this->paths['nova'])));
120111

121112
foreach ($iterator as $file) {
122113
if ($file->isFile() && $file->getExtension() === 'php') {
@@ -130,11 +121,11 @@ protected function getCommonNovaResources(): array
130121
$resources = [];
131122

132123
foreach ($this->getNovaFiles() as $file) {
133-
$relativePath = Str::after($file->getPathname(), $this->novaPath . DIRECTORY_SEPARATOR);
124+
$relativePath = Str::after($file->getPathname(), $this->paths['nova'] . DIRECTORY_SEPARATOR);
134125

135126
$class = Str::before($relativePath, '.');
136127

137-
$className = $this->pathToNamespace($this->novaPath . DIRECTORY_SEPARATOR . $class);
128+
$className = $this->pathToNamespace($this->paths['nova'] . DIRECTORY_SEPARATOR . $class);
138129

139130
if ($this->isResourceNameContainModel($className) && $this->isNovaResource($className)) {
140131
$resources[] = $className;

tests/Support/Command/CommandMockTrait.php

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ public function mockGenerator(): void
5252
$this->nativeClassExistsMethodCall(['RonasIT\Support\Tests\Support\Command\Models\Post', true]),
5353
$this->nativeClassExistsMethodCall(['Laravel\Nova\NovaServiceProvider', true]),
5454
$this->nativeClassExistsMethodCall(['Laravel\Nova\NovaServiceProvider', true]),
55-
$this->nativeUcwordsMethodCall(['vfs:\\\\root\\app\\Nova\\PostResource', '\\'], 'App\Nova\PostResource'),
5655
$this->nativeIsSubClassOfMethodCall(['App\Nova\PostResource', 'Laravel\\Nova\\Resource']),
5756
$this->nativeClassExistsMethodCall(['RonasIT\Support\Tests\Support\Command\Models\Post', true]),
5857
);
@@ -79,7 +78,6 @@ public function mockGeneratorSubFolders(): void
7978
$this->nativeClassExistsMethodCall(['RonasIT\Support\Tests\Support\Command\Models\Forum\Post', true]),
8079
$this->nativeClassExistsMethodCall(['Laravel\Nova\NovaServiceProvider', true]),
8180
$this->nativeClassExistsMethodCall(['Laravel\Nova\NovaServiceProvider', true]),
82-
$this->nativeUcwordsMethodCall(['vfs:\\\\root\\app\\Nova\\Forum\\PostResource', '\\'], 'App\Nova\Forum\PostResource'),
8381
$this->nativeIsSubClassOfMethodCall(['App\Nova\Forum\PostResource', 'Laravel\\Nova\\Resource']),
8482
$this->nativeClassExistsMethodCall(['RonasIT\Support\Tests\Support\Command\Models\Forum\Post', true]),
8583
);
@@ -89,9 +87,4 @@ public function nativeIsSubClassOfMethodCall(array $arguments, bool $result = tr
8987
{
9088
return $this->functionCall('is_subclass_of', $arguments, $result);
9189
}
92-
93-
public function nativeUcwordsMethodCall(array $arguments, string $result): array
94-
{
95-
return $this->functionCall('ucwords', $arguments, $result);
96-
}
97-
}
90+
}

0 commit comments

Comments
 (0)