From 111a41b2a823378500e2e0e52ea9a5be442922fe Mon Sep 17 00:00:00 2001 From: Mior Muhammad Zaki Date: Mon, 25 Nov 2024 07:56:21 +0800 Subject: [PATCH 1/5] wip Signed-off-by: Mior Muhammad Zaki --- bin/sync | 154 ++++++++++-------- composer.json | 7 +- laravel/artisan | 53 ++++++ laravel/config/app.php | 8 +- laravel/config/auth.php | 8 +- laravel/config/cache.php | 6 +- laravel/config/database.php | 8 +- laravel/config/hashing.php | 8 +- laravel/config/logging.php | 6 +- laravel/config/mail.php | 2 +- laravel/config/queue.php | 13 +- laravel/config/session.php | 12 +- src/Console/Commander.php | 28 ++-- src/Foundation/Application.php | 18 ++ .../resources/views/errors/418.blade.php | 1 + workbench/routes/web.php | 3 + 16 files changed, 212 insertions(+), 123 deletions(-) create mode 100644 laravel/artisan create mode 100644 src/Foundation/Application.php create mode 100644 workbench/resources/views/errors/418.blade.php diff --git a/bin/sync b/bin/sync index ababe189..f0494a89 100755 --- a/bin/sync +++ b/bin/sync @@ -7,8 +7,17 @@ require __DIR__.'/../vendor/autoload.php'; $files = new Illuminate\Filesystem\Filesystem(); -$files->delete("{$workingPath}/laravel/.env"); -$files->deleteDirectory("{$workingPath}/skeleton"); +$purgeSkeletonDirectories = static function () use ($files, $workingPath) { + $files->delete("{$workingPath}/laravel/.env"); + + $files->deleteDirectory("{$workingPath}/skeleton"); +}; + +function line(string $code, int $tab = 0): string { + return implode('', [PHP_EOL, str_repeat(' ', ($tab * 4)), $code]); +} + +$purgeSkeletonDirectories(); $files->copy("{$workingPath}/vendor/orchestra/testbench-core/laravel/bootstrap/app.php", "{$workingPath}/laravel/bootstrap/app.php"); $files->copy("{$workingPath}/vendor/orchestra/testbench-core/laravel/server.php", "{$workingPath}/laravel/server.php"); @@ -22,75 +31,86 @@ Symfony\Component\Process\Process::fromShellCommandline( 'composer create-project "laravel/laravel:9.x-dev" skeleton --no-scripts --no-plugins --quiet --no-install', $workingPath )->mustRun(); -Illuminate\Support\Collection::make([ - '.env.example', - 'config/*.php', - 'database/.gitignore', - 'database/migrations/2014_10_12_000000_create_users_table.php', - 'database/migrations/2014_10_12_100000_create_password_resets_table.php', - 'database/migrations/2019_08_19_000000_create_failed_jobs_table.php', - 'lang/en/*.php', - 'lang/*.json', - 'resources/views/*', - 'public/index.php', - 'tests/CreatesApplication.php', -])->transform(fn ($file) => "{$workingPath}/skeleton/{$file}") -->map(fn ($file) => str_contains($file, '*') ? [...$files->glob($file)] : $file) -->flatten() -->each(function ($file) use ($files, $workingPath) { - $files->copy($file, "{$workingPath}/laravel".Illuminate\Support\Str::after($file, "{$workingPath}/skeleton")); -}); -$files->delete("{$workingPath}/laravel/config/sanctum.php"); -$files->move("{$workingPath}/laravel/database/migrations/2014_10_12_000000_create_users_table.php", "{$workingPath}/laravel/migrations/2014_10_12_000000_testbench_create_users_table.php"); -$files->move("{$workingPath}/laravel/database/migrations/2014_10_12_100000_create_password_resets_table.php", "{$workingPath}/laravel/migrations/2014_10_12_100000_testbench_create_password_resets_table.php"); -$files->move("{$workingPath}/laravel/database/migrations/2019_08_19_000000_create_failed_jobs_table.php", "{$workingPath}/laravel/migrations/2019_08_19_000000_testbench_create_failed_jobs_table.php"); - -Illuminate\Support\Collection::make([ - 'cache/0001_01_01_000000_testbench_create_cache_table' => 'Cache/Console/stubs/cache.stub', - 'notifications/0001_01_01_000000_testbench_create_notifications_table' => 'Notifications/Console/stubs/notifications.stub', - 'queue/0001_01_01_000000_testbench_create_jobs_table' => 'Queue/Console/stubs/jobs.stub', - 'queue/0001_01_01_000000_testbench_create_job_batches_table' => 'Queue/Console/stubs/batches.stub', - // 'queue/0001_01_01_000000_testbench_create_failed_jobs_table' => 'Queue/Console/stubs/failed_jobs.stub', - 'session/0001_01_01_000000_testbench_create_sessions_table' => 'Session/Console/stubs/database.stub', -])->transform(fn ($file) => "{$workingPath}/vendor/laravel/framework/src/Illuminate/{$file}") -->each(function ($from, $to) use ($files, $workingPath) { - $files->copy($from, "{$workingPath}/laravel/migrations/{$to}.php"); -})->keys() -->push(...[ - '2014_10_12_000000_testbench_create_users_table', - '2014_10_12_100000_testbench_create_password_resets_table', - '2019_08_19_000000_testbench_create_failed_jobs_table', -])->each(function ($migration) use ($files, $workingPath) { - $files->replaceInFile('class Create', 'class TestbenchCreate', "{$workingPath}/laravel/migrations/{$migration}.php"); -})->filter(fn ($migration) => str_starts_with($migration, 'queue')) -->mapWithKeys(fn ($migration) => match ($migration) { - 'queue/0001_01_01_000000_testbench_create_jobs_table' => [$migration => 'jobs'], - 'queue/0001_01_01_000000_testbench_create_job_batches_table' => [$migration => 'job_batches'], - // 'queue/0001_01_01_000000_testbench_create_failed_jobs_table' => [$migration => 'failed_jobs'], -})->each(function ($table, $migration) use ($files, $workingPath) { - $files->replaceInFile(['{{tableClassName}}', '{{table}}'], [Illuminate\Support\Str::studly($table), $table], "{$workingPath}/laravel/migrations/{$migration}.php"); -}); - -transform([ - PHP_EOL.'APP_KEY=' => PHP_EOL.'APP_KEY=AckfSECXIvnK5r28GVIWUAxmbBSjTsmF', - PHP_EOL.'DB_CONNECTION=mysql' => PHP_EOL.'DB_CONNECTION=sqlite', - PHP_EOL.'DB_HOST=' => PHP_EOL.'# DB_HOST=', - PHP_EOL.'DB_PORT=' => PHP_EOL.'# DB_PORT=', - PHP_EOL.'DB_DATABASE=' => PHP_EOL.'# DB_DATABASE=', - PHP_EOL.'DB_USERNAME=' => PHP_EOL.'# DB_USERNAME=', - PHP_EOL.'DB_PASSWORD=' => PHP_EOL.'# DB_PASSWORD=', -], fn ($changes) => $files->replaceInFile(array_keys($changes), array_values($changes), "{$workingPath}/laravel/.env.example")); +require Orchestra\Testbench\join_paths($workingPath, 'vendor', 'orchestra', 'testbench-core', 'bin', 'configure-skeleton.php'); transform([ - "env('APP_ENV', 'production')" => "env('APP_ENV', 'testing')", - PHP_EOL.' App\Providers' => PHP_EOL.' // App\Providers', - PHP_EOL.' * Package Service Providers...' => PHP_EOL.' * Dusk Service Provider'.PHP_EOL.' */'.PHP_EOL.' Laravel\Dusk\DuskServiceProvider::class,'.PHP_EOL.PHP_EOL.' /*'.PHP_EOL.' * Package Service Providers...' + line('App\Providers', 2) => line('// App\Providers', 2), + line(' * Package Service Providers...', 2) => line(' * Dusk Service Provider', 2).line(' */', 2).line('Laravel\Dusk\DuskServiceProvider::class,', 2).PHP_EOL.line('/*', 2).line(' * Package Service Providers...', 2), ], fn ($changes) => $files->replaceInFile(array_keys($changes), array_values($changes), "{$workingPath}/laravel/config/app.php")); -transform([ - "'model' => App\Models\User::class" => "'model' => Illuminate\Foundation\Auth\User::class", -], fn ($changes) => $files->replaceInFile(array_keys($changes), array_values($changes), "{$workingPath}/laravel/config/auth.php")); +// Illuminate\Support\Collection::make([ +// '.env.example', +// 'config/*.php', +// 'database/.gitignore', +// 'database/migrations/2014_10_12_000000_create_users_table.php', +// 'database/migrations/2014_10_12_100000_create_password_resets_table.php', +// 'database/migrations/2019_08_19_000000_create_failed_jobs_table.php', +// 'lang/en/*.php', +// 'lang/*.json', +// 'resources/views/*', +// 'public/index.php', +// 'tests/CreatesApplication.php', +// ])->transform(fn ($file) => "{$workingPath}/skeleton/{$file}") +// ->map(fn ($file) => str_contains($file, '*') ? [...$files->glob($file)] : $file) +// ->flatten() +// ->each(function ($file) use ($files, $workingPath) { +// $files->copy($file, "{$workingPath}/laravel".Illuminate\Support\Str::after($file, "{$workingPath}/skeleton")); +// }); +// $files->delete("{$workingPath}/laravel/config/sanctum.php"); +// $files->move("{$workingPath}/laravel/database/migrations/2014_10_12_000000_create_users_table.php", "{$workingPath}/laravel/migrations/2014_10_12_000000_testbench_create_users_table.php"); +// $files->move("{$workingPath}/laravel/database/migrations/2014_10_12_100000_create_password_resets_table.php", "{$workingPath}/laravel/migrations/2014_10_12_100000_testbench_create_password_resets_table.php"); +// $files->move("{$workingPath}/laravel/database/migrations/2019_08_19_000000_create_failed_jobs_table.php", "{$workingPath}/laravel/migrations/2019_08_19_000000_testbench_create_failed_jobs_table.php"); + +// Illuminate\Support\Collection::make([ +// 'cache/0001_01_01_000000_testbench_create_cache_table' => 'Cache/Console/stubs/cache.stub', +// 'notifications/0001_01_01_000000_testbench_create_notifications_table' => 'Notifications/Console/stubs/notifications.stub', +// 'queue/0001_01_01_000000_testbench_create_jobs_table' => 'Queue/Console/stubs/jobs.stub', +// 'queue/0001_01_01_000000_testbench_create_job_batches_table' => 'Queue/Console/stubs/batches.stub', +// // 'queue/0001_01_01_000000_testbench_create_failed_jobs_table' => 'Queue/Console/stubs/failed_jobs.stub', +// 'session/0001_01_01_000000_testbench_create_sessions_table' => 'Session/Console/stubs/database.stub', +// ])->transform(fn ($file) => "{$workingPath}/vendor/laravel/framework/src/Illuminate/{$file}") +// ->each(function ($from, $to) use ($files, $workingPath) { +// $files->copy($from, "{$workingPath}/laravel/migrations/{$to}.php"); +// })->keys() +// ->push(...[ +// '2014_10_12_000000_testbench_create_users_table', +// '2014_10_12_100000_testbench_create_password_resets_table', +// '2019_08_19_000000_testbench_create_failed_jobs_table', +// ])->each(function ($migration) use ($files, $workingPath) { +// $files->replaceInFile('class Create', 'class TestbenchCreate', "{$workingPath}/laravel/migrations/{$migration}.php"); +// })->filter(fn ($migration) => str_starts_with($migration, 'queue')) +// ->mapWithKeys(fn ($migration) => match ($migration) { +// 'queue/0001_01_01_000000_testbench_create_jobs_table' => [$migration => 'jobs'], +// 'queue/0001_01_01_000000_testbench_create_job_batches_table' => [$migration => 'job_batches'], +// // 'queue/0001_01_01_000000_testbench_create_failed_jobs_table' => [$migration => 'failed_jobs'], +// })->each(function ($table, $migration) use ($files, $workingPath) { +// $files->replaceInFile(['{{tableClassName}}', '{{table}}'], [Illuminate\Support\Str::studly($table), $table], "{$workingPath}/laravel/migrations/{$migration}.php"); +// }); + +// transform([ +// line('APP_KEY=') => line('APP_KEY=AckfSECXIvnK5r28GVIWUAxmbBSjTsmF'), +// line('DB_CONNECTION=mysql') => line('DB_CONNECTION=sqlite'), +// line('DB_HOST=') => line('# DB_HOST='), +// line('DB_PORT=') => line('# DB_PORT='), +// line('DB_DATABASE=') => line('# DB_DATABASE='), +// line('DB_USERNAME=') => line('# DB_USERNAME='), +// line('DB_PASSWORD=') => line('# DB_PASSWORD='), +// ], fn ($changes) => $files->replaceInFile(array_keys($changes), array_values($changes), "{$workingPath}/laravel/.env.example")); + +// transform([ +// line("'env' => env('APP_ENV', 'production'),", 1) => line("'env' => env('APP_ENV', 'workbench'),", 1), +// line("'timezone' => 'UTC',", 1) => line("'timezone' => env('APP_TIMEZONE', 'UTC'),", 1), +// line("'locale' => 'en',", 1) => line("'locale' => env('APP_LOCALE', 'en'),", 1), +// line("'fallback_locale' => 'en',", 1) => line("'fallback_locale' => env('APP_FALLBACK_LOCALE', 'en'),", 1), +// line('App\Providers', 2) => line('// App\Providers', 2), +// PHP_EOL.' App\Providers' => PHP_EOL.' // App\Providers', +// PHP_EOL.' * Package Service Providers...' => PHP_EOL.' * Dusk Service Provider'.PHP_EOL.' */'.PHP_EOL.' Laravel\Dusk\DuskServiceProvider::class,'.PHP_EOL.PHP_EOL.' /*'.PHP_EOL.' * Package Service Providers...' +// ], fn ($changes) => $files->replaceInFile(array_keys($changes), array_values($changes), "{$workingPath}/laravel/config/app.php")); + +// transform([ +// "'model' => App\Models\User::class" => "'model' => Illuminate\Foundation\Auth\User::class", +// ], fn ($changes) => $files->replaceInFile(array_keys($changes), array_values($changes), "{$workingPath}/laravel/config/auth.php")); $files->copy("{$workingPath}/vendor/laravel/dusk/stubs/phpunit.xml", "{$workingPath}/stubs/phpunit.xml"); -$files->deleteDirectory("{$workingPath}/skeleton"); +$purgeSkeletonDirectories(); diff --git a/composer.json b/composer.json index ea52d3e3..de69a2a6 100644 --- a/composer.json +++ b/composer.json @@ -41,9 +41,10 @@ "laravel/dusk": "^7.13", "laravel/serializable-closure": "^1.3", "orchestra/dusk-updater": "^1.10 || ^2.6", - "orchestra/testbench": "^7.47", - "orchestra/testbench-core": "^7.48", - "php-webdriver/webdriver": "^1.9" + "orchestra/testbench": "^7.48", + "orchestra/testbench-core": "^7.49", + "php-webdriver/webdriver": "^1.9", + "symfony/polyfill-php83": "^1.31" }, "require-dev": { "laravel/pint": "^1.4", diff --git a/laravel/artisan b/laravel/artisan new file mode 100644 index 00000000..67a3329b --- /dev/null +++ b/laravel/artisan @@ -0,0 +1,53 @@ +#!/usr/bin/env php +make(Illuminate\Contracts\Console\Kernel::class); + +$status = $kernel->handle( + $input = new Symfony\Component\Console\Input\ArgvInput, + new Symfony\Component\Console\Output\ConsoleOutput +); + +/* +|-------------------------------------------------------------------------- +| Shutdown The Application +|-------------------------------------------------------------------------- +| +| Once Artisan has finished running, we will fire off the shutdown events +| so that any final work may be done by the application before we shut +| down the process. This is the last thing to happen to the request. +| +*/ + +$kernel->terminate($input, $status); + +exit($status); diff --git a/laravel/config/app.php b/laravel/config/app.php index 6935092f..6fa78201 100644 --- a/laravel/config/app.php +++ b/laravel/config/app.php @@ -28,7 +28,7 @@ | */ - 'env' => env('APP_ENV', 'testing'), + 'env' => env('APP_ENV', 'workbench'), /* |-------------------------------------------------------------------------- @@ -69,7 +69,7 @@ | */ - 'timezone' => 'UTC', + 'timezone' => env('APP_TIMEZONE', 'UTC'), /* |-------------------------------------------------------------------------- @@ -82,7 +82,7 @@ | */ - 'locale' => 'en', + 'locale' => env('APP_LOCALE', 'en'), /* |-------------------------------------------------------------------------- @@ -95,7 +95,7 @@ | */ - 'fallback_locale' => 'en', + 'fallback_locale' => env('APP_FALLBACK_LOCALE', 'en'), /* |-------------------------------------------------------------------------- diff --git a/laravel/config/auth.php b/laravel/config/auth.php index 03dd0ae6..6199c4fe 100644 --- a/laravel/config/auth.php +++ b/laravel/config/auth.php @@ -14,8 +14,8 @@ */ 'defaults' => [ - 'guard' => 'web', - 'passwords' => 'users', + 'guard' => env('AUTH_GUARD', 'web'), + 'passwords' => env('AUTH_PASSWORD_BROKER', 'users'), ], /* @@ -62,7 +62,7 @@ 'providers' => [ 'users' => [ 'driver' => 'eloquent', - 'model' => Illuminate\Foundation\Auth\User::class, + 'model' => env('AUTH_MODEL', Illuminate\Foundation\Auth\User::class), ], // 'users' => [ @@ -110,6 +110,6 @@ | */ - 'password_timeout' => 10800, + 'password_timeout' => env('AUTH_PASSWORD_TIMEOUT', 10800), ]; diff --git a/laravel/config/cache.php b/laravel/config/cache.php index 33bb2954..53b56100 100644 --- a/laravel/config/cache.php +++ b/laravel/config/cache.php @@ -44,9 +44,9 @@ 'database' => [ 'driver' => 'database', - 'table' => 'cache', - 'connection' => null, - 'lock_connection' => null, + 'table' => env('DB_CACHE_TABLE', 'cache'), + 'connection' => env('DB_CACHE_CONNECTION'), + 'lock_connection' => env('DB_CACHE_LOCK_CONNECTION'), ], 'file' => [ diff --git a/laravel/config/database.php b/laravel/config/database.php index 137ad18c..e64d4bbb 100644 --- a/laravel/config/database.php +++ b/laravel/config/database.php @@ -52,8 +52,8 @@ 'username' => env('DB_USERNAME', 'forge'), 'password' => env('DB_PASSWORD', ''), 'unix_socket' => env('DB_SOCKET', ''), - 'charset' => 'utf8mb4', - 'collation' => 'utf8mb4_unicode_ci', + 'charset' => env('DB_CHARSET', 'utf8mb4'), + 'collation' => env('DB_COLLATION', 'utf8mb4_unicode_ci'), 'prefix' => '', 'prefix_indexes' => true, 'strict' => true, @@ -71,7 +71,7 @@ 'database' => env('DB_DATABASE', 'forge'), 'username' => env('DB_USERNAME', 'forge'), 'password' => env('DB_PASSWORD', ''), - 'charset' => 'utf8', + 'charset' => env('DB_CHARSET', 'utf8'), 'prefix' => '', 'prefix_indexes' => true, 'search_path' => 'public', @@ -86,7 +86,7 @@ 'database' => env('DB_DATABASE', 'forge'), 'username' => env('DB_USERNAME', 'forge'), 'password' => env('DB_PASSWORD', ''), - 'charset' => 'utf8', + 'charset' => env('DB_CHARSET', 'utf8'), 'prefix' => '', 'prefix_indexes' => true, // 'encrypt' => env('DB_ENCRYPT', 'yes'), diff --git a/laravel/config/hashing.php b/laravel/config/hashing.php index bcd3be4c..ab5e451d 100644 --- a/laravel/config/hashing.php +++ b/laravel/config/hashing.php @@ -15,7 +15,7 @@ | */ - 'driver' => 'bcrypt', + 'driver' => env('HASH_DRIVER', 'bcrypt'), /* |-------------------------------------------------------------------------- @@ -44,9 +44,9 @@ */ 'argon' => [ - 'memory' => 65536, - 'threads' => 1, - 'time' => 4, + 'memory' => env('ARGON_MEMORY', 65536), + 'threads' => env('ARGON_THREADS', 1), + 'time' => env('ARGON_TIME', 4), ], ]; diff --git a/laravel/config/logging.php b/laravel/config/logging.php index 5aa1dbb7..d7f11ca7 100644 --- a/laravel/config/logging.php +++ b/laravel/config/logging.php @@ -32,7 +32,7 @@ 'deprecations' => [ 'channel' => env('LOG_DEPRECATIONS_CHANNEL', 'null'), - 'trace' => false, + 'trace' => env('LOG_DEPRECATIONS_TRACE', false), ], /* @@ -53,7 +53,7 @@ 'channels' => [ 'stack' => [ 'driver' => 'stack', - 'channels' => ['single'], + 'channels' => explode(',', env('LOG_STACK', 'single')), 'ignore_exceptions' => false, ], @@ -67,7 +67,7 @@ 'driver' => 'daily', 'path' => storage_path('logs/laravel.log'), 'level' => env('LOG_LEVEL', 'debug'), - 'days' => 14, + 'days' => env('LOG_DAILY_DAYS', 14), ], 'slack' => [ diff --git a/laravel/config/mail.php b/laravel/config/mail.php index 534395a3..68f4b555 100644 --- a/laravel/config/mail.php +++ b/laravel/config/mail.php @@ -108,7 +108,7 @@ */ 'markdown' => [ - 'theme' => 'default', + 'theme' => env('MAIL_MARKDOWN_THEME', 'default'), 'paths' => [ resource_path('views/vendor/mail'), diff --git a/laravel/config/queue.php b/laravel/config/queue.php index 25ea5a81..6232736d 100644 --- a/laravel/config/queue.php +++ b/laravel/config/queue.php @@ -36,17 +36,18 @@ 'database' => [ 'driver' => 'database', - 'table' => 'jobs', - 'queue' => 'default', - 'retry_after' => 90, + 'connection' => env('DB_QUEUE_CONNECTION'), + 'table' => env('DB_QUEUE_TABLE', 'jobs'), + 'queue' => env('DB_QUEUE', 'default'), + 'retry_after' => (int) env('DB_QUEUE_RETRY_AFTER', 90), 'after_commit' => false, ], 'beanstalkd' => [ 'driver' => 'beanstalkd', - 'host' => 'localhost', - 'queue' => 'default', - 'retry_after' => 90, + 'host' => env('BEANSTALKD_QUEUE_HOST', 'localhost'), + 'queue' => env('BEANSTALKD_QUEUE', 'default'), + 'retry_after' => (int) env('BEANSTALKD_QUEUE_RETRY_AFTER', 90), 'block_for' => 0, 'after_commit' => false, ], diff --git a/laravel/config/session.php b/laravel/config/session.php index 8fed97c0..e7d8563b 100644 --- a/laravel/config/session.php +++ b/laravel/config/session.php @@ -33,7 +33,7 @@ 'lifetime' => env('SESSION_LIFETIME', 120), - 'expire_on_close' => false, + 'expire_on_close' => env('SESSION_EXPIRE_ON_CLOSE', false), /* |-------------------------------------------------------------------------- @@ -46,7 +46,7 @@ | */ - 'encrypt' => false, + 'encrypt' => env('SESSION_ENCRYPT', false), /* |-------------------------------------------------------------------------- @@ -85,7 +85,7 @@ | */ - 'table' => 'sessions', + 'table' => env('SESSION_TABLE', 'sessions'), /* |-------------------------------------------------------------------------- @@ -142,7 +142,7 @@ | */ - 'path' => '/', + 'path' => env('SESSION_PATH', '/'), /* |-------------------------------------------------------------------------- @@ -181,7 +181,7 @@ | */ - 'http_only' => true, + 'http_only' => env('SESSION_HTTP_ONLY', true), /* |-------------------------------------------------------------------------- @@ -196,6 +196,6 @@ | */ - 'same_site' => 'lax', + 'same_site' => env('SESSION_SAME_SITE', 'lax'), ]; diff --git a/src/Console/Commander.php b/src/Console/Commander.php index 250542d7..8caf1486 100644 --- a/src/Console/Commander.php +++ b/src/Console/Commander.php @@ -2,12 +2,10 @@ namespace Orchestra\Testbench\Dusk\Console; -use Orchestra\Testbench\Console\Commander as Testbench; +use Orchestra\Testbench\Dusk\Foundation\Application as Testbench; use Orchestra\Testbench\Dusk\Foundation\TestbenchServiceProvider; -use function Orchestra\Testbench\Dusk\default_skeleton_path; - -class Commander extends Testbench +class Commander extends \Orchestra\Testbench\Console\Commander { /** * The environment file name. @@ -17,24 +15,18 @@ class Commander extends Testbench protected $environmentFile = '.env.dusk'; /** - * Resolve application implementation. + * The testbench implementation class. * - * @return \Closure(\Illuminate\Foundation\Application):void + * @var class-string<\Orchestra\Testbench\Foundation\Application> */ - protected function resolveApplicationCallback() - { - return static function ($app) { - $app->register(TestbenchServiceProvider::class); - }; - } + protected static string $testbench = Testbench::class; /** - * Get Application base path. + * List of providers. * - * @return string + * @var array> */ - public static function applicationBasePath() - { - return $_ENV['APP_BASE_PATH'] ?? default_skeleton_path(); - } + protected array $providers = [ + TestbenchServiceProvider::class, + ]; } diff --git a/src/Foundation/Application.php b/src/Foundation/Application.php new file mode 100644 index 00000000..70627972 --- /dev/null +++ b/src/Foundation/Application.php @@ -0,0 +1,18 @@ +name('testbench'); Route::text('/hello-world', 'Hello world'); +Route::get('/root', function () { + abort(418); +}); From 3e3dedc204878139fe72d28b40ab54fce1a7a7c7 Mon Sep 17 00:00:00 2001 From: Mior Muhammad Zaki Date: Mon, 25 Nov 2024 07:57:40 +0800 Subject: [PATCH 2/5] wip Signed-off-by: Mior Muhammad Zaki --- bin/sync | 73 ---------------------------------- src/Foundation/Application.php | 2 +- 2 files changed, 1 insertion(+), 74 deletions(-) diff --git a/bin/sync b/bin/sync index f0494a89..776dee1a 100755 --- a/bin/sync +++ b/bin/sync @@ -38,79 +38,6 @@ transform([ line(' * Package Service Providers...', 2) => line(' * Dusk Service Provider', 2).line(' */', 2).line('Laravel\Dusk\DuskServiceProvider::class,', 2).PHP_EOL.line('/*', 2).line(' * Package Service Providers...', 2), ], fn ($changes) => $files->replaceInFile(array_keys($changes), array_values($changes), "{$workingPath}/laravel/config/app.php")); -// Illuminate\Support\Collection::make([ -// '.env.example', -// 'config/*.php', -// 'database/.gitignore', -// 'database/migrations/2014_10_12_000000_create_users_table.php', -// 'database/migrations/2014_10_12_100000_create_password_resets_table.php', -// 'database/migrations/2019_08_19_000000_create_failed_jobs_table.php', -// 'lang/en/*.php', -// 'lang/*.json', -// 'resources/views/*', -// 'public/index.php', -// 'tests/CreatesApplication.php', -// ])->transform(fn ($file) => "{$workingPath}/skeleton/{$file}") -// ->map(fn ($file) => str_contains($file, '*') ? [...$files->glob($file)] : $file) -// ->flatten() -// ->each(function ($file) use ($files, $workingPath) { -// $files->copy($file, "{$workingPath}/laravel".Illuminate\Support\Str::after($file, "{$workingPath}/skeleton")); -// }); -// $files->delete("{$workingPath}/laravel/config/sanctum.php"); -// $files->move("{$workingPath}/laravel/database/migrations/2014_10_12_000000_create_users_table.php", "{$workingPath}/laravel/migrations/2014_10_12_000000_testbench_create_users_table.php"); -// $files->move("{$workingPath}/laravel/database/migrations/2014_10_12_100000_create_password_resets_table.php", "{$workingPath}/laravel/migrations/2014_10_12_100000_testbench_create_password_resets_table.php"); -// $files->move("{$workingPath}/laravel/database/migrations/2019_08_19_000000_create_failed_jobs_table.php", "{$workingPath}/laravel/migrations/2019_08_19_000000_testbench_create_failed_jobs_table.php"); - -// Illuminate\Support\Collection::make([ -// 'cache/0001_01_01_000000_testbench_create_cache_table' => 'Cache/Console/stubs/cache.stub', -// 'notifications/0001_01_01_000000_testbench_create_notifications_table' => 'Notifications/Console/stubs/notifications.stub', -// 'queue/0001_01_01_000000_testbench_create_jobs_table' => 'Queue/Console/stubs/jobs.stub', -// 'queue/0001_01_01_000000_testbench_create_job_batches_table' => 'Queue/Console/stubs/batches.stub', -// // 'queue/0001_01_01_000000_testbench_create_failed_jobs_table' => 'Queue/Console/stubs/failed_jobs.stub', -// 'session/0001_01_01_000000_testbench_create_sessions_table' => 'Session/Console/stubs/database.stub', -// ])->transform(fn ($file) => "{$workingPath}/vendor/laravel/framework/src/Illuminate/{$file}") -// ->each(function ($from, $to) use ($files, $workingPath) { -// $files->copy($from, "{$workingPath}/laravel/migrations/{$to}.php"); -// })->keys() -// ->push(...[ -// '2014_10_12_000000_testbench_create_users_table', -// '2014_10_12_100000_testbench_create_password_resets_table', -// '2019_08_19_000000_testbench_create_failed_jobs_table', -// ])->each(function ($migration) use ($files, $workingPath) { -// $files->replaceInFile('class Create', 'class TestbenchCreate', "{$workingPath}/laravel/migrations/{$migration}.php"); -// })->filter(fn ($migration) => str_starts_with($migration, 'queue')) -// ->mapWithKeys(fn ($migration) => match ($migration) { -// 'queue/0001_01_01_000000_testbench_create_jobs_table' => [$migration => 'jobs'], -// 'queue/0001_01_01_000000_testbench_create_job_batches_table' => [$migration => 'job_batches'], -// // 'queue/0001_01_01_000000_testbench_create_failed_jobs_table' => [$migration => 'failed_jobs'], -// })->each(function ($table, $migration) use ($files, $workingPath) { -// $files->replaceInFile(['{{tableClassName}}', '{{table}}'], [Illuminate\Support\Str::studly($table), $table], "{$workingPath}/laravel/migrations/{$migration}.php"); -// }); - -// transform([ -// line('APP_KEY=') => line('APP_KEY=AckfSECXIvnK5r28GVIWUAxmbBSjTsmF'), -// line('DB_CONNECTION=mysql') => line('DB_CONNECTION=sqlite'), -// line('DB_HOST=') => line('# DB_HOST='), -// line('DB_PORT=') => line('# DB_PORT='), -// line('DB_DATABASE=') => line('# DB_DATABASE='), -// line('DB_USERNAME=') => line('# DB_USERNAME='), -// line('DB_PASSWORD=') => line('# DB_PASSWORD='), -// ], fn ($changes) => $files->replaceInFile(array_keys($changes), array_values($changes), "{$workingPath}/laravel/.env.example")); - -// transform([ -// line("'env' => env('APP_ENV', 'production'),", 1) => line("'env' => env('APP_ENV', 'workbench'),", 1), -// line("'timezone' => 'UTC',", 1) => line("'timezone' => env('APP_TIMEZONE', 'UTC'),", 1), -// line("'locale' => 'en',", 1) => line("'locale' => env('APP_LOCALE', 'en'),", 1), -// line("'fallback_locale' => 'en',", 1) => line("'fallback_locale' => env('APP_FALLBACK_LOCALE', 'en'),", 1), -// line('App\Providers', 2) => line('// App\Providers', 2), -// PHP_EOL.' App\Providers' => PHP_EOL.' // App\Providers', -// PHP_EOL.' * Package Service Providers...' => PHP_EOL.' * Dusk Service Provider'.PHP_EOL.' */'.PHP_EOL.' Laravel\Dusk\DuskServiceProvider::class,'.PHP_EOL.PHP_EOL.' /*'.PHP_EOL.' * Package Service Providers...' -// ], fn ($changes) => $files->replaceInFile(array_keys($changes), array_values($changes), "{$workingPath}/laravel/config/app.php")); - -// transform([ -// "'model' => App\Models\User::class" => "'model' => Illuminate\Foundation\Auth\User::class", -// ], fn ($changes) => $files->replaceInFile(array_keys($changes), array_values($changes), "{$workingPath}/laravel/config/auth.php")); - $files->copy("{$workingPath}/vendor/laravel/dusk/stubs/phpunit.xml", "{$workingPath}/stubs/phpunit.xml"); $purgeSkeletonDirectories(); diff --git a/src/Foundation/Application.php b/src/Foundation/Application.php index 70627972..d1b73d32 100644 --- a/src/Foundation/Application.php +++ b/src/Foundation/Application.php @@ -15,4 +15,4 @@ public static function applicationBasePath() { return $_ENV['APP_BASE_PATH'] ?? default_skeleton_path(); } -} \ No newline at end of file +} From 1572efc2164c510a0fd94da8641364ca5f88bddf Mon Sep 17 00:00:00 2001 From: Mior Muhammad Zaki Date: Mon, 25 Nov 2024 08:04:24 +0800 Subject: [PATCH 3/5] wip Signed-off-by: Mior Muhammad Zaki --- src/DuskServer.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/DuskServer.php b/src/DuskServer.php index 0e84091f..c37ea7dc 100644 --- a/src/DuskServer.php +++ b/src/DuskServer.php @@ -213,6 +213,7 @@ protected function startServer(): void env: array_merge(defined_environment_variables(), [ 'APP_BASE_PATH' => $this->basePath(), 'APP_URL' => $this->baseUrl(), + 'APP_ENV' => 'testing', ]), timeout: $this->timeout ); From a2d99ee62402810266c013f5983866241cc9a522 Mon Sep 17 00:00:00 2001 From: Mior Muhammad Zaki Date: Mon, 25 Nov 2024 08:17:36 +0800 Subject: [PATCH 4/5] wip Signed-off-by: Mior Muhammad Zaki --- bin/sync | 6 +++++- composer.json | 5 +++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/bin/sync b/bin/sync index 776dee1a..e72a85aa 100755 --- a/bin/sync +++ b/bin/sync @@ -19,6 +19,10 @@ function line(string $code, int $tab = 0): string { $purgeSkeletonDirectories(); +if (! is_file($configureSkeleton = Orchestra\Testbench\join_paths($workingPath, 'vendor', 'orchestra', 'testbench-core', 'bin', 'configure-skeleton.php'))) { + throw new RuntimeException(sprintf('Misssing [%s] file from `orchestra/testbench-core`', $configureSkeleton)); +} + $files->copy("{$workingPath}/vendor/orchestra/testbench-core/laravel/bootstrap/app.php", "{$workingPath}/laravel/bootstrap/app.php"); $files->copy("{$workingPath}/vendor/orchestra/testbench-core/laravel/server.php", "{$workingPath}/laravel/server.php"); $files->copy("{$workingPath}/vendor/orchestra/testbench-core/laravel/.gitignore", "{$workingPath}/laravel/.gitignore"); @@ -31,7 +35,7 @@ Symfony\Component\Process\Process::fromShellCommandline( 'composer create-project "laravel/laravel:9.x-dev" skeleton --no-scripts --no-plugins --quiet --no-install', $workingPath )->mustRun(); -require Orchestra\Testbench\join_paths($workingPath, 'vendor', 'orchestra', 'testbench-core', 'bin', 'configure-skeleton.php'); +require $configureSkeleton; transform([ line('App\Providers', 2) => line('// App\Providers', 2), diff --git a/composer.json b/composer.json index de69a2a6..6ce75430 100644 --- a/composer.json +++ b/composer.json @@ -81,6 +81,11 @@ "@php testbench-dusk package:create-sqlite-db", "@php vendor/bin/phpunit --no-coverage --no-configuration --dont-report-useless-tests --bootstrap vendor/autoload.php --color tests" ], + "sync": [ + "@clear", + "@php bin/sync", + "@lint" + ], "ci": [ "@prepare", "@dusk:install-chromedriver", From 7eac0fd5814548b2651990e4ea34b89a123389d6 Mon Sep 17 00:00:00 2001 From: Mior Muhammad Zaki Date: Mon, 25 Nov 2024 08:19:51 +0800 Subject: [PATCH 5/5] wip Signed-off-by: Mior Muhammad Zaki --- bin/sync | 4 ++++ laravel/bootstrap/app.php | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/bin/sync b/bin/sync index e72a85aa..f987f1d0 100755 --- a/bin/sync +++ b/bin/sync @@ -42,6 +42,10 @@ transform([ line(' * Package Service Providers...', 2) => line(' * Dusk Service Provider', 2).line(' */', 2).line('Laravel\Dusk\DuskServiceProvider::class,', 2).PHP_EOL.line('/*', 2).line(' * Package Service Providers...', 2), ], fn ($changes) => $files->replaceInFile(array_keys($changes), array_values($changes), "{$workingPath}/laravel/config/app.php")); +transform([ + line('use Orchestra\Testbench\Foundation\Application;') => line('use Orchestra\Testbench\Dusk\Foundation\Application;'), +], fn ($changes) => $files->replaceInFile(array_keys($changes), array_values($changes), "{$workingPath}/laravel/bootstrap/app.php")); + $files->copy("{$workingPath}/vendor/laravel/dusk/stubs/phpunit.xml", "{$workingPath}/stubs/phpunit.xml"); $purgeSkeletonDirectories(); diff --git a/laravel/bootstrap/app.php b/laravel/bootstrap/app.php index 309c9647..8cb866c8 100644 --- a/laravel/bootstrap/app.php +++ b/laravel/bootstrap/app.php @@ -1,6 +1,6 @@