Skip to content

Commit 8205f58

Browse files
committed
test(tests): Improve autoload class retrieval in Pest
- Add a function `classes()` to retrieve autoloaded class names. - Utilize `ClassLoader` to target specific autoload functions. - Enhance testability by ensuring all loaded classes can be accessed easily.
1 parent d5b3059 commit 8205f58

File tree

3 files changed

+19
-5
lines changed

3 files changed

+19
-5
lines changed

.ai-commit.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"diff_options": [
33
":!*-lock.json",
44
":!*.lock",
5-
":!/baselines/*.neon",
6-
":!*.sum"
5+
":!*.sum",
6+
":!/baselines/*.neon"
77
]
88
}

tests/Foundation/Concerns/HasOptionsTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,5 +103,7 @@ public function normalizers(): array
103103
expect($message['foo'])->toBe('baz');
104104

105105
unset($message['foo']);
106+
107+
/** @noinspection PhpConditionAlreadyCheckedInspection */
106108
expect(isset($message['foo']))->toBeFalse();
107109
})->group(__DIR__, __FILE__);

tests/Pest.php

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,7 @@
22

33
/** @noinspection AnonymousFunctionStaticInspection */
44
/** @noinspection PhpInternalEntityUsedInspection */
5-
/** @noinspection PhpUndefinedClassInspection */
6-
/** @noinspection PhpUnused */
75
/** @noinspection StaticClosureCanBeUsedInspection */
8-
/** @noinspection VirtualTypeCheckInspection */
96

107
declare(strict_types=1);
118

@@ -18,13 +15,15 @@
1815
* @see https://github.com/guanguans/notify
1916
*/
2017

18+
use Composer\Autoload\ClassLoader;
2119
use Faker\Factory;
2220
use Faker\Generator;
2321
use Guanguans\Notify\Foundation\Client;
2422
use Guanguans\Notify\Foundation\Message;
2523
use Guanguans\NotifyTests\TestCase;
2624
use GuzzleHttp\Handler\MockHandler;
2725
use GuzzleHttp\Psr7\Response;
26+
use Illuminate\Support\Collection;
2827
use Pest\Expectation;
2928
use Psr\Http\Message\ResponseInterface;
3029

@@ -93,6 +92,19 @@
9392
|
9493
*/
9594

95+
function classes(): Collection
96+
{
97+
return collect(spl_autoload_functions())
98+
->pipe(static fn (Collection $splAutoloadFunctions): Collection => collect(
99+
$splAutoloadFunctions
100+
->firstOrFail(
101+
static fn (mixed $loader): bool => \is_array($loader) && $loader[0] instanceof ClassLoader
102+
)[0]
103+
->getClassMap()
104+
))
105+
->keys();
106+
}
107+
96108
/**
97109
* @throws ReflectionException
98110
*/

0 commit comments

Comments
 (0)