Skip to content

Commit 78f73d3

Browse files
committed
refactor(testing): add ApplicationContract and Router type hints
Add proper type hints following existing codebase conventions: - Use `ApplicationContract` alias for contract type hints - Use `Router` type hints for route definition methods - Update all contracts, attributes, traits, and test files This improves type safety while maintaining consistency with the existing codebase pattern where 20+ files use the ApplicationContract alias convention.
1 parent e91a8da commit 78f73d3

22 files changed

+59
-72
lines changed

src/foundation/src/Testing/Attributes/DefineDatabase.php

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
use Attribute;
88
use Closure;
9+
use Hypervel\Foundation\Contracts\Application as ApplicationContract;
910
use Hypervel\Foundation\Testing\Contracts\Attributes\Actionable;
1011
use Hypervel\Foundation\Testing\Contracts\Attributes\AfterEach;
1112
use Hypervel\Foundation\Testing\Contracts\Attributes\BeforeEach;
@@ -26,31 +27,26 @@ public function __construct(
2627

2728
/**
2829
* Handle the attribute before each test.
29-
*
30-
* @param \Hypervel\Foundation\Contracts\Application $app
3130
*/
32-
public function beforeEach($app): void
31+
public function beforeEach(ApplicationContract $app): void
3332
{
3433
ResetRefreshDatabaseState::run();
3534
}
3635

3736
/**
3837
* Handle the attribute after each test.
39-
*
40-
* @param \Hypervel\Foundation\Contracts\Application $app
4138
*/
42-
public function afterEach($app): void
39+
public function afterEach(ApplicationContract $app): void
4340
{
4441
ResetRefreshDatabaseState::run();
4542
}
4643

4744
/**
4845
* Handle the attribute.
4946
*
50-
* @param \Hypervel\Foundation\Contracts\Application $app
5147
* @param Closure(string, array<int, mixed>):void $action
5248
*/
53-
public function handle($app, Closure $action): ?Closure
49+
public function handle(ApplicationContract $app, Closure $action): ?Closure
5450
{
5551
$resolver = function () use ($app, $action) {
5652
\call_user_func($action, $this->method, [$app]);

src/foundation/src/Testing/Attributes/DefineEnvironment.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
use Attribute;
88
use Closure;
9+
use Hypervel\Foundation\Contracts\Application as ApplicationContract;
910
use Hypervel\Foundation\Testing\Contracts\Attributes\Actionable;
1011

1112
/**
@@ -22,10 +23,9 @@ public function __construct(
2223
/**
2324
* Handle the attribute.
2425
*
25-
* @param \Hypervel\Foundation\Contracts\Application $app
2626
* @param Closure(string, array<int, mixed>):void $action
2727
*/
28-
public function handle($app, Closure $action): mixed
28+
public function handle(ApplicationContract $app, Closure $action): mixed
2929
{
3030
\call_user_func($action, $this->method, [$app]);
3131

src/foundation/src/Testing/Attributes/DefineRoute.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
use Attribute;
88
use Closure;
9+
use Hypervel\Foundation\Contracts\Application as ApplicationContract;
910
use Hypervel\Foundation\Testing\Contracts\Attributes\Actionable;
1011
use Hypervel\Router\Router;
1112

@@ -23,10 +24,9 @@ public function __construct(
2324
/**
2425
* Handle the attribute.
2526
*
26-
* @param \Hypervel\Foundation\Contracts\Application $app
2727
* @param Closure(string, array<int, mixed>):void $action
2828
*/
29-
public function handle($app, Closure $action): mixed
29+
public function handle(ApplicationContract $app, Closure $action): mixed
3030
{
3131
$router = $app->get(Router::class);
3232

src/foundation/src/Testing/Attributes/RequiresEnv.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
use Attribute;
88
use Closure;
9+
use Hypervel\Foundation\Contracts\Application as ApplicationContract;
910
use Hypervel\Foundation\Testing\Contracts\Attributes\Actionable;
1011

1112
/**
@@ -23,10 +24,9 @@ public function __construct(
2324
/**
2425
* Handle the attribute.
2526
*
26-
* @param \Hypervel\Foundation\Contracts\Application $app
2727
* @param Closure(string, array<int, mixed>):void $action
2828
*/
29-
public function handle($app, Closure $action): mixed
29+
public function handle(ApplicationContract $app, Closure $action): mixed
3030
{
3131
$message = $this->message ?? "Missing required environment variable `{$this->key}`";
3232

src/foundation/src/Testing/Attributes/WithConfig.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
namespace Hypervel\Foundation\Testing\Attributes;
66

77
use Attribute;
8+
use Hypervel\Foundation\Contracts\Application as ApplicationContract;
89
use Hypervel\Foundation\Testing\Contracts\Attributes\Invokable;
910

1011
/**
@@ -21,10 +22,8 @@ public function __construct(
2122

2223
/**
2324
* Handle the attribute.
24-
*
25-
* @param \Hypervel\Foundation\Contracts\Application $app
2625
*/
27-
public function __invoke($app): mixed
26+
public function __invoke(ApplicationContract $app): mixed
2827
{
2928
$app->get('config')->set($this->key, $this->value);
3029

src/foundation/src/Testing/Attributes/WithMigration.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
use Attribute;
88
use Hyperf\Database\Migrations\Migrator;
9+
use Hypervel\Foundation\Contracts\Application as ApplicationContract;
910
use Hypervel\Foundation\Testing\Contracts\Attributes\Invokable;
1011

1112
/**
@@ -29,10 +30,8 @@ public function __construct(string ...$paths)
2930

3031
/**
3132
* Handle the attribute.
32-
*
33-
* @param \Hypervel\Foundation\Contracts\Application $app
3433
*/
35-
public function __invoke($app): mixed
34+
public function __invoke(ApplicationContract $app): mixed
3635
{
3736
$app->afterResolving(Migrator::class, function (Migrator $migrator) {
3837
foreach ($this->paths as $path) {

src/foundation/src/Testing/Concerns/HandlesAttributes.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace Hypervel\Foundation\Testing\Concerns;
66

7+
use Hypervel\Foundation\Contracts\Application as ApplicationContract;
78
use Hypervel\Foundation\Testing\Contracts\Attributes\Actionable;
89
use Hypervel\Foundation\Testing\Contracts\Attributes\Invokable;
910
use Hypervel\Foundation\Testing\Features\FeaturesCollection;
@@ -22,10 +23,9 @@ trait HandlesAttributes
2223
*
2324
* @internal
2425
*
25-
* @param \Hypervel\Foundation\Contracts\Application $app
2626
* @param class-string $attribute
2727
*/
28-
protected function parseTestMethodAttributes($app, string $attribute): FeaturesCollection
28+
protected function parseTestMethodAttributes(ApplicationContract $app, string $attribute): FeaturesCollection
2929
{
3030
$attributes = $this->resolvePhpUnitAttributes()
3131
->filter(static fn ($attributes, string $key) => $key === $attribute && ! empty($attributes))

src/foundation/src/Testing/Concerns/InteractsWithContainer.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,8 @@ protected function refreshApplication(): void
9898

9999
/**
100100
* Define environment setup.
101-
*
102-
* @param \Hypervel\Foundation\Contracts\Application $app
103101
*/
104-
protected function defineEnvironment($app): void
102+
protected function defineEnvironment(ApplicationContract $app): void
105103
{
106104
// Override in subclass.
107105
}

src/foundation/src/Testing/Contracts/Attributes/Actionable.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
namespace Hypervel\Foundation\Testing\Contracts\Attributes;
66

77
use Closure;
8+
use Hypervel\Foundation\Contracts\Application as ApplicationContract;
89

910
/**
1011
* Interface for attributes that handle actions via a callback.
@@ -14,8 +15,7 @@ interface Actionable extends TestingFeature
1415
/**
1516
* Handle the attribute.
1617
*
17-
* @param \Hypervel\Foundation\Contracts\Application $app
1818
* @param Closure(string, array<int, mixed>):void $action
1919
*/
20-
public function handle($app, Closure $action): mixed;
20+
public function handle(ApplicationContract $app, Closure $action): mixed;
2121
}

src/foundation/src/Testing/Contracts/Attributes/AfterEach.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@
44

55
namespace Hypervel\Foundation\Testing\Contracts\Attributes;
66

7+
use Hypervel\Foundation\Contracts\Application as ApplicationContract;
8+
79
/**
810
* Interface for attributes that run after each test.
911
*/
1012
interface AfterEach extends TestingFeature
1113
{
1214
/**
1315
* Handle the attribute.
14-
*
15-
* @param \Hypervel\Foundation\Contracts\Application $app
1616
*/
17-
public function afterEach($app): void;
17+
public function afterEach(ApplicationContract $app): void;
1818
}

0 commit comments

Comments
 (0)