Skip to content

Commit 3fb0d02

Browse files
committed
fix: non-vendor namespaces with directories
1 parent adcd49b commit 3fb0d02

2 files changed

Lines changed: 27 additions & 4 deletions

File tree

src/Support/Composer.php

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,22 @@ public static function userNamespaces(): array
2828
* @return array<string, string>
2929
*/
3030
public static function userNamespacesWithDirectories(): array
31+
{
32+
$rootPath = TestSuite::getInstance()->rootPath.DIRECTORY_SEPARATOR;
33+
34+
return array_filter(
35+
self::allNamespacesWithDirectories(),
36+
static fn (string $namespace, string $directory): bool => ! str_starts_with($directory, $rootPath.'tests') || str_ends_with($directory, 'pest-plugin-arch'.DIRECTORY_SEPARATOR.'tests'),
37+
ARRAY_FILTER_USE_BOTH,
38+
);
39+
}
40+
41+
/**
42+
* Gets the map of directories to namespaces for all non-vendor PSR-4 entries.
43+
*
44+
* @return array<string, string>
45+
*/
46+
public static function allNamespacesWithDirectories(): array
3147
{
3248
$namespaces = [];
3349

@@ -45,10 +61,6 @@ public static function userNamespacesWithDirectories(): array
4561
continue;
4662
}
4763

48-
if (str_starts_with($directory, $rootPath.'tests') && ! str_ends_with($directory, 'pest-plugin-arch'.DIRECTORY_SEPARATOR.'tests')) {
49-
continue;
50-
}
51-
5264
$namespaces[$directory] = rtrim($namespace, '\\');
5365
}
5466
}

tests/Composer.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,14 @@
1818
->and(array_values($namespaces))->toContain('Tests')
1919
->and($namespaces)->each(fn ($namespace, $directory) => expect($directory)->toBeDirectory());
2020
});
21+
22+
it('retrieves all non-vendor namespaces with directories', function () {
23+
$all = Composer::allNamespacesWithDirectories();
24+
$user = Composer::userNamespacesWithDirectories();
25+
26+
expect($all)->toBeArray()
27+
->and(array_values($all))->toContain('Pest\Arch')
28+
->and(array_values($all))->toContain('Tests')
29+
->and($all)->each(fn ($namespace, $directory) => expect($directory)->toBeDirectory())
30+
->and(array_keys($user))->each(fn ($directory) => expect($all)->toHaveKey($directory->value));
31+
});

0 commit comments

Comments
 (0)