Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[7.x] Integration Improvements #111

Merged
merged 5 commits into from
Nov 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
87 changes: 21 additions & 66 deletions bin/sync
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,21 @@ 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();

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");
Expand All @@ -22,75 +35,17 @@ 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 $configureSkeleton;

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"));
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");

$files->deleteDirectory("{$workingPath}/skeleton");
$purgeSkeletonDirectories();
12 changes: 9 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -80,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",
Expand Down
53 changes: 53 additions & 0 deletions laravel/artisan
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#!/usr/bin/env php
<?php

define('LARAVEL_START', microtime(true));

/*
|--------------------------------------------------------------------------
| Register The Auto Loader
|--------------------------------------------------------------------------
|
| Composer provides a convenient, automatically generated class loader
| for our application. We just need to utilize it! We'll require it
| into the script here so that we do not have to worry about the
| loading of any of our classes manually. It's great to relax.
|
*/

require __DIR__.'/vendor/autoload.php';

$app = require_once __DIR__.'/bootstrap/app.php';

/*
|--------------------------------------------------------------------------
| Run The Artisan Application
|--------------------------------------------------------------------------
|
| When we run the console application, the current CLI command will be
| executed in this console and the response sent back to a terminal
| or another output device for the developers. Here goes nothing!
|
*/

$kernel = $app->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);
2 changes: 1 addition & 1 deletion laravel/bootstrap/app.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

use Orchestra\Testbench\Foundation\Application;
use Orchestra\Testbench\Dusk\Foundation\Application;
use Orchestra\Testbench\Foundation\Bootstrap\SyncTestbenchCachedRoutes;
use Orchestra\Testbench\Foundation\Config;
use Orchestra\Testbench\Workbench\Workbench;
Expand Down
8 changes: 4 additions & 4 deletions laravel/config/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
|
*/

'env' => env('APP_ENV', 'testing'),
'env' => env('APP_ENV', 'workbench'),

/*
|--------------------------------------------------------------------------
Expand Down Expand Up @@ -69,7 +69,7 @@
|
*/

'timezone' => 'UTC',
'timezone' => env('APP_TIMEZONE', 'UTC'),

/*
|--------------------------------------------------------------------------
Expand All @@ -82,7 +82,7 @@
|
*/

'locale' => 'en',
'locale' => env('APP_LOCALE', 'en'),

/*
|--------------------------------------------------------------------------
Expand All @@ -95,7 +95,7 @@
|
*/

'fallback_locale' => 'en',
'fallback_locale' => env('APP_FALLBACK_LOCALE', 'en'),

/*
|--------------------------------------------------------------------------
Expand Down
8 changes: 4 additions & 4 deletions laravel/config/auth.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
*/

'defaults' => [
'guard' => 'web',
'passwords' => 'users',
'guard' => env('AUTH_GUARD', 'web'),
'passwords' => env('AUTH_PASSWORD_BROKER', 'users'),
],

/*
Expand Down Expand Up @@ -62,7 +62,7 @@
'providers' => [
'users' => [
'driver' => 'eloquent',
'model' => Illuminate\Foundation\Auth\User::class,
'model' => env('AUTH_MODEL', Illuminate\Foundation\Auth\User::class),
],

// 'users' => [
Expand Down Expand Up @@ -110,6 +110,6 @@
|
*/

'password_timeout' => 10800,
'password_timeout' => env('AUTH_PASSWORD_TIMEOUT', 10800),

];
6 changes: 3 additions & 3 deletions laravel/config/cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' => [
Expand Down
8 changes: 4 additions & 4 deletions laravel/config/database.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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',
Expand All @@ -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'),
Expand Down
8 changes: 4 additions & 4 deletions laravel/config/hashing.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
|
*/

'driver' => 'bcrypt',
'driver' => env('HASH_DRIVER', 'bcrypt'),

/*
|--------------------------------------------------------------------------
Expand Down Expand Up @@ -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),
],

];
6 changes: 3 additions & 3 deletions laravel/config/logging.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@

'deprecations' => [
'channel' => env('LOG_DEPRECATIONS_CHANNEL', 'null'),
'trace' => false,
'trace' => env('LOG_DEPRECATIONS_TRACE', false),
],

/*
Expand All @@ -53,7 +53,7 @@
'channels' => [
'stack' => [
'driver' => 'stack',
'channels' => ['single'],
'channels' => explode(',', env('LOG_STACK', 'single')),
'ignore_exceptions' => false,
],

Expand All @@ -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' => [
Expand Down
2 changes: 1 addition & 1 deletion laravel/config/mail.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@
*/

'markdown' => [
'theme' => 'default',
'theme' => env('MAIL_MARKDOWN_THEME', 'default'),

'paths' => [
resource_path('views/vendor/mail'),
Expand Down
13 changes: 7 additions & 6 deletions laravel/config/queue.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
],
Expand Down
Loading
Loading