File tree Expand file tree Collapse file tree 5 files changed +57
-14
lines changed Expand file tree Collapse file tree 5 files changed +57
-14
lines changed Original file line number Diff line number Diff line change 149149 'param_separator ' => ', ' ,
150150
151151 /**
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.
157155 */
158156 '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',
166159 ],
167160
168161 ],
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 1111use Illuminate \Support \Facades \Route ;
1212use Illuminate \Support \Str ;
1313use Leeovery \LaravelPlaywright \Exceptions \LaravelPlaywrightException ;
14+ use Leeovery \LaravelPlaywright \Playwright ;
1415use Throwable ;
1516
1617class LaravelPlaywrightController
@@ -309,7 +310,7 @@ protected function resolveStateAttributes($state): array
309310 */
310311 protected function resolveParamAlias (string $ alias ): callable
311312 {
312- $ paramAlias = data_get ( config ( ' laravel-playwright.factory.param_aliases ' ), $ alias );
313+ $ paramAlias = Playwright:: getAlias ( $ alias );
313314
314315 throw_if (is_null ($ paramAlias ),
315316 LaravelPlaywrightException::resolvedParamAliasDoesNotExist ($ alias )
Original file line number Diff line number Diff line change 66use Leeovery \LaravelPlaywright \Commands \Database \DropDatabaseCommand ;
77use Leeovery \LaravelPlaywright \Commands \LaravelPlaywrightEnvSetup ;
88use Leeovery \LaravelPlaywright \Commands \LaravelPlaywrightEnvTeardown ;
9+ use Spatie \LaravelPackageTools \Commands \InstallCommand ;
910use Spatie \LaravelPackageTools \Package ;
1011use Spatie \LaravelPackageTools \PackageServiceProvider as ServiceProvider ;
1112
@@ -17,11 +18,18 @@ public function configurePackage(Package $package): void
1718 ->name ('laravel-playwright ' )
1819 ->hasConfigFile ('laravel-playwright ' )
1920 ->hasRoute ('playwright ' )
21+ ->publishesServiceProvider ('LaravelPlaywrightServiceProvider ' )
2022 ->hasCommands (
2123 LaravelPlaywrightEnvSetup::class,
2224 LaravelPlaywrightEnvTeardown::class,
2325 CreateDatabaseCommand::class,
2426 DropDatabaseCommand::class,
25- );
27+ )
28+ ->hasInstallCommand (function (InstallCommand $ command ) {
29+ $ command
30+ ->publishConfigFile ()
31+ ->copyAndRegisterServiceProviderInApp ()
32+ ->askToStarRepoOnGitHub ('leeovery/laravel-playwright ' );
33+ });
2634 }
2735}
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