Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
Signed-off-by: Mior Muhammad Zaki <crynobone@gmail.com>
  • Loading branch information
crynobone committed Dec 9, 2023
1 parent 501af8d commit 63e0e50
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 29 deletions.
20 changes: 9 additions & 11 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,15 @@
}
},
"scripts": {
"refacto": "@php vendor/bin/rector",
"lint": "@php vendor/bin/pint",
"test:refacto": "@refacto --dry-run",
"test:lint": "@lint --test",
"test:types": "@php vendor/bin/phpstan analyse --ansi",
"test:unit": "@php vendor/bin/pest --colors=always",
"test": [
"@test:refacto",
"@test:lint",
"@test:types",
"@test:unit"
"lint": [
"@php vendor/bin/rector",
"@php vendor/bin/phpstan analyse --ansi",
"@php vendor/bin/pint"
],
"test": "@php vendor/bin/pest --colors=always",
"ci": [
"@lint",
"@test"
]
},
"prefer-stable": true,
Expand Down
5 changes: 2 additions & 3 deletions src/Autoload.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ function defineDatabaseMigrations(Closure $callback): void
/**
* Define routes for the test case.
*
* @param \Closure(\Illuminate\Http\Router):void $callback
* @param \Closure(\Illuminate\Routing\Router):void $callback
*/
function defineRoute(Closure $callback): void
{
Expand All @@ -63,14 +63,13 @@ function defineRoute(Closure $callback): void
/**
* Define web routes for the test case.
*
* @param \Closure(\Illuminate\Http\Router):void $callback
* @param \Closure(\Illuminate\Routing\Router):void $callback
*/
function defineWebRoute(Closure $callback): void
{
Hook::create('@defineWebRoute', Backtrace::testFile(), $callback);
}


/**
* Define "afterApplicationCreated" hook for the test case.
*/
Expand Down
21 changes: 6 additions & 15 deletions src/Hook.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,14 @@
use Closure;

/**
* @phpstan-type TSetUpTearDownCallback \Closure():void
* @phpstan-type TCallback \Closure(TSetUpTearDownCallback):void
*
* @internal
*/
final class Hook
{
/**
* The cached hooks.
*
* @var array<string, \Closure|null>
*
* @phpstan-var array<string, TCallback|null>
* @var array<string, array<string, \Closure|null>>
*/
private static array $cachedHooks = [
'@setUp' => [],
Expand All @@ -30,21 +25,17 @@ final class Hook

/**
* Define a hook for Pest test file.
*
* @param (\Closure(\Closure):(void))|null $callback
*
* @phpstan-param TCallback|null $callback
*/
public static function create(string $type, string $fileOrMethod, Closure $callback = null): void
public static function create(string $type, string $fileOrMethod, ?Closure $callback = null): void
{
static::$cachedHooks[$type][$fileOrMethod] = $callback;
self::$cachedHooks[$type][$fileOrMethod] = $callback;
}

/**
* Resolve the "setUp" hook.
* Unpack the hook.
*/
public static function unpack(string $type, string $fileOrMethod, Closure $callback = null): ?Closure
public static function unpack(string $type, string $fileOrMethod, ?Closure $callback = null): ?Closure
{
return static::$cachedHooks[$type][$fileOrMethod] ?? $callback;
return self::$cachedHooks[$type][$fileOrMethod] ?? $callback;
}
}

0 comments on commit 63e0e50

Please sign in to comment.