File tree 5 files changed +57
-14
lines changed
5 files changed +57
-14
lines changed Original file line number Diff line number Diff line change 149
149
'param_separator ' => ', ' ,
150
150
151
151
/**
152
- * You can optionally register aliases for models or other objects, rather than having
153
- * to provide the fully namespaced class name. You can then provide the alias
154
- * when creating entities via the factory endpoint. You can also define here a function
155
- * to instruct Laravel-Playwright how to construct an object with the parameters sent
156
- * from your Playwright test suite.
152
+ * You can optionally register aliases for models rather than having to provide the fully
153
+ * namespaced class name. You can then provide the alias when creating entities via the
154
+ * factory endpoint.
157
155
*/
158
156
'model_aliases ' => [
159
- // 'User' => 'App\\Models\\User',
160
- // 'Post' => 'App\\Models\\Post',
161
- ],
162
-
163
- 'param_aliases ' => [
164
- // 'Carbon' => fn($date) => \Carbon\Carbon::create($date),
165
- // 'collect' => fn($items) => collect(...$items),
157
+ // 'User' => '\App\Models\User::class',
158
+ // 'Post' => '\App\Models\Post::class',
166
159
],
167
160
168
161
],
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace App\Providers;
4
+
5
+ use Illuminate\Support\ServiceProvider;
6
+
7
+ class LaravelPlaywrightServiceProvider extends ServiceProvider
8
+ {
9
+ public function register()
10
+ {
11
+ //
12
+ }
13
+
14
+ public function boot()
15
+ {
16
+ // Playwright::alias('Carbon', fn(string $date) => \Carbon\Carbon::create($date));
17
+ // Playwright::alias('collect', fn($items) => collect(...$items));
18
+ }
19
+ }
Original file line number Diff line number Diff line change 11
11
use Illuminate \Support \Facades \Route ;
12
12
use Illuminate \Support \Str ;
13
13
use Leeovery \LaravelPlaywright \Exceptions \LaravelPlaywrightException ;
14
+ use Leeovery \LaravelPlaywright \Playwright ;
14
15
use Throwable ;
15
16
16
17
class LaravelPlaywrightController
@@ -309,7 +310,7 @@ protected function resolveStateAttributes($state): array
309
310
*/
310
311
protected function resolveParamAlias (string $ alias ): callable
311
312
{
312
- $ paramAlias = data_get ( config ( ' laravel-playwright.factory.param_aliases ' ), $ alias );
313
+ $ paramAlias = Playwright:: getAlias ( $ alias );
313
314
314
315
throw_if (is_null ($ paramAlias ),
315
316
LaravelPlaywrightException::resolvedParamAliasDoesNotExist ($ alias )
Original file line number Diff line number Diff line change 6
6
use Leeovery \LaravelPlaywright \Commands \Database \DropDatabaseCommand ;
7
7
use Leeovery \LaravelPlaywright \Commands \LaravelPlaywrightEnvSetup ;
8
8
use Leeovery \LaravelPlaywright \Commands \LaravelPlaywrightEnvTeardown ;
9
+ use Spatie \LaravelPackageTools \Commands \InstallCommand ;
9
10
use Spatie \LaravelPackageTools \Package ;
10
11
use Spatie \LaravelPackageTools \PackageServiceProvider as ServiceProvider ;
11
12
@@ -17,11 +18,18 @@ public function configurePackage(Package $package): void
17
18
->name ('laravel-playwright ' )
18
19
->hasConfigFile ('laravel-playwright ' )
19
20
->hasRoute ('playwright ' )
21
+ ->publishesServiceProvider ('LaravelPlaywrightServiceProvider ' )
20
22
->hasCommands (
21
23
LaravelPlaywrightEnvSetup::class,
22
24
LaravelPlaywrightEnvTeardown::class,
23
25
CreateDatabaseCommand::class,
24
26
DropDatabaseCommand::class,
25
- );
27
+ )
28
+ ->hasInstallCommand (function (InstallCommand $ command ) {
29
+ $ command
30
+ ->publishConfigFile ()
31
+ ->copyAndRegisterServiceProviderInApp ()
32
+ ->askToStarRepoOnGitHub ('leeovery/laravel-playwright ' );
33
+ });
26
34
}
27
35
}
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace Leeovery \LaravelPlaywright ;
4
+
5
+ use Closure ;
6
+
7
+ class Playwright
8
+ {
9
+ public static array $ aliasCallbacks = [];
10
+
11
+ public static function alias (string $ alias , Closure $ callable ): static
12
+ {
13
+ static ::$ aliasCallbacks [$ alias ] = $ callable ;
14
+
15
+ return new static ;
16
+ }
17
+
18
+ public static function getAlias (string $ alias ): callable |null
19
+ {
20
+ return data_get (static ::$ aliasCallbacks , $ alias );
21
+ }
22
+ }
You can’t perform that action at this time.
0 commit comments