From d20c03cdb7ff223a4b051654dd5a75a5d43e2e21 Mon Sep 17 00:00:00 2001 From: Mior Muhammad Zaki Date: Mon, 19 Aug 2024 09:27:33 +0800 Subject: [PATCH 01/37] wip Signed-off-by: Mior Muhammad Zaki --- .github/workflows/analyse.yaml | 43 ++++++++++++++++++++++++++++++++-- 1 file changed, 41 insertions(+), 2 deletions(-) diff --git a/.github/workflows/analyse.yaml b/.github/workflows/analyse.yaml index b0909c1b1..e0241400c 100644 --- a/.github/workflows/analyse.yaml +++ b/.github/workflows/analyse.yaml @@ -17,7 +17,7 @@ jobs: experimental: - false - name: PHP:${{ matrix.php }} on ${{ matrix.os }} + name: PHP:${{ matrix.php }} PHPStan & Pint steps: - name: Checkout code @@ -27,7 +27,7 @@ jobs: uses: shivammathur/setup-php@v2 with: php-version: ${{ matrix.php }} - extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, mysql, mysqli, pdo_mysql, bcmath, intl, fileinfo + extensions: dom, curl, libxml, mbstring, zip, pcntl, sqlite3, pdo_sqlite, bcmath, fileinfo coverage: none - name: Install dependencies @@ -44,3 +44,42 @@ jobs: - name: Execute Static Code Analysis run: vendor/bin/phpstan analyse + + lint: + runs-on: ${{ matrix.os }} + continue-on-error: ${{ matrix.experimental }} + strategy: + matrix: + os: + - "ubuntu-latest" + php: + - 8.0 + - 8.1 + - 8.2 + - 8.3 + dependencies: + - "highest" + experimental: + - false + + name: PHP:${{ matrix.php }} Code Lint + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php }} + extensions: dom, curl, libxml, mbstring, zip, pcntl, sqlite3, pdo_sqlite, bcmath, fileinfo + coverage: none + + - name: Install dependencies + uses: "ramsey/composer-install@v3" + with: + dependency-versions: "${{ matrix.dependencies }}" + composer-options: "--prefer-dist --no-cache" + + - name: PHP Lint + run: php -l ./src From 5083d5f016beb36044dc0bc701cb091e3d9c808b Mon Sep 17 00:00:00 2001 From: Mior Muhammad Zaki Date: Mon, 19 Aug 2024 09:28:23 +0800 Subject: [PATCH 02/37] wip Signed-off-by: Mior Muhammad Zaki --- .github/workflows/analyse.yaml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/analyse.yaml b/.github/workflows/analyse.yaml index e0241400c..9af1d4ece 100644 --- a/.github/workflows/analyse.yaml +++ b/.github/workflows/analyse.yaml @@ -54,8 +54,6 @@ jobs: - "ubuntu-latest" php: - 8.0 - - 8.1 - - 8.2 - 8.3 dependencies: - "highest" From ea93c4385065962760820aecff94078c3fb7da9b Mon Sep 17 00:00:00 2001 From: Mior Muhammad Zaki Date: Mon, 19 Aug 2024 09:30:41 +0800 Subject: [PATCH 03/37] wip Signed-off-by: Mior Muhammad Zaki --- .github/workflows/analyse.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/analyse.yaml b/.github/workflows/analyse.yaml index 9af1d4ece..a9607231c 100644 --- a/.github/workflows/analyse.yaml +++ b/.github/workflows/analyse.yaml @@ -21,7 +21,7 @@ jobs: steps: - name: Checkout code - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Setup PHP uses: shivammathur/setup-php@v2 From 517811be4aee6a6625417b4762f508fc5d3e3791 Mon Sep 17 00:00:00 2001 From: Mior Muhammad Zaki Date: Mon, 19 Aug 2024 09:30:51 +0800 Subject: [PATCH 04/37] wip Signed-off-by: Mior Muhammad Zaki --- .github/workflows/analyse.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/analyse.yaml b/.github/workflows/analyse.yaml index a9607231c..9325433ef 100644 --- a/.github/workflows/analyse.yaml +++ b/.github/workflows/analyse.yaml @@ -53,7 +53,7 @@ jobs: os: - "ubuntu-latest" php: - - 8.0 + - '8.0' - 8.3 dependencies: - "highest" From 1da3a6e94e6c0330d5c2d12d2ba9298455eac9f0 Mon Sep 17 00:00:00 2001 From: Mior Muhammad Zaki Date: Mon, 19 Aug 2024 09:38:00 +0800 Subject: [PATCH 05/37] wip Signed-off-by: Mior Muhammad Zaki --- .github/workflows/audits.yaml | 3 +-- .github/workflows/collision-tests.yaml | 3 +-- .github/workflows/parallel-tests.yaml | 3 +-- 3 files changed, 3 insertions(+), 6 deletions(-) diff --git a/.github/workflows/audits.yaml b/.github/workflows/audits.yaml index 93cfb6aac..f46f4d162 100644 --- a/.github/workflows/audits.yaml +++ b/.github/workflows/audits.yaml @@ -3,8 +3,7 @@ name: audits on: push: pull_request: - schedule: - - cron: '0 0 1 * *' + workflow_dispatch: jobs: audit-dependencies: diff --git a/.github/workflows/collision-tests.yaml b/.github/workflows/collision-tests.yaml index cfe38eb48..69272f07b 100644 --- a/.github/workflows/collision-tests.yaml +++ b/.github/workflows/collision-tests.yaml @@ -3,8 +3,7 @@ name: collision-tests on: push: pull_request: - schedule: - - cron: '0 0 1 * *' + workflow_dispatch: jobs: tests: diff --git a/.github/workflows/parallel-tests.yaml b/.github/workflows/parallel-tests.yaml index cb0ee693e..26416b0ad 100644 --- a/.github/workflows/parallel-tests.yaml +++ b/.github/workflows/parallel-tests.yaml @@ -3,8 +3,7 @@ name: parallel-tests on: push: pull_request: - schedule: - - cron: '0 0 1 * *' + workflow_dispatch: jobs: tests: From 7c3338a87b927047655e5f43e68e7f367018d7c0 Mon Sep 17 00:00:00 2001 From: Mior Muhammad Zaki Date: Mon, 19 Aug 2024 10:23:13 +0800 Subject: [PATCH 06/37] wip Signed-off-by: Mior Muhammad Zaki --- src/functions.php | 52 +++++++++++++++++++++++++++++++---------------- 1 file changed, 35 insertions(+), 17 deletions(-) diff --git a/src/functions.php b/src/functions.php index 4f1c0a769..9f80cf489 100644 --- a/src/functions.php +++ b/src/functions.php @@ -75,7 +75,7 @@ static function ($phpBinary) { $binary = \defined('TESTBENCH_DUSK') ? 'testbench-dusk' : 'testbench'; - $commander = is_file($vendorBin = package_path("vendor/bin/{$binary}")) + $commander = is_file($vendorBin = package_path('vendor', 'bin', $binary)) ? ProcessUtils::escapeArgument((string) $vendorBin) : $binary; @@ -246,9 +246,7 @@ function transform_relative_path(string $path, string $workingPath): string */ function default_skeleton_path(string $path = ''): string { - $path = $path != '' ? ltrim($path, DIRECTORY_SEPARATOR) : ''; - - return rtrim((string) realpath(__DIR__."/../laravel/{$path}"), DIRECTORY_SEPARATOR); + return (string) realpath(join_paths(__DIR__, '..', 'laravel', ...Arr::wrap($path))); } /** @@ -256,24 +254,26 @@ function default_skeleton_path(string $path = ''): string * * @api * - * @param string $path + * @param array|string $path * @return string */ -function package_path(string $path = ''): string +function package_path(array|string $path = ''): string { + $argumentCount = \func_num_args(); + $workingPath = \defined('TESTBENCH_WORKING_PATH') ? TESTBENCH_WORKING_PATH : Env::get('TESTBENCH_WORKING_PATH', getcwd()); - if (str_starts_with($path, './')) { + if ($argumentCount === 1 && \is_string($path) && str_starts_with($path, './')) { return transform_relative_path($path, $workingPath); } - if (empty($path)) { - return rtrim($workingPath, DIRECTORY_SEPARATOR); - } + $path = join_paths(...Arr::wrap($argumentCount > 1 ? \func_get_args() : $path)); - return rtrim($workingPath, DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR.ltrim($path, DIRECTORY_SEPARATOR); + return str_starts_with($path, './') + ? transform_relative_path($path, $workingPath) + : join_paths(rtrim($workingPath, DIRECTORY_SEPARATOR), $path); } /** @@ -298,14 +298,12 @@ function workbench(): array * * @api * - * @param string $path + * @param array|string $path * @return string */ -function workbench_path(string $path = ''): string +function workbench_path(array|string $path = ''): string { - $path = $path != '' ? ltrim($path, DIRECTORY_SEPARATOR) : ''; - - return package_path('workbench'.DIRECTORY_SEPARATOR.$path); + return package_path(join_paths('workbench', ...Arr::wrap(\func_num_args() > 1 ? \func_get_args() : $path))); } /** @@ -321,7 +319,7 @@ function workbench_path(string $path = ''): string function laravel_migration_path(?string $type = null): string { $path = realpath( - \is_null($type) ? base_path('migrations') : base_path("migrations/{$type}") + \is_null($type) ? base_path('migrations') : base_path(join_paths('migrations', $type)) ); if ($path === false) { @@ -375,3 +373,23 @@ function phpunit_version_compare(string $version, ?string $operator = null) return version_compare(Version::id(), $version, $operator); } + +/** + * Join the given paths together. + * + * @param string|null $basePath + * @param string ...$paths + * @return string + */ +function join_paths(?string $basePath, string ...$paths): string +{ + foreach ($paths as $index => $path) { + if (empty($path) && $path !== '0') { + unset($paths[$index]); + } else { + $paths[$index] = DIRECTORY_SEPARATOR.ltrim($path, DIRECTORY_SEPARATOR); + } + } + + return $basePath.implode('', $paths); +} From 1497955b46f6aab516537e7af20458687f85e408 Mon Sep 17 00:00:00 2001 From: Mior Muhammad Zaki Date: Mon, 19 Aug 2024 11:39:03 +0800 Subject: [PATCH 07/37] wip Signed-off-by: Mior Muhammad Zaki --- tests/Helpers/PackagePathTest.php | 44 ++++++++++++++++--------------- tests/Workbench/HelpersTest.php | 10 +++++++ 2 files changed, 33 insertions(+), 21 deletions(-) diff --git a/tests/Helpers/PackagePathTest.php b/tests/Helpers/PackagePathTest.php index 4818ebc3b..210044f70 100644 --- a/tests/Helpers/PackagePathTest.php +++ b/tests/Helpers/PackagePathTest.php @@ -6,36 +6,38 @@ use function Orchestra\Testbench\package_path; +/** + * @group workbench + */ class PackagePathTest extends TestCase { - /** - * @test - * - * @group workbench - */ + /** @test */ public function it_can_use_package_path() { $this->assertSame(realpath(__DIR__.'/../../'), package_path()); $this->assertSame(implode('', [realpath(__DIR__.'/../../'), DIRECTORY_SEPARATOR]), package_path(DIRECTORY_SEPARATOR)); + } + /** + * @test + * @dataProvider pathDataProvider + */ + public function it_can_resolve_correct_package_path(string $path) + { $this->assertSame( - realpath(__DIR__.DIRECTORY_SEPARATOR.'PackagePathTest.php'), - package_path('./tests'.DIRECTORY_SEPARATOR.'Helpers'.DIRECTORY_SEPARATOR.'PackagePathTest.php') - ); - - $this->assertSame( - realpath(__DIR__.DIRECTORY_SEPARATOR.'PackagePathTest.php'), - package_path('./tests'.DIRECTORY_SEPARATOR.'Helpers'.DIRECTORY_SEPARATOR.'PackagePathTest.php') - ); - - $this->assertSame( - realpath(__DIR__.DIRECTORY_SEPARATOR.'PackagePathTest.php'), - package_path('tests'.DIRECTORY_SEPARATOR.'Helpers'.DIRECTORY_SEPARATOR.'PackagePathTest.php') + realpath(__DIR__.DIRECTORY_SEPARATOR.'PackagePathTest.php'), $path ); + } - $this->assertSame( - realpath(__DIR__.DIRECTORY_SEPARATOR.'PackagePathTest.php'), - package_path(DIRECTORY_SEPARATOR.'tests'.DIRECTORY_SEPARATOR.'Helpers'.DIRECTORY_SEPARATOR.'PackagePathTest.php') - ); + public static function pathDataProvider() + { + yield [package_path('tests'.DIRECTORY_SEPARATOR.'Helpers'.DIRECTORY_SEPARATOR.'PackagePathTest.php')]; + yield [package_path('./tests'.DIRECTORY_SEPARATOR.'Helpers'.DIRECTORY_SEPARATOR.'PackagePathTest.php')]; + yield [package_path(DIRECTORY_SEPARATOR.'tests'.DIRECTORY_SEPARATOR.'Helpers'.DIRECTORY_SEPARATOR.'PackagePathTest.php')]; + + yield [package_path('tests', 'Helpers', 'PackagePathTest.php')]; + yield [package_path(['tests', 'Helpers', 'PackagePathTest.php'])]; + yield [package_path('./tests', 'Helpers', 'PackagePathTest.php')]; + yield [package_path(['./tests', 'Helpers', 'PackagePathTest.php'])]; } } diff --git a/tests/Workbench/HelpersTest.php b/tests/Workbench/HelpersTest.php index 61b73ce6d..28712d9a9 100644 --- a/tests/Workbench/HelpersTest.php +++ b/tests/Workbench/HelpersTest.php @@ -84,5 +84,15 @@ public function it_can_resolve_workbench_path() realpath(package_path('workbench/database/migrations/2013_07_26_182750_create_testbench_users_table.php')), workbench_path('database'.DIRECTORY_SEPARATOR.'migrations'.DIRECTORY_SEPARATOR.'2013_07_26_182750_create_testbench_users_table.php') ); + + $this->assertSame( + realpath(package_path('workbench/database/migrations/2013_07_26_182750_create_testbench_users_table.php')), + workbench_path('database', 'migrations', '2013_07_26_182750_create_testbench_users_table.php') + ); + + $this->assertSame( + realpath(package_path('workbench/database/migrations/2013_07_26_182750_create_testbench_users_table.php')), + workbench_path(['database', 'migrations', '2013_07_26_182750_create_testbench_users_table.php']) + ); } } From 7b4235413c02b477a83df1d256d4ecabad99722f Mon Sep 17 00:00:00 2001 From: Mior Muhammad Zaki Date: Mon, 19 Aug 2024 11:39:38 +0800 Subject: [PATCH 08/37] wip Signed-off-by: Mior Muhammad Zaki --- tests/Helpers/PackagePathTest.php | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/Helpers/PackagePathTest.php b/tests/Helpers/PackagePathTest.php index 210044f70..e43620ca0 100644 --- a/tests/Helpers/PackagePathTest.php +++ b/tests/Helpers/PackagePathTest.php @@ -20,6 +20,7 @@ public function it_can_use_package_path() /** * @test + * * @dataProvider pathDataProvider */ public function it_can_resolve_correct_package_path(string $path) From 9b4f480940442cc4210d5f4e0aff10f68f2f2060 Mon Sep 17 00:00:00 2001 From: Mior Muhammad Zaki Date: Mon, 19 Aug 2024 13:16:06 +0800 Subject: [PATCH 09/37] wip Signed-off-by: Mior Muhammad Zaki --- tests/Workbench/HelpersTest.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/tests/Workbench/HelpersTest.php b/tests/Workbench/HelpersTest.php index 28712d9a9..6cc115b6c 100644 --- a/tests/Workbench/HelpersTest.php +++ b/tests/Workbench/HelpersTest.php @@ -80,18 +80,20 @@ public function it_can_resolve_workbench_without_bound() */ public function it_can_resolve_workbench_path() { + $expected = realpath(package_path('workbench/database/migrations/2013_07_26_182750_create_testbench_users_table.php')); + $this->assertSame( - realpath(package_path('workbench/database/migrations/2013_07_26_182750_create_testbench_users_table.php')), + $expected, workbench_path('database'.DIRECTORY_SEPARATOR.'migrations'.DIRECTORY_SEPARATOR.'2013_07_26_182750_create_testbench_users_table.php') ); $this->assertSame( - realpath(package_path('workbench/database/migrations/2013_07_26_182750_create_testbench_users_table.php')), + $expected, workbench_path('database', 'migrations', '2013_07_26_182750_create_testbench_users_table.php') ); $this->assertSame( - realpath(package_path('workbench/database/migrations/2013_07_26_182750_create_testbench_users_table.php')), + $expected, workbench_path(['database', 'migrations', '2013_07_26_182750_create_testbench_users_table.php']) ); } From 94a0c69ed024e8774f8d7ee8399a8fdf9dfb8fa6 Mon Sep 17 00:00:00 2001 From: Mior Muhammad Zaki Date: Wed, 21 Aug 2024 12:13:28 +0800 Subject: [PATCH 10/37] [7.x] Utilise `Orchestra\Testbench\join_paths` (#222) * [7.x] Utilise `Orchestra\Testbench\join_paths` Signed-off-by: Mior Muhammad Zaki * wip Signed-off-by: Mior Muhammad Zaki * wip Signed-off-by: Mior Muhammad Zaki --------- Signed-off-by: Mior Muhammad Zaki --- src/Bootstrap/HandleExceptions.php | 3 ++- .../LoadConfigurationWithWorkbench.php | 4 ++-- src/Bootstrap/LoadEnvironmentVariables.php | 4 +++- src/Concerns/HandlesRoutes.php | 9 ++++---- src/Console/Commander.php | 5 +++-- src/Console/Kernel.php | 4 +++- .../Bootstrap/CreateVendorSymlink.php | 10 +++++---- .../Console/Actions/EnsureDirectoryExists.php | 4 +++- .../Console/Concerns/CopyTestbenchFiles.php | 10 +++++---- .../Console/CreateSqliteDbCommand.php | 10 +++++---- .../Console/DropSqliteDbCommand.php | 4 +++- .../Console/PurgeSkeletonCommand.php | 12 +++++----- src/Workbench/Workbench.php | 22 +++++++++---------- .../Actions/EnsureDirectoryExistsTest.php | 16 ++++++++------ 14 files changed, 69 insertions(+), 48 deletions(-) diff --git a/src/Bootstrap/HandleExceptions.php b/src/Bootstrap/HandleExceptions.php index d78538173..dc37bd75f 100644 --- a/src/Bootstrap/HandleExceptions.php +++ b/src/Bootstrap/HandleExceptions.php @@ -6,6 +6,7 @@ use Orchestra\Testbench\Exceptions\DeprecatedException; use Orchestra\Testbench\Foundation\Env; +use function Orchestra\Testbench\join_paths; use function Orchestra\Testbench\phpunit_version_compare; /** @@ -82,7 +83,7 @@ protected function ensureDeprecationLoggerIsConfigured() if ($driver === 'single') { $config->set('logging.channels.deprecations', array_merge($config->get('logging.channels.single'), [ - 'path' => self::$app->storagePath('logs/deprecations.log'), + 'path' => self::$app->storagePath(join_paths('logs', 'deprecations.log')), ])); } else { $config->set('logging.channels.deprecations', $config->get("logging.channels.{$driver}")); diff --git a/src/Bootstrap/LoadConfigurationWithWorkbench.php b/src/Bootstrap/LoadConfigurationWithWorkbench.php index 3e2e71715..cc0e27b0e 100644 --- a/src/Bootstrap/LoadConfigurationWithWorkbench.php +++ b/src/Bootstrap/LoadConfigurationWithWorkbench.php @@ -39,8 +39,8 @@ public function __construct() */ protected function resolveConfigurationFile(string $path, string $key): string { - return $this->usesWorkbenchConfigFile === true && is_file(workbench_path("config/{$key}.php")) - ? workbench_path("config/{$key}.php") + return $this->usesWorkbenchConfigFile === true && is_file(workbench_path('config', "{$key}.php")) + ? workbench_path('config', "{$key}.php") : $path; } diff --git a/src/Bootstrap/LoadEnvironmentVariables.php b/src/Bootstrap/LoadEnvironmentVariables.php index 93c5a9983..d00e2b7bd 100644 --- a/src/Bootstrap/LoadEnvironmentVariables.php +++ b/src/Bootstrap/LoadEnvironmentVariables.php @@ -5,6 +5,8 @@ use Dotenv\Dotenv; use Orchestra\Testbench\Foundation\Env; +use function Orchestra\Testbench\join_paths; + /** * @internal */ @@ -21,7 +23,7 @@ protected function createDotenv($app) /** @phpstan-ignore method.notFound, method.notFound */ if (! file_exists(implode(DIRECTORY_SEPARATOR, [$app->environmentPath(), $app->environmentFile()]))) { return Dotenv::create( - Env::getRepository(), (string) realpath(__DIR__.'/stubs'), '.env.testbench' + Env::getRepository(), (string) realpath(join_paths(__DIR__, 'stubs')), '.env.testbench' ); } diff --git a/src/Concerns/HandlesRoutes.php b/src/Concerns/HandlesRoutes.php index 60fa3931e..f2054279e 100644 --- a/src/Concerns/HandlesRoutes.php +++ b/src/Concerns/HandlesRoutes.php @@ -8,6 +8,7 @@ use Orchestra\Testbench\Features\TestingFeature; use Orchestra\Testbench\Foundation\Application; +use function Orchestra\Testbench\join_paths; use function Orchestra\Testbench\refresh_router_lookups; use function Orchestra\Testbench\remote; @@ -84,13 +85,13 @@ protected function defineCacheRoutes(string $route) $laravel = Application::create(static::applicationBasePath()); $files->put( - $laravel->basePath("routes/testbench-{$time}.php"), $route + $laravel->basePath(join_paths('routes', "testbench-{$time}.php")), $route ); remote('route:cache')->mustRun(); $this->assertTrue( - $files->exists($laravel->bootstrapPath('cache/routes-v7.php')) + $files->exists($laravel->bootstrapPath(join_paths('cache', 'routes-v7.php'))) ); if ($this->app instanceof LaravelApplication) { @@ -114,8 +115,8 @@ protected function requireApplicationCachedRoutes(Filesystem $files): void $this->beforeApplicationDestroyed(function () use ($files) { if ($this->app instanceof LaravelApplication) { $files->delete( - $this->app->bootstrapPath('cache/routes-v7.php'), - ...$files->glob($this->app->basePath('routes/testbench-*.php')) + $this->app->bootstrapPath(join_paths('cache', 'routes-v7.php')), + ...$files->glob($this->app->basePath(join_paths('routes', 'testbench-*.php'))) ); } diff --git a/src/Console/Commander.php b/src/Console/Commander.php index a5b90e580..e4bb53e45 100644 --- a/src/Console/Commander.php +++ b/src/Console/Commander.php @@ -24,6 +24,7 @@ use Symfony\Component\Console\SignalRegistry\SignalRegistry; use Throwable; +use function Orchestra\Testbench\join_paths; use function Orchestra\Testbench\transform_relative_path; /** @@ -118,9 +119,9 @@ public function laravel() if (! $this->app instanceof LaravelApplication) { $laravelBasePath = $this->getBasePath(); - $hasEnvironmentFile = fn () => file_exists("{$laravelBasePath}/.env"); + $hasEnvironmentFile = fn () => file_exists(join_paths($laravelBasePath, '.env')); - tap(Application::createVendorSymlink($laravelBasePath, $this->workingPath.'/vendor'), function ($app) use ($hasEnvironmentFile) { + tap(Application::createVendorSymlink($laravelBasePath, join_paths($this->workingPath, 'vendor')), function ($app) use ($hasEnvironmentFile) { $filesystem = new Filesystem; $this->copyTestbenchConfigurationFile($app, $filesystem, $this->workingPath); diff --git a/src/Console/Kernel.php b/src/Console/Kernel.php index 8ec4bd858..e03053283 100644 --- a/src/Console/Kernel.php +++ b/src/Console/Kernel.php @@ -5,6 +5,8 @@ use Orchestra\Testbench\Foundation\Console\Kernel as ConsoleKernel; use Throwable; +use function Orchestra\Testbench\join_paths; + final class Kernel extends ConsoleKernel { /** @@ -21,7 +23,7 @@ final class Kernel extends ConsoleKernel */ protected function commands() { - if (file_exists($console = base_path('routes/console.php'))) { + if (file_exists($console = base_path(join_paths('routes', 'console.php')))) { require $console; } } diff --git a/src/Foundation/Bootstrap/CreateVendorSymlink.php b/src/Foundation/Bootstrap/CreateVendorSymlink.php index d98dc0d4a..0807b8fe0 100644 --- a/src/Foundation/Bootstrap/CreateVendorSymlink.php +++ b/src/Foundation/Bootstrap/CreateVendorSymlink.php @@ -6,6 +6,8 @@ use Illuminate\Contracts\Foundation\Application; use Illuminate\Filesystem\Filesystem; +use function Orchestra\Testbench\join_paths; + /** * @internal */ @@ -41,11 +43,11 @@ public function bootstrap(Application $app): void $appVendorPath = $app->basePath('vendor'); if ( - ! $filesystem->isFile("{$appVendorPath}/autoload.php") || - $filesystem->hash("{$appVendorPath}/autoload.php") !== $filesystem->hash("{$this->workingPath}/autoload.php") + ! $filesystem->isFile(join_paths($appVendorPath, 'autoload.php')) || + $filesystem->hash(join_paths($appVendorPath, 'autoload.php')) !== $filesystem->hash(join_paths($this->workingPath, 'autoload.php')) ) { - if ($filesystem->exists($app->bootstrapPath('cache/packages.php'))) { - $filesystem->delete($app->bootstrapPath('cache/packages.php')); + if ($filesystem->exists($app->bootstrapPath(join_paths('cache', 'packages.php')))) { + $filesystem->delete($app->bootstrapPath(join_paths('cache', 'packages.php'))); } if (is_link($appVendorPath)) { diff --git a/src/Foundation/Console/Actions/EnsureDirectoryExists.php b/src/Foundation/Console/Actions/EnsureDirectoryExists.php index 3152b3b88..d9d7a8289 100644 --- a/src/Foundation/Console/Actions/EnsureDirectoryExists.php +++ b/src/Foundation/Console/Actions/EnsureDirectoryExists.php @@ -6,6 +6,8 @@ use Illuminate\Filesystem\Filesystem; use Illuminate\Support\LazyCollection; +use function Orchestra\Testbench\join_paths; + class EnsureDirectoryExists extends Action { /** @@ -43,7 +45,7 @@ public function handle(iterable $directories): void } $this->filesystem->ensureDirectoryExists($directory, 0755, true); - $this->filesystem->copy((string) realpath(__DIR__.'/stubs/.gitkeep'), "{$directory}/.gitkeep"); + $this->filesystem->copy((string) realpath(join_paths(__DIR__, 'stubs', '.gitkeep')), join_paths($directory, '.gitkeep')); $this->components?->task(\sprintf('Prepare [%s] directory', $this->pathLocation($directory))); }); diff --git a/src/Foundation/Console/Concerns/CopyTestbenchFiles.php b/src/Foundation/Console/Concerns/CopyTestbenchFiles.php index 28e564019..0ba6f192a 100644 --- a/src/Foundation/Console/Concerns/CopyTestbenchFiles.php +++ b/src/Foundation/Console/Concerns/CopyTestbenchFiles.php @@ -6,6 +6,8 @@ use Illuminate\Filesystem\Filesystem; use Illuminate\Support\LazyCollection; +use function Orchestra\Testbench\join_paths; + trait CopyTestbenchFiles { use HandleTerminatingConsole; @@ -25,7 +27,7 @@ protected function copyTestbenchConfigurationFile(Application $app, Filesystem $ yield 'testbench.yaml.example'; yield 'testbench.yaml.dist'; })->map(static function ($file) use ($workingPath) { - return "{$workingPath}/{$file}"; + return join_paths($workingPath, $file); })->filter(static function ($file) use ($filesystem) { return $filesystem->exists($file); })->first(); @@ -63,15 +65,15 @@ protected function copyTestbenchConfigurationFile(Application $app, Filesystem $ */ protected function copyTestbenchDotEnvFile(Application $app, Filesystem $filesystem, string $workingPath): void { - $workingPath = $filesystem->isDirectory("{$workingPath}/workbench") - ? "{$workingPath}/workbench" + $workingPath = $filesystem->isDirectory(join_paths($workingPath, 'workbench')) + ? join_paths($workingPath, 'workbench') : $workingPath; $configurationFile = LazyCollection::make(function () { yield $this->environmentFile; yield "{$this->environmentFile}.example"; yield "{$this->environmentFile}.dist"; - })->map(fn ($file) => "{$workingPath}/{$file}") + })->map(fn ($file) => join_paths($workingPath, $file)) ->filter(fn ($file) => $filesystem->exists($file)) ->first(); diff --git a/src/Foundation/Console/CreateSqliteDbCommand.php b/src/Foundation/Console/CreateSqliteDbCommand.php index 6c4b4de63..366102ceb 100644 --- a/src/Foundation/Console/CreateSqliteDbCommand.php +++ b/src/Foundation/Console/CreateSqliteDbCommand.php @@ -6,6 +6,8 @@ use Illuminate\Filesystem\Filesystem; use Symfony\Component\Console\Attribute\AsCommand; +use function Orchestra\Testbench\join_paths; + #[AsCommand(name: 'package:create-sqlite-db', description: 'Create sqlite database file')] class CreateSqliteDbCommand extends Command { @@ -30,11 +32,11 @@ public function handle(Filesystem $filesystem) /** @var bool $force */ $force = $this->option('force'); - $from = $filesystem->exists("{$databasePath}/database.sqlite.example") - ? "{$databasePath}/database.sqlite.example" - : (string) realpath(__DIR__.'/stubs/database.sqlite.example'); + $from = $filesystem->exists(join_paths($databasePath, 'database.sqlite.example')) + ? join_paths($databasePath, 'database.sqlite.example') + : (string) realpath(join_paths(__DIR__, 'stubs', 'database.sqlite.example')); - $to = "{$databasePath}/database.sqlite"; + $to = join_paths($databasePath, 'database.sqlite'); (new Actions\GeneratesFile( filesystem: $filesystem, diff --git a/src/Foundation/Console/DropSqliteDbCommand.php b/src/Foundation/Console/DropSqliteDbCommand.php index d7ff5e051..68de74294 100644 --- a/src/Foundation/Console/DropSqliteDbCommand.php +++ b/src/Foundation/Console/DropSqliteDbCommand.php @@ -6,6 +6,8 @@ use Illuminate\Filesystem\Filesystem; use Symfony\Component\Console\Attribute\AsCommand; +use function Orchestra\Testbench\join_paths; + #[AsCommand(name: 'package:drop-sqlite-db', description: 'Drop sqlite database file')] class DropSqliteDbCommand extends Command { @@ -31,7 +33,7 @@ public function handle(Filesystem $filesystem) filesystem: $filesystem, components: $this->components, workingPath: $workingPath, - ))->handle(["{$databasePath}/database.sqlite"]); + ))->handle([join_paths($databasePath, 'database.sqlite')]); return Command::SUCCESS; } diff --git a/src/Foundation/Console/PurgeSkeletonCommand.php b/src/Foundation/Console/PurgeSkeletonCommand.php index e1cc1047a..e52cb60db 100644 --- a/src/Foundation/Console/PurgeSkeletonCommand.php +++ b/src/Foundation/Console/PurgeSkeletonCommand.php @@ -9,6 +9,8 @@ use Orchestra\Testbench\Contracts\Config as ConfigContract; use Symfony\Component\Console\Attribute\AsCommand; +use function Orchestra\Testbench\join_paths; + #[AsCommand(name: 'package:purge-skeleton', description: 'Purge skeleton folder to original state')] class PurgeSkeletonCommand extends Command { @@ -51,11 +53,11 @@ public function handle(Filesystem $filesystem, ConfigContract $config) workingPath: $workingPath, ))->handle( LazyCollection::make(function () use ($filesystem) { - yield $this->laravel->basePath('database/database.sqlite'); - yield $filesystem->glob($this->laravel->basePath('routes/testbench-*.php')); - yield $filesystem->glob($this->laravel->basePath('storage/app/public/*')); - yield $filesystem->glob($this->laravel->basePath('storage/app/*')); - yield $filesystem->glob($this->laravel->basePath('storage/framework/sessions/*')); + yield $this->laravel->basePath(join_paths('database', 'database.sqlite')); + yield $filesystem->glob($this->laravel->basePath(join_paths('routes', 'testbench-*.php'))); + yield $filesystem->glob($this->laravel->basePath(join_paths('storage', 'app', 'public', '*'))); + yield $filesystem->glob($this->laravel->basePath(join_paths('storage', 'app', '*'))); + yield $filesystem->glob($this->laravel->basePath(join_paths('storage', 'framework', 'sessions', '*'))); })->flatten() ); diff --git a/src/Workbench/Workbench.php b/src/Workbench/Workbench.php index b771c833d..3b9f834f9 100644 --- a/src/Workbench/Workbench.php +++ b/src/Workbench/Workbench.php @@ -89,7 +89,7 @@ public static function discoverRoutes(ApplicationContract $app, ConfigContract $ tap($app->make('router'), static function (Router $router) use ($discoversConfig) { foreach (['web', 'api'] as $group) { if (($discoversConfig[$group] ?? false) === true) { - if (file_exists($route = workbench_path("routes/{$group}.php"))) { + if (file_exists($route = workbench_path('routes', "{$group}.php"))) { $router->middleware($group)->group($route); } } @@ -104,8 +104,8 @@ public static function discoverRoutes(ApplicationContract $app, ConfigContract $ after_resolving($app, 'translator', static function ($translator) { /** @var \Illuminate\Contracts\Translation\Loader $translator */ $path = Collection::make([ - workbench_path('/lang'), - workbench_path('/resources/lang'), + workbench_path('lang'), + workbench_path('resources', 'lang'), ])->filter(static function ($path) { return is_dir($path); })->first(); @@ -119,7 +119,7 @@ public static function discoverRoutes(ApplicationContract $app, ConfigContract $ after_resolving($app, 'view', static function ($view, $app) use ($discoversConfig) { /** @var \Illuminate\Contracts\View\Factory|\Illuminate\View\Factory $view */ - if (! is_dir($path = workbench_path('/resources/views'))) { + if (! is_dir($path = workbench_path('resources', 'views'))) { return; } @@ -140,7 +140,7 @@ public static function discoverRoutes(ApplicationContract $app, ConfigContract $ after_resolving($app, 'blade.compiler', static function ($blade) use ($discoversConfig) { /** @var \Illuminate\View\Compilers\BladeCompiler $blade */ - if (($discoversConfig['components'] ?? false) === false && is_dir(workbench_path('/app/View/Components'))) { + if (($discoversConfig['components'] ?? false) === false && is_dir(workbench_path('app', 'View', 'Components'))) { $blade->componentNamespace('Workbench\\App\\View\\Components', 'workbench'); } }); @@ -188,17 +188,17 @@ public static function discoverRoutes(ApplicationContract $app, ConfigContract $ */ public static function discoverCommandsRoutes(ApplicationContract $app): void { - if (file_exists($console = workbench_path('routes/console.php'))) { + if (file_exists($console = workbench_path('routes', 'console.php'))) { require $console; } - if (! is_dir(workbench_path('app/Console/Commands'))) { + if (! is_dir(workbench_path('app', 'Console', 'Commands'))) { return; } $namespace = 'Workbench\App'; - foreach ((new Finder)->in([workbench_path('app/Console/Commands')])->files() as $command) { + foreach ((new Finder)->in([workbench_path('app', 'Console', 'Commands')])->files() as $command) { $command = $namespace.str_replace( ['/', '.php'], ['\\', ''], @@ -240,7 +240,7 @@ public static function configuration(): ConfigContract public static function applicationConsoleKernel(): ?string { if (! isset(static::$cachedCoreBindings['kernel']['console'])) { - static::$cachedCoreBindings['kernel']['console'] = file_exists(workbench_path('/app/Console/Kernel.php')) + static::$cachedCoreBindings['kernel']['console'] = file_exists(workbench_path('app', 'Console', 'Kernel.php')) ? 'Workbench\App\Console\Kernel' : null; } @@ -256,7 +256,7 @@ public static function applicationConsoleKernel(): ?string public static function applicationHttpKernel(): ?string { if (! isset(static::$cachedCoreBindings['kernel']['http'])) { - static::$cachedCoreBindings['kernel']['http'] = file_exists(workbench_path('/app/Http/Kernel.php')) + static::$cachedCoreBindings['kernel']['http'] = file_exists(workbench_path('app', 'Http', 'Kernel.php')) ? 'Workbench\App\Http\Kernel' : null; } @@ -272,7 +272,7 @@ public static function applicationHttpKernel(): ?string public static function applicationExceptionHandler(): ?string { if (! isset(static::$cachedCoreBindings['handler']['exception'])) { - static::$cachedCoreBindings['handler']['exception'] = file_exists(workbench_path('/app/Exceptions/Handler.php')) + static::$cachedCoreBindings['handler']['exception'] = file_exists(workbench_path('app', 'Exceptions', 'Handler.php')) ? 'Workbench\App\Exceptions\Handler' : null; } diff --git a/tests/Foundation/Console/Actions/EnsureDirectoryExistsTest.php b/tests/Foundation/Console/Actions/EnsureDirectoryExistsTest.php index 3e180d002..bde9d6f0b 100644 --- a/tests/Foundation/Console/Actions/EnsureDirectoryExistsTest.php +++ b/tests/Foundation/Console/Actions/EnsureDirectoryExistsTest.php @@ -7,6 +7,8 @@ use Mockery as m; use Orchestra\Testbench\TestCase; +use function Orchestra\Testbench\join_paths; + class EnsureDirectoryExistsTest extends TestCase { /** @test */ @@ -17,21 +19,21 @@ public function it_can_ensure_directory_exists() $filesystem->shouldReceive('isDirectory')->once()->with('a')->andReturnFalse() ->shouldReceive('ensureDirectoryExists')->once()->with('a', 493, true)->andReturnSelf() - ->shouldReceive('copy')->once()->with(M::type('String'), 'a/.gitkeep')->andReturnSelf() + ->shouldReceive('copy')->once()->with(M::type('String'), join_paths('a', '.gitkeep'))->andReturnSelf() ->shouldReceive('isDirectory')->once()->with('b')->andReturnTrue() ->shouldReceive('ensureDirectoryExists')->never()->with('b', 493, true)->andReturnSelf() - ->shouldReceive('copy')->never()->with(M::type('String'), 'b/.gitkeep')->andReturnSelf() - ->shouldReceive('isDirectory')->once()->with('c/d')->andReturnFalse() - ->shouldReceive('ensureDirectoryExists')->once()->with('c/d', 493, true)->andReturnSelf() - ->shouldReceive('copy')->once()->with(M::type('String'), 'c/d/.gitkeep')->andReturnSelf(); + ->shouldReceive('copy')->never()->with(M::type('String'), join_paths('b', '.gitkeep'))->andReturnSelf() + ->shouldReceive('isDirectory')->once()->with(join_paths('c', 'd'))->andReturnFalse() + ->shouldReceive('ensureDirectoryExists')->once()->with(join_paths('c', 'd'), 493, true)->andReturnSelf() + ->shouldReceive('copy')->once()->with(M::type('String'), join_paths('c', 'd', '.gitkeep'))->andReturnSelf(); $components->shouldReceive('task')->once()->with('Prepare [a] directory')->andReturnNull() ->shouldReceive('twoColumnDetail')->once()->with('Directory [b] already exists', 'SKIPPED')->andReturnNull() - ->shouldReceive('task')->once()->with('Prepare [c/d] directory')->andReturnNull(); + ->shouldReceive('task')->once()->with(\sprintf('Prepare [%s] directory', join_paths('c', 'd')))->andReturnNull(); (new EnsureDirectoryExists( filesystem: $filesystem, components: $components, - ))->handle(['a', 'b', 'c/d']); + ))->handle(['a', 'b', join_paths('c', 'd')]); } } From 1dce836497332c2297256fed02b5c174df605ecc Mon Sep 17 00:00:00 2001 From: Mior Muhammad Zaki Date: Wed, 21 Aug 2024 12:18:28 +0800 Subject: [PATCH 11/37] [7.x] Add `artisan` binary (#221) * [7.x] Add `artisan` binary Signed-off-by: Mior Muhammad Zaki * wip Signed-off-by: Mior Muhammad Zaki * wip Signed-off-by: Mior Muhammad Zaki * wip Signed-off-by: Mior Muhammad Zaki * wip Signed-off-by: Mior Muhammad Zaki * wip Signed-off-by: Mior Muhammad Zaki * wip Signed-off-by: Mior Muhammad Zaki * wip Signed-off-by: Mior Muhammad Zaki --------- Signed-off-by: Mior Muhammad Zaki --- bin/sync | 1 + laravel/artisan | 55 +++++++++++++++++++ laravel/bootstrap/app.php | 17 +++--- .../Bootstrap/SyncTestbenchCachedRoutes.php | 29 ++++++++++ .../SyncTestbenchConfigurationFiles.php | 44 +++++++++++++++ .../Console/Concerns/CopyTestbenchFiles.php | 13 ++--- tests/Integrations/ArtisanTest.php | 28 ++++++++++ 7 files changed, 169 insertions(+), 18 deletions(-) create mode 100644 laravel/artisan create mode 100644 src/Foundation/Console/Bootstrap/SyncTestbenchCachedRoutes.php create mode 100644 src/Foundation/Console/Bootstrap/SyncTestbenchConfigurationFiles.php create mode 100644 tests/Integrations/ArtisanTest.php diff --git a/bin/sync b/bin/sync index 79f8be15c..939c3281f 100755 --- a/bin/sync +++ b/bin/sync @@ -29,6 +29,7 @@ Symfony\Component\Process\Process::fromShellCommandline( )->mustRun(); Illuminate\Support\Collection::make([ + 'artisan', '.env.example', 'config/*.php', 'database/.gitignore', diff --git a/laravel/artisan b/laravel/artisan new file mode 100644 index 000000000..e57b15017 --- /dev/null +++ b/laravel/artisan @@ -0,0 +1,55 @@ +#!/usr/bin/env php +bootstrap($app); + +/* +|-------------------------------------------------------------------------- +| 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); diff --git a/laravel/bootstrap/app.php b/laravel/bootstrap/app.php index cbf76bbf1..bf41ec9ac 100644 --- a/laravel/bootstrap/app.php +++ b/laravel/bootstrap/app.php @@ -2,8 +2,11 @@ use Orchestra\Testbench\Foundation\Application; use Orchestra\Testbench\Foundation\Config; +use Orchestra\Testbench\Foundation\Console\Bootstrap\SyncTestbenchCachedRoutes; use Orchestra\Testbench\Workbench\Workbench; +use function Orchestra\Testbench\join_paths; + /** * Create Laravel application. * @@ -16,8 +19,8 @@ ); $hasEnvironmentFile = ! is_null($config['laravel']) - ? file_exists($config['laravel'].'/.env') - : file_exists("{$workingPath}/.env"); + ? file_exists(join_paths($config['laravel'], '.env')) + : file_exists(join_paths($workingPath, '.env')); return Application::create( basePath: $config['laravel'], @@ -33,16 +36,10 @@ define('TESTBENCH_WORKING_PATH', getenv('TESTBENCH_WORKING_PATH')); } -$app = $createApp(realpath(__DIR__.'/../')); +$app = $createApp(realpath(join_paths(__DIR__, '..'))); unset($createApp); -/** @var \Illuminate\Routing\Router $router */ -$router = $app->make('router'); - -collect(glob(__DIR__.'/../routes/testbench-*.php')) - ->each(static function ($routeFile) use ($app, $router) { - require $routeFile; - }); +(new SyncTestbenchCachedRoutes)->bootstrap($app); return $app; diff --git a/src/Foundation/Console/Bootstrap/SyncTestbenchCachedRoutes.php b/src/Foundation/Console/Bootstrap/SyncTestbenchCachedRoutes.php new file mode 100644 index 000000000..61ac2d04d --- /dev/null +++ b/src/Foundation/Console/Bootstrap/SyncTestbenchCachedRoutes.php @@ -0,0 +1,29 @@ +make('router'); + + /** @phpstan-ignore argument.type */ + Collection::make(glob($app->basePath(join_paths('routes', 'testbench-*.php')))) + ->each(static function ($routeFile) use ($app, $router) { // @phpstan-ignore closure.unusedUse, closure.unusedUse + require $routeFile; + }); + } +} diff --git a/src/Foundation/Console/Bootstrap/SyncTestbenchConfigurationFiles.php b/src/Foundation/Console/Bootstrap/SyncTestbenchConfigurationFiles.php new file mode 100644 index 000000000..1950b0a41 --- /dev/null +++ b/src/Foundation/Console/Bootstrap/SyncTestbenchConfigurationFiles.php @@ -0,0 +1,44 @@ +exists($app->basePath('testbench.yaml'))) { + $this->copyTestbenchConfigurationFile($app, $filesystem, package_path()); + } + + if (! $filesystem->exists($app->basePath('.env'))) { + $this->copyTestbenchDotEnvFile($app, $filesystem, package_path()); + } + + $app->terminating(function () { + $this->handleTerminatingConsole(); + }); + } +} diff --git a/src/Foundation/Console/Concerns/CopyTestbenchFiles.php b/src/Foundation/Console/Concerns/CopyTestbenchFiles.php index 0ba6f192a..c69b58f17 100644 --- a/src/Foundation/Console/Concerns/CopyTestbenchFiles.php +++ b/src/Foundation/Console/Concerns/CopyTestbenchFiles.php @@ -26,11 +26,9 @@ protected function copyTestbenchConfigurationFile(Application $app, Filesystem $ yield 'testbench.yaml'; yield 'testbench.yaml.example'; yield 'testbench.yaml.dist'; - })->map(static function ($file) use ($workingPath) { - return join_paths($workingPath, $file); - })->filter(static function ($file) use ($filesystem) { - return $filesystem->exists($file); - })->first(); + })->map(static fn ($file) => join_paths($workingPath, $file)) + ->filter(static fn ($file) => $filesystem->exists($file)) + ->first(); $testbenchFile = $app->basePath('testbench.yaml'); @@ -68,13 +66,12 @@ protected function copyTestbenchDotEnvFile(Application $app, Filesystem $filesys $workingPath = $filesystem->isDirectory(join_paths($workingPath, 'workbench')) ? join_paths($workingPath, 'workbench') : $workingPath; - $configurationFile = LazyCollection::make(function () { yield $this->environmentFile; yield "{$this->environmentFile}.example"; yield "{$this->environmentFile}.dist"; - })->map(fn ($file) => join_paths($workingPath, $file)) - ->filter(fn ($file) => $filesystem->exists($file)) + })->map(static fn ($file) => join_paths($workingPath, $file)) + ->filter(static fn ($file) => $filesystem->exists($file)) ->first(); if (\is_null($configurationFile) && $filesystem->exists($app->basePath('.env.example'))) { diff --git a/tests/Integrations/ArtisanTest.php b/tests/Integrations/ArtisanTest.php new file mode 100644 index 000000000..0463e5854 --- /dev/null +++ b/tests/Integrations/ArtisanTest.php @@ -0,0 +1,28 @@ +find(); + + $remote = remote('--version --no-ansi')->mustRun(); + + $artisan = (new Process( + command: [$phpBinary, 'artisan', '--version', '--no-ansi'], + cwd: package_path('laravel'), + ))->mustRun(); + + $this->assertSame(json_decode($artisan->getOutput(), true), json_decode($remote->getOutput(), true)); + } +} From 7df6fdc03178437c68df3b912f0c74ef2d61e913 Mon Sep 17 00:00:00 2001 From: Mior Muhammad Zaki Date: Wed, 21 Aug 2024 12:40:04 +0800 Subject: [PATCH 12/37] wip Signed-off-by: Mior Muhammad Zaki --- laravel/artisan | 52 ++++++------------------------------------------- 1 file changed, 6 insertions(+), 46 deletions(-) diff --git a/laravel/artisan b/laravel/artisan index e57b15017..8e04b4224 100644 --- a/laravel/artisan +++ b/laravel/artisan @@ -1,55 +1,15 @@ #!/usr/bin/env php bootstrap($app); - -/* -|-------------------------------------------------------------------------- -| 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); +// Bootstrap Laravel and handle the command... +$status = (require_once __DIR__.'/bootstrap/app.php') + ->handleCommand(new ArgvInput); exit($status); From f76de34b1e13937a56658e04e5339dfd5d18e434 Mon Sep 17 00:00:00 2001 From: Mior Muhammad Zaki Date: Wed, 21 Aug 2024 13:18:06 +0800 Subject: [PATCH 13/37] wip Signed-off-by: Mior Muhammad Zaki --- laravel/artisan | 2 -- 1 file changed, 2 deletions(-) diff --git a/laravel/artisan b/laravel/artisan index e57b15017..67a3329b1 100644 --- a/laravel/artisan +++ b/laravel/artisan @@ -19,8 +19,6 @@ require __DIR__.'/vendor/autoload.php'; $app = require_once __DIR__.'/bootstrap/app.php'; -(new Orchestra\Testbench\Foundation\Console\Bootstrap\SyncTestbenchConfigurationFiles)->bootstrap($app); - /* |-------------------------------------------------------------------------- | Run The Artisan Application From 3fe49c322244a8ca5a3bab453fa6826e38f1fd4f Mon Sep 17 00:00:00 2001 From: Mior Muhammad Zaki Date: Wed, 21 Aug 2024 13:18:39 +0800 Subject: [PATCH 14/37] wip Signed-off-by: Mior Muhammad Zaki --- laravel/artisan | 2 -- 1 file changed, 2 deletions(-) diff --git a/laravel/artisan b/laravel/artisan index e57b15017..67a3329b1 100644 --- a/laravel/artisan +++ b/laravel/artisan @@ -19,8 +19,6 @@ require __DIR__.'/vendor/autoload.php'; $app = require_once __DIR__.'/bootstrap/app.php'; -(new Orchestra\Testbench\Foundation\Console\Bootstrap\SyncTestbenchConfigurationFiles)->bootstrap($app); - /* |-------------------------------------------------------------------------- | Run The Artisan Application From fd7307088d8598acafa91eb809246b4022730ea2 Mon Sep 17 00:00:00 2001 From: Mior Muhammad Zaki Date: Wed, 21 Aug 2024 14:45:23 +0800 Subject: [PATCH 15/37] wip Signed-off-by: Mior Muhammad Zaki --- src/Foundation/Console/TestCommand.php | 2 +- src/functions.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Foundation/Console/TestCommand.php b/src/Foundation/Console/TestCommand.php index cb647f186..4a31fa645 100644 --- a/src/Foundation/Console/TestCommand.php +++ b/src/Foundation/Console/TestCommand.php @@ -72,7 +72,7 @@ public function phpUnitConfigurationFile() return Collection::make([ package_path('/'.$configurationFile), - package_path('/'.$configurationFile.'.dist'), + package_path("/{$configurationFile}.dist"), ])->filter(static function ($path) { return file_exists($path); })->first() ?? './'; diff --git a/src/functions.php b/src/functions.php index 9f80cf489..873b5d85a 100644 --- a/src/functions.php +++ b/src/functions.php @@ -303,7 +303,7 @@ function workbench(): array */ function workbench_path(array|string $path = ''): string { - return package_path(join_paths('workbench', ...Arr::wrap(\func_num_args() > 1 ? \func_get_args() : $path))); + return package_path('workbench', ...Arr::wrap(\func_num_args() > 1 ? \func_get_args() : $path)); } /** From 2f2588af9394a7ae010ed5c369a8413eab3d1144 Mon Sep 17 00:00:00 2001 From: Mior Muhammad Zaki Date: Wed, 21 Aug 2024 14:48:00 +0800 Subject: [PATCH 16/37] wip Signed-off-by: Mior Muhammad Zaki --- bin/sync | 1 + laravel/artisan | 53 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+) create mode 100644 laravel/artisan diff --git a/bin/sync b/bin/sync index ea137e01e..67ca0b008 100755 --- a/bin/sync +++ b/bin/sync @@ -23,6 +23,7 @@ Symfony\Component\Process\Process::fromShellCommandline( )->mustRun(); Illuminate\Support\Collection::make([ + 'artisan', 'config/*.php', 'database/.gitignore', 'database/migrations/2014_10_12_000000_create_users_table.php', diff --git a/laravel/artisan b/laravel/artisan new file mode 100644 index 000000000..67a3329b1 --- /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); From 689479a2cdaa88661d9fb8821d4f8b0b0b802222 Mon Sep 17 00:00:00 2001 From: Mior Muhammad Zaki Date: Wed, 21 Aug 2024 15:14:44 +0800 Subject: [PATCH 17/37] [6.x] Add `Orchestra\Testbench\join_paths()` (#223) * [6.x] Add `Orchestra\Testbench\join_paths()` Signed-off-by: Mior Muhammad Zaki * wip Signed-off-by: Mior Muhammad Zaki * wip Signed-off-by: Mior Muhammad Zaki --------- Signed-off-by: Mior Muhammad Zaki --- src/functions.php | 48 +++++++++++++++++++++--------- tests/Helpers/PackagePathTest.php | 45 +++++++++++++++------------- tests/Integrations/ArtisanTest.php | 28 +++++++++++++++++ tests/Workbench/HelpersTest.php | 14 ++++++++- 4 files changed, 99 insertions(+), 36 deletions(-) create mode 100644 tests/Integrations/ArtisanTest.php diff --git a/src/functions.php b/src/functions.php index 6aaec500f..c0e6d400f 100644 --- a/src/functions.php +++ b/src/functions.php @@ -251,7 +251,7 @@ function default_skeleton_path(string $path = ''): string { $path = $path != '' ? ltrim($path, DIRECTORY_SEPARATOR) : ''; - return rtrim((string) realpath(__DIR__."/../laravel/{$path}"), DIRECTORY_SEPARATOR); + return (string) realpath(join_paths(__DIR__, '..', 'laravel', ...Arr::wrap($path))); } /** @@ -259,24 +259,26 @@ function default_skeleton_path(string $path = ''): string * * @api * - * @param string $path + * @param array|string $path * @return string */ -function package_path(string $path = ''): string +function package_path($path = ''): string { + $argumentCount = \func_num_args(); + $workingPath = \defined('TESTBENCH_WORKING_PATH') ? TESTBENCH_WORKING_PATH : Env::get('TESTBENCH_WORKING_PATH', getcwd()); - if (Str::startsWith($path, './')) { + if ($argumentCount === 1 && \is_string($path) && str_starts_with($path, './')) { return transform_relative_path($path, $workingPath); } - if (empty($path)) { - return rtrim($workingPath, DIRECTORY_SEPARATOR); - } + $path = join_paths(...Arr::wrap($argumentCount > 1 ? \func_get_args() : $path)); - return rtrim($workingPath, DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR.ltrim($path, DIRECTORY_SEPARATOR); + return Str::startsWith($path, './') + ? transform_relative_path($path, $workingPath) + : join_paths(rtrim($workingPath, DIRECTORY_SEPARATOR), $path); } /** @@ -301,14 +303,12 @@ function workbench(): array * * @api * - * @param string $path + * @param array|string $path * @return string */ -function workbench_path(string $path = ''): string +function workbench_path($path = ''): string { - $path = $path != '' ? ltrim($path, DIRECTORY_SEPARATOR) : ''; - - return package_path('workbench'.DIRECTORY_SEPARATOR.$path); + return package_path(join_paths('workbench', ...Arr::wrap(\func_num_args() > 1 ? \func_get_args() : $path))); } /** @@ -324,7 +324,7 @@ function workbench_path(string $path = ''): string function laravel_migration_path(?string $type = null): string { $path = realpath( - \is_null($type) ? base_path('migrations') : base_path("migrations/{$type}") + \is_null($type) ? base_path('migrations') : base_path(join_paths('migrations', $type)) ); if ($path === false) { @@ -378,3 +378,23 @@ function phpunit_version_compare(string $version, ?string $operator = null) return version_compare(Version::id(), $version, $operator); } + +/** + * Join the given paths together. + * + * @param string|null $basePath + * @param string ...$paths + * @return string + */ +function join_paths(?string $basePath, string ...$paths): string +{ + foreach ($paths as $index => $path) { + if (empty($path) && $path !== '0') { + unset($paths[$index]); + } else { + $paths[$index] = DIRECTORY_SEPARATOR.ltrim($path, DIRECTORY_SEPARATOR); + } + } + + return $basePath.implode('', $paths); +} diff --git a/tests/Helpers/PackagePathTest.php b/tests/Helpers/PackagePathTest.php index 4818ebc3b..e43620ca0 100644 --- a/tests/Helpers/PackagePathTest.php +++ b/tests/Helpers/PackagePathTest.php @@ -6,36 +6,39 @@ use function Orchestra\Testbench\package_path; +/** + * @group workbench + */ class PackagePathTest extends TestCase { - /** - * @test - * - * @group workbench - */ + /** @test */ public function it_can_use_package_path() { $this->assertSame(realpath(__DIR__.'/../../'), package_path()); $this->assertSame(implode('', [realpath(__DIR__.'/../../'), DIRECTORY_SEPARATOR]), package_path(DIRECTORY_SEPARATOR)); + } + /** + * @test + * + * @dataProvider pathDataProvider + */ + public function it_can_resolve_correct_package_path(string $path) + { $this->assertSame( - realpath(__DIR__.DIRECTORY_SEPARATOR.'PackagePathTest.php'), - package_path('./tests'.DIRECTORY_SEPARATOR.'Helpers'.DIRECTORY_SEPARATOR.'PackagePathTest.php') - ); - - $this->assertSame( - realpath(__DIR__.DIRECTORY_SEPARATOR.'PackagePathTest.php'), - package_path('./tests'.DIRECTORY_SEPARATOR.'Helpers'.DIRECTORY_SEPARATOR.'PackagePathTest.php') - ); - - $this->assertSame( - realpath(__DIR__.DIRECTORY_SEPARATOR.'PackagePathTest.php'), - package_path('tests'.DIRECTORY_SEPARATOR.'Helpers'.DIRECTORY_SEPARATOR.'PackagePathTest.php') + realpath(__DIR__.DIRECTORY_SEPARATOR.'PackagePathTest.php'), $path ); + } - $this->assertSame( - realpath(__DIR__.DIRECTORY_SEPARATOR.'PackagePathTest.php'), - package_path(DIRECTORY_SEPARATOR.'tests'.DIRECTORY_SEPARATOR.'Helpers'.DIRECTORY_SEPARATOR.'PackagePathTest.php') - ); + public static function pathDataProvider() + { + yield [package_path('tests'.DIRECTORY_SEPARATOR.'Helpers'.DIRECTORY_SEPARATOR.'PackagePathTest.php')]; + yield [package_path('./tests'.DIRECTORY_SEPARATOR.'Helpers'.DIRECTORY_SEPARATOR.'PackagePathTest.php')]; + yield [package_path(DIRECTORY_SEPARATOR.'tests'.DIRECTORY_SEPARATOR.'Helpers'.DIRECTORY_SEPARATOR.'PackagePathTest.php')]; + + yield [package_path('tests', 'Helpers', 'PackagePathTest.php')]; + yield [package_path(['tests', 'Helpers', 'PackagePathTest.php'])]; + yield [package_path('./tests', 'Helpers', 'PackagePathTest.php')]; + yield [package_path(['./tests', 'Helpers', 'PackagePathTest.php'])]; } } diff --git a/tests/Integrations/ArtisanTest.php b/tests/Integrations/ArtisanTest.php new file mode 100644 index 000000000..47d7c8c75 --- /dev/null +++ b/tests/Integrations/ArtisanTest.php @@ -0,0 +1,28 @@ +find(); + + $remote = remote('--version --no-ansi')->mustRun(); + + $artisan = (new Process( + [$phpBinary, 'artisan', '--version', '--no-ansi'], + package_path('laravel') + ))->mustRun(); + + $this->assertSame(json_decode($artisan->getOutput(), true), json_decode($remote->getOutput(), true)); + } +} diff --git a/tests/Workbench/HelpersTest.php b/tests/Workbench/HelpersTest.php index 61b73ce6d..6cc115b6c 100644 --- a/tests/Workbench/HelpersTest.php +++ b/tests/Workbench/HelpersTest.php @@ -80,9 +80,21 @@ public function it_can_resolve_workbench_without_bound() */ public function it_can_resolve_workbench_path() { + $expected = realpath(package_path('workbench/database/migrations/2013_07_26_182750_create_testbench_users_table.php')); + $this->assertSame( - realpath(package_path('workbench/database/migrations/2013_07_26_182750_create_testbench_users_table.php')), + $expected, workbench_path('database'.DIRECTORY_SEPARATOR.'migrations'.DIRECTORY_SEPARATOR.'2013_07_26_182750_create_testbench_users_table.php') ); + + $this->assertSame( + $expected, + workbench_path('database', 'migrations', '2013_07_26_182750_create_testbench_users_table.php') + ); + + $this->assertSame( + $expected, + workbench_path(['database', 'migrations', '2013_07_26_182750_create_testbench_users_table.php']) + ); } } From cd4450645db4d81c7e3a5ec45a4648a75071e380 Mon Sep 17 00:00:00 2001 From: Mior Muhammad Zaki Date: Wed, 21 Aug 2024 15:40:41 +0800 Subject: [PATCH 18/37] wip Signed-off-by: Mior Muhammad Zaki --- src/functions.php | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/functions.php b/src/functions.php index c0e6d400f..90c2e88fb 100644 --- a/src/functions.php +++ b/src/functions.php @@ -244,14 +244,12 @@ function transform_relative_path(string $path, string $workingPath): string /** * Get the default skeleton path. * - * @param string $path + * @param array|string $path * @return string */ -function default_skeleton_path(string $path = ''): string +function default_skeleton_path($path = ''): string { - $path = $path != '' ? ltrim($path, DIRECTORY_SEPARATOR) : ''; - - return (string) realpath(join_paths(__DIR__, '..', 'laravel', ...Arr::wrap($path))); + return (string) realpath(join_paths(__DIR__, '..', 'laravel', ...Arr::wrap(\func_num_args() > 1 ? \func_get_args() : $path))); } /** @@ -308,7 +306,7 @@ function workbench(): array */ function workbench_path($path = ''): string { - return package_path(join_paths('workbench', ...Arr::wrap(\func_num_args() > 1 ? \func_get_args() : $path))); + return package_path('workbench', ...Arr::wrap(\func_num_args() > 1 ? \func_get_args() : $path)); } /** From 31196f64c34601bed42509df77f87681a835f82c Mon Sep 17 00:00:00 2001 From: Mior Muhammad Zaki Date: Wed, 21 Aug 2024 15:46:39 +0800 Subject: [PATCH 19/37] wip Signed-off-by: Mior Muhammad Zaki --- src/Foundation/Console/TestCommand.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Foundation/Console/TestCommand.php b/src/Foundation/Console/TestCommand.php index 4a31fa645..d78e65c88 100644 --- a/src/Foundation/Console/TestCommand.php +++ b/src/Foundation/Console/TestCommand.php @@ -71,11 +71,11 @@ public function phpUnitConfigurationFile() $configurationFile = str_replace('./', '', $this->option('configuration') ?? 'phpunit.xml'); return Collection::make([ - package_path('/'.$configurationFile), - package_path("/{$configurationFile}.dist"), - ])->filter(static function ($path) { - return file_exists($path); - })->first() ?? './'; + package_path($configurationFile), + package_path("{$configurationFile}.dist"), + ])->transform(static fn ($path) => DIRECTORY_SEPARATOR.$path) + ->filter(static fn ($path) => file_exists($path)) + ->first() ?? './'; } /** From eeeb0948523af8d6b209da1a77ad49ec85d002ad Mon Sep 17 00:00:00 2001 From: Mior Muhammad Zaki Date: Wed, 21 Aug 2024 15:57:45 +0800 Subject: [PATCH 20/37] wip Signed-off-by: Mior Muhammad Zaki --- .github/workflows/analyse.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/analyse.yaml b/.github/workflows/analyse.yaml index ab64142a6..d1c8b9f17 100644 --- a/.github/workflows/analyse.yaml +++ b/.github/workflows/analyse.yaml @@ -50,7 +50,7 @@ jobs: os: - "ubuntu-latest" php: - - 8.1 + - 8.2 - 8.3 dependencies: - "highest" From 7ff34770ac70c04d1ebc01c178e6df3441282449 Mon Sep 17 00:00:00 2001 From: Mior Muhammad Zaki Date: Thu, 22 Aug 2024 07:00:27 +0800 Subject: [PATCH 21/37] wip Signed-off-by: Mior Muhammad Zaki --- laravel/composer.json | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/laravel/composer.json b/laravel/composer.json index 735f9c08e..7fb39bf56 100644 --- a/laravel/composer.json +++ b/laravel/composer.json @@ -5,12 +5,15 @@ "license": "MIT", "type": "project", "autoload": { - "classmap": [ - "database", - "tests/TestCase.php" - ], "psr-4": { - "App\\": "app/" + "App\\": "app/", + "Database\\Factories\\": "database/factories/", + "Database\\Seeders\\": "database/seeders/" + } + }, + "autoload-dev": { + "psr-4": { + "Tests\\": "tests/" } }, "extra": { From c61c9eba4dcef42a41c87a6b9ec83bc39123ea32 Mon Sep 17 00:00:00 2001 From: Mior Muhammad Zaki Date: Thu, 22 Aug 2024 10:23:24 +0800 Subject: [PATCH 22/37] [7.x] Add `Orchestra\Testbench\Attributes\UsesVendor` (#224) * wip Signed-off-by: Mior Muhammad Zaki * wip Signed-off-by: Mior Muhammad Zaki * wip Signed-off-by: Mior Muhammad Zaki * wip Signed-off-by: Mior Muhammad Zaki * wip Signed-off-by: Mior Muhammad Zaki * wip Signed-off-by: Mior Muhammad Zaki * wip Signed-off-by: Mior Muhammad Zaki * wip Signed-off-by: Mior Muhammad Zaki --------- Signed-off-by: Mior Muhammad Zaki --- src/Attributes/UsesVendor.php | 49 +++++++++++++++++++ .../Bootstrap/CreateVendorSymlink.php | 4 +- tests/Attributes/UsesVendorTest.php | 25 ++++++++++ 3 files changed, 77 insertions(+), 1 deletion(-) create mode 100644 src/Attributes/UsesVendor.php create mode 100644 tests/Attributes/UsesVendorTest.php diff --git a/src/Attributes/UsesVendor.php b/src/Attributes/UsesVendor.php new file mode 100644 index 000000000..ea24bc5da --- /dev/null +++ b/src/Attributes/UsesVendor.php @@ -0,0 +1,49 @@ +basePath('vendor'); + + $laravel = Application::createVendorSymlink(base_path(), package_path('vendor')); + + $this->vendorSymlinkCreated = $laravel['TESTBENCH_VENDOR_SYMLINK'] ?? false; + } + + /** + * Handle the attribute. + * + * @param \Illuminate\Foundation\Application $app + * @return void + */ + public function afterEach($app): void + { + $vendorPath = $app->basePath('vendor'); + + if (is_link($vendorPath) && $this->vendorSymlinkCreated === true) { + $app['files']->delete($vendorPath); + } + } +} diff --git a/src/Foundation/Bootstrap/CreateVendorSymlink.php b/src/Foundation/Bootstrap/CreateVendorSymlink.php index 0807b8fe0..3ebcb5d49 100644 --- a/src/Foundation/Bootstrap/CreateVendorSymlink.php +++ b/src/Foundation/Bootstrap/CreateVendorSymlink.php @@ -56,8 +56,10 @@ public function bootstrap(Application $app): void try { $filesystem->link($this->workingPath, $appVendorPath); + + $app->instance('TESTBENCH_VENDOR_SYMLINK', true); } catch (ErrorException $e) { - // + $app->instance('TESTBENCH_VENDOR_SYMLINK', false); } } diff --git a/tests/Attributes/UsesVendorTest.php b/tests/Attributes/UsesVendorTest.php new file mode 100644 index 000000000..f0a5b2b71 --- /dev/null +++ b/tests/Attributes/UsesVendorTest.php @@ -0,0 +1,25 @@ +assertSame( + $filesystem->hash(base_path(join_paths('vendor', 'autoload.php'))), + $filesystem->hash(package_path('vendor', 'autoload.php')) + ); + } +} From cebbfb0ac903b6aecd17ec1710efe61102aa3a4f Mon Sep 17 00:00:00 2001 From: Mior Muhammad Zaki Date: Thu, 22 Aug 2024 10:54:47 +0800 Subject: [PATCH 23/37] wip Signed-off-by: Mior Muhammad Zaki --- tests/Attributes/UsesVendorTest.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/Attributes/UsesVendorTest.php b/tests/Attributes/UsesVendorTest.php index f0a5b2b71..2a67f947d 100644 --- a/tests/Attributes/UsesVendorTest.php +++ b/tests/Attributes/UsesVendorTest.php @@ -5,13 +5,14 @@ use Illuminate\Filesystem\Filesystem; use Orchestra\Testbench\Attributes\UsesVendor; use Orchestra\Testbench\TestCase; +use PHPUnit\Framework\Attributes\Test; use function Orchestra\Testbench\join_paths; use function Orchestra\Testbench\package_path; class UsesVendorTest extends TestCase { - /** @test */ + #[Test] #[UsesVendor] public function it_can_uses_vendor_attribute() { From 7491beda72e9da6d31bd24f9ae87acdbe03f93d5 Mon Sep 17 00:00:00 2001 From: Mior Muhammad Zaki Date: Thu, 22 Aug 2024 16:13:39 +0800 Subject: [PATCH 24/37] wip Signed-off-by: Mior Muhammad Zaki --- .github/workflows/collision-tests.yaml | 1 - .github/workflows/coveralls.yaml | 2 +- .github/workflows/tests.yaml | 3 +-- 3 files changed, 2 insertions(+), 4 deletions(-) diff --git a/.github/workflows/collision-tests.yaml b/.github/workflows/collision-tests.yaml index a3d96598c..23a06be30 100644 --- a/.github/workflows/collision-tests.yaml +++ b/.github/workflows/collision-tests.yaml @@ -22,7 +22,6 @@ jobs: phpunit: - "^9.5.10" dependencies: - - "locked" - "highest" experimental: - false diff --git a/.github/workflows/coveralls.yaml b/.github/workflows/coveralls.yaml index cefe69f5a..a14837791 100644 --- a/.github/workflows/coveralls.yaml +++ b/.github/workflows/coveralls.yaml @@ -15,7 +15,7 @@ jobs: php: - 8.1 dependencies: - - "locked" + - "highest" experimental: - false diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index a80a2696c..4aae02bd5 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -21,9 +21,8 @@ jobs: phpunit: - "^8.5.21" dependencies: - - "locked" - - "lowest" - "highest" + - "lowest" experimental: - false From ee6af6c4cd1cb9864d7de4d11f05f5a7fb4faeda Mon Sep 17 00:00:00 2001 From: Mior Muhammad Zaki Date: Thu, 22 Aug 2024 17:24:31 +0800 Subject: [PATCH 25/37] [9.x] Allow serializing Closure using `defineCacheRoute()` (#226) * wip Signed-off-by: Mior Muhammad Zaki * wip Signed-off-by: Mior Muhammad Zaki * wip Signed-off-by: Mior Muhammad Zaki * wip Signed-off-by: Mior Muhammad Zaki --------- Signed-off-by: Mior Muhammad Zaki --- composer.json | 1 + laravel/bootstrap/app.php | 2 +- src/Concerns/HandlesRoutes.php | 40 ++++++++++++++----- src/Concerns/stubs/routes.stub | 9 +++++ .../Bootstrap/SyncTestbenchCachedRoutes.php | 2 +- .../SyncTestbenchConfigurationFiles.php | 2 +- tests/Integrations/ClosureCacheRouteTest.php | 30 ++++++++++++++ 7 files changed, 72 insertions(+), 14 deletions(-) create mode 100644 src/Concerns/stubs/routes.stub rename src/Foundation/{Console => }/Bootstrap/SyncTestbenchCachedRoutes.php (92%) rename src/Foundation/{Console => }/Bootstrap/SyncTestbenchConfigurationFiles.php (94%) create mode 100644 tests/Integrations/ClosureCacheRouteTest.php diff --git a/composer.json b/composer.json index ae695f646..a52a77a1e 100644 --- a/composer.json +++ b/composer.json @@ -54,6 +54,7 @@ "conflict": { "brianium/paratest": "<7.3.0 || >=8.0.0", "laravel/framework": "<11.11.0 || >=12.0.0", + "laravel/serializable-closure": "<1.3.0 || >=2.0.0", "nunomaduro/collision": "<8.0.0 || >=9.0.0", "phpunit/phpunit": "<10.5.0 || 11.0.0 || >=11.4.0" }, diff --git a/laravel/bootstrap/app.php b/laravel/bootstrap/app.php index bf41ec9ac..309c96471 100644 --- a/laravel/bootstrap/app.php +++ b/laravel/bootstrap/app.php @@ -1,8 +1,8 @@ get(join_paths(__DIR__, 'stubs', 'routes.stub')); + $route = str_replace('{{routes}}', (string) json_encode($serializeRoute), $stub); + } + $files->put( join_paths($basePath, 'routes', "testbench-{$time}.php"), $route ); - remote('route:cache')->mustRun(); + if ($cached === true) { + remote('route:cache')->mustRun(); - $this->assertTrue( - $files->exists(join_paths($bootstrapPath, 'cache', 'routes-v7.php')) - ); + assert($files->exists(join_paths($bootstrapPath, 'cache', 'routes-v7.php')) === true); + } if ($this->app instanceof LaravelApplication) { $this->reloadApplication(); } - $this->requireApplicationCachedRoutes($files); + $this->requireApplicationCachedRoutes($files, $cached); } /** @@ -123,11 +135,17 @@ protected function defineCacheRoutes(string $route) * @param \Illuminate\Filesystem\Filesystem $files * @return void */ - protected function requireApplicationCachedRoutes(Filesystem $files): void + protected function requireApplicationCachedRoutes(Filesystem $files, bool $cached): void { - $this->afterApplicationCreated(function () { - if ($this->app instanceof LaravelApplication) { - require $this->app->getCachedRoutesPath(); + $this->afterApplicationCreated(function () use ($cached) { + $app = $this->app; + + if ($app instanceof LaravelApplication) { + if ($cached === true) { + require $app->getCachedRoutesPath(); + } else { + (new SyncTestbenchCachedRoutes)->bootstrap($app); + } } }); diff --git a/src/Concerns/stubs/routes.stub b/src/Concerns/stubs/routes.stub new file mode 100644 index 000000000..b725e524d --- /dev/null +++ b/src/Concerns/stubs/routes.stub @@ -0,0 +1,9 @@ +getClosure(), function ($serializedClosure) use ($router) { + if ($serializedClosure instanceof Closure) { + value($serializedClosure, $router); + } +}); diff --git a/src/Foundation/Console/Bootstrap/SyncTestbenchCachedRoutes.php b/src/Foundation/Bootstrap/SyncTestbenchCachedRoutes.php similarity index 92% rename from src/Foundation/Console/Bootstrap/SyncTestbenchCachedRoutes.php rename to src/Foundation/Bootstrap/SyncTestbenchCachedRoutes.php index 61ac2d04d..2086c17b0 100644 --- a/src/Foundation/Console/Bootstrap/SyncTestbenchCachedRoutes.php +++ b/src/Foundation/Bootstrap/SyncTestbenchCachedRoutes.php @@ -1,6 +1,6 @@ defineCacheRoutes(function () { + Route::get('stubs-controller', 'Workbench\App\Http\Controllers\ExampleController@index'); + }); + + parent::setUp(); + } + + #[Test] + public function it_can_cache_route() + { + $this->get('stubs-controller') + ->assertOk() + ->assertSee('ExampleController@index'); + } +} From a40c510bd2a745fbdfa47fd1f5edce00cead3a53 Mon Sep 17 00:00:00 2001 From: Mior Muhammad Zaki Date: Thu, 22 Aug 2024 17:44:05 +0800 Subject: [PATCH 26/37] wip Signed-off-by: Mior Muhammad Zaki --- src/Concerns/HandlesRoutes.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Concerns/HandlesRoutes.php b/src/Concerns/HandlesRoutes.php index 78056f513..d90e1a64e 100644 --- a/src/Concerns/HandlesRoutes.php +++ b/src/Concerns/HandlesRoutes.php @@ -107,7 +107,7 @@ protected function defineCacheRoutes(Closure|string $route, bool $cached = true) /** @var string $serializeRoute */ $serializeRoute = serialize(SerializableClosure::unsigned($route)); $stub = $files->get(join_paths(__DIR__, 'stubs', 'routes.stub')); - $route = str_replace('{{routes}}', (string) json_encode($serializeRoute), $stub); + $route = str_replace('{{routes}}', var_export($serializeRoute, true), $stub); } $files->put( From 150468241cd485a75ad371f86a0419601391a945 Mon Sep 17 00:00:00 2001 From: Mior Muhammad Zaki Date: Thu, 22 Aug 2024 18:32:00 +0800 Subject: [PATCH 27/37] wip Signed-off-by: Mior Muhammad Zaki --- src/Concerns/HandlesRoutes.php | 14 ++++++++++++++ tests/Integrations/RequestTest.php | 8 ++------ ...losureCacheRouteTest.php => StashRouteTest.php} | 9 ++++----- 3 files changed, 20 insertions(+), 11 deletions(-) rename tests/Integrations/{ClosureCacheRouteTest.php => StashRouteTest.php} (79%) diff --git a/src/Concerns/HandlesRoutes.php b/src/Concerns/HandlesRoutes.php index d90e1a64e..054573b0e 100644 --- a/src/Concerns/HandlesRoutes.php +++ b/src/Concerns/HandlesRoutes.php @@ -82,6 +82,20 @@ protected function defineWebRoutes($router) // Define routes. } + /** + * Define stash routes setup. + * + * @api + * + * @param \Closure|string $route + * @param bool $cached + * @return void + */ + protected function defineStashRoutes(Closure|string $route): void + { + $this->defineCacheRoutes($route, false); + } + /** * Define cache routes setup. * diff --git a/tests/Integrations/RequestTest.php b/tests/Integrations/RequestTest.php index 9b929682d..60e6272f1 100644 --- a/tests/Integrations/RequestTest.php +++ b/tests/Integrations/RequestTest.php @@ -10,12 +10,8 @@ #[WithConfig('app.key', 'AckfSECXIvnK5r28GVIWUAxmbBSjTsmF')] class RequestTest extends TestCase { - /** - * Define routes setup. - * - * @param \Illuminate\Routing\Router $router - * @return void - */ + /** {@inheritDoc} */ + #[\Override] protected function defineRoutes($router) { $router->get('hello', ['uses' => fn () => 'hello world']); diff --git a/tests/Integrations/ClosureCacheRouteTest.php b/tests/Integrations/StashRouteTest.php similarity index 79% rename from tests/Integrations/ClosureCacheRouteTest.php rename to tests/Integrations/StashRouteTest.php index eaf57420e..76b8cfcf9 100644 --- a/tests/Integrations/ClosureCacheRouteTest.php +++ b/tests/Integrations/StashRouteTest.php @@ -6,14 +6,13 @@ use Orchestra\Testbench\TestCase; use PHPUnit\Framework\Attributes\Test; -class ClosureCacheRouteTest extends TestCase +class StashRouteTest extends TestCase { - /** - * Setup the test environment. - */ + /** {@inheritDoc} */ + #[\Override] protected function setUp(): void { - $this->defineCacheRoutes(function () { + $this->defineStashRoutes(function () { Route::get('stubs-controller', 'Workbench\App\Http\Controllers\ExampleController@index'); }); From 2f2924e7573e89549cf80717949fb38ad0d48bc6 Mon Sep 17 00:00:00 2001 From: Mior Muhammad Zaki Date: Thu, 22 Aug 2024 18:51:17 +0800 Subject: [PATCH 28/37] [7.x] Allow serializing Closure using `defineCacheRoute()` (#227) * wip Signed-off-by: Mior Muhammad Zaki * wip Signed-off-by: Mior Muhammad Zaki --------- Signed-off-by: Mior Muhammad Zaki --- composer.json | 1 + laravel/bootstrap/app.php | 2 +- src/Concerns/HandlesRoutes.php | 56 ++++++++++++++----- src/Concerns/stubs/routes.stub | 9 +++ .../Bootstrap/SyncTestbenchCachedRoutes.php | 2 +- .../SyncTestbenchConfigurationFiles.php | 2 +- tests/Integrations/StashRouteTest.php | 30 ++++++++++ 7 files changed, 86 insertions(+), 16 deletions(-) create mode 100644 src/Concerns/stubs/routes.stub rename src/Foundation/{Console => }/Bootstrap/SyncTestbenchCachedRoutes.php (92%) rename src/Foundation/{Console => }/Bootstrap/SyncTestbenchConfigurationFiles.php (94%) create mode 100644 tests/Integrations/StashRouteTest.php diff --git a/composer.json b/composer.json index 1e003974c..49020b288 100644 --- a/composer.json +++ b/composer.json @@ -53,6 +53,7 @@ "conflict": { "brianium/paratest": "<6.4.0 || >=7.0.0", "laravel/framework": "<9.52.16 || >=10.0.0", + "laravel/serializable-closure": "<1.3.0 || >=2.0.0", "orchestra/testbench-dusk": "<7.39.0 || >=8.0.0", "orchestra/workbench": "<1.0.0", "nunomaduro/collision": "<6.2.0 || >=7.0.0", diff --git a/laravel/bootstrap/app.php b/laravel/bootstrap/app.php index bf41ec9ac..309c96471 100644 --- a/laravel/bootstrap/app.php +++ b/laravel/bootstrap/app.php @@ -1,8 +1,8 @@ defineCacheRoutes($route, false); + } + /** * Define cache routes setup. * - * @param string $route + * @param \Closure|string $route + * @param bool $cached * @return void */ - protected function defineCacheRoutes(string $route) + protected function defineCacheRoutes(Closure|string $route, bool $cached = true): void { $files = new Filesystem; $time = time(); - $laravel = Application::create(static::applicationBasePath()); + $basePath = static::applicationBasePath(); + $bootstrapPath = join_paths($basePath, 'bootstrap'); + + if ($route instanceof Closure) { + $cached = false; + /** @var string $serializeRoute */ + $serializeRoute = serialize(SerializableClosure::unsigned($route)); + $stub = $files->get(join_paths(__DIR__, 'stubs', 'routes.stub')); + $route = str_replace('{{routes}}', (string) json_encode($serializeRoute), $stub); + } $files->put( - $laravel->basePath(join_paths('routes', "testbench-{$time}.php")), $route + join_paths($basePath, 'routes', "testbench-{$time}.php"), $route ); - remote('route:cache')->mustRun(); + if ($cached === true) { + remote('route:cache')->mustRun(); - $this->assertTrue( - $files->exists($laravel->bootstrapPath(join_paths('cache', 'routes-v7.php'))) - ); + \assert($files->exists(join_paths($bootstrapPath, 'cache', 'routes-v7.php')) === true); + } if ($this->app instanceof LaravelApplication) { $this->reloadApplication(); } - $this->requireApplicationCachedRoutes($files); + $this->requireApplicationCachedRoutes($files, $cached); } /** * Require application cached routes. */ - protected function requireApplicationCachedRoutes(Filesystem $files): void + protected function requireApplicationCachedRoutes(Filesystem $files, bool $cached): void { - $this->afterApplicationCreated(function () { - if ($this->app instanceof LaravelApplication) { - require $this->app->getCachedRoutesPath(); + $this->afterApplicationCreated(function () use ($cached) { + $app = $this->app; + + if ($app instanceof LaravelApplication) { + if ($cached === true) { + require $app->getCachedRoutesPath(); + } else { + (new SyncTestbenchCachedRoutes)->bootstrap($app); + } } }); diff --git a/src/Concerns/stubs/routes.stub b/src/Concerns/stubs/routes.stub new file mode 100644 index 000000000..b725e524d --- /dev/null +++ b/src/Concerns/stubs/routes.stub @@ -0,0 +1,9 @@ +getClosure(), function ($serializedClosure) use ($router) { + if ($serializedClosure instanceof Closure) { + value($serializedClosure, $router); + } +}); diff --git a/src/Foundation/Console/Bootstrap/SyncTestbenchCachedRoutes.php b/src/Foundation/Bootstrap/SyncTestbenchCachedRoutes.php similarity index 92% rename from src/Foundation/Console/Bootstrap/SyncTestbenchCachedRoutes.php rename to src/Foundation/Bootstrap/SyncTestbenchCachedRoutes.php index 61ac2d04d..2086c17b0 100644 --- a/src/Foundation/Console/Bootstrap/SyncTestbenchCachedRoutes.php +++ b/src/Foundation/Bootstrap/SyncTestbenchCachedRoutes.php @@ -1,6 +1,6 @@ defineStashRoutes(function () { + Route::get('stubs-controller', 'Workbench\App\Http\Controllers\ExampleController@index'); + }); + + parent::setUp(); + } + + /** @test */ + public function it_can_cache_route() + { + $this->get('stubs-controller') + ->assertOk() + ->assertSee('ExampleController@index'); + } +} From 18cb72d35c3f2ccbc120393c393ebe8f7acbd028 Mon Sep 17 00:00:00 2001 From: Mior Muhammad Zaki Date: Thu, 22 Aug 2024 23:25:11 +0800 Subject: [PATCH 29/37] wip Signed-off-by: Mior Muhammad Zaki --- tests/Integrations/ArtisanTest.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/Integrations/ArtisanTest.php b/tests/Integrations/ArtisanTest.php index 47d7c8c75..761001539 100644 --- a/tests/Integrations/ArtisanTest.php +++ b/tests/Integrations/ArtisanTest.php @@ -11,7 +11,10 @@ class ArtisanTest extends TestCase { - /** @test */ + /** + * @test + * @group core + */ public function it_can_generate_the_same_output() { $phpBinary = \defined('PHP_BINARY') ? PHP_BINARY : (new PhpExecutableFinder)->find(); From 85b82f3ec5abd80d5c7c5c063b7477183d8ffefc Mon Sep 17 00:00:00 2001 From: Mior Muhammad Zaki Date: Fri, 23 Aug 2024 08:39:34 +0800 Subject: [PATCH 30/37] wip Signed-off-by: Mior Muhammad Zaki --- src/Concerns/InteractsWithPublishedFiles.php | 2 +- src/Foundation/Application.php | 2 +- src/Foundation/Config.php | 2 +- src/Foundation/Console/Actions/GeneratesFile.php | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Concerns/InteractsWithPublishedFiles.php b/src/Concerns/InteractsWithPublishedFiles.php index a7189eb29..6d08fc843 100644 --- a/src/Concerns/InteractsWithPublishedFiles.php +++ b/src/Concerns/InteractsWithPublishedFiles.php @@ -4,7 +4,7 @@ use Illuminate\Support\Collection; -use function Illuminate\Filesystem\join_paths; +use function Orchestra\Testbench\join_paths; /** * @internal diff --git a/src/Foundation/Application.php b/src/Foundation/Application.php index e7b924f6b..2d892399f 100644 --- a/src/Foundation/Application.php +++ b/src/Foundation/Application.php @@ -20,7 +20,7 @@ use Orchestra\Testbench\Contracts\Config as ConfigContract; use Orchestra\Testbench\Workbench\Workbench; -use function Illuminate\Filesystem\join_paths; +use function Orchestra\Testbench\join_paths; /** * @api diff --git a/src/Foundation/Config.php b/src/Foundation/Config.php index c4a372618..901642135 100644 --- a/src/Foundation/Config.php +++ b/src/Foundation/Config.php @@ -8,7 +8,7 @@ use Orchestra\Testbench\Contracts\Config as ConfigContract; use Symfony\Component\Yaml\Yaml; -use function Illuminate\Filesystem\join_paths; +use function Orchestra\Testbench\join_paths; use function Orchestra\Testbench\parse_environment_variables; use function Orchestra\Testbench\transform_relative_path; diff --git a/src/Foundation/Console/Actions/GeneratesFile.php b/src/Foundation/Console/Actions/GeneratesFile.php index 664e982a6..1a75eb575 100644 --- a/src/Foundation/Console/Actions/GeneratesFile.php +++ b/src/Foundation/Console/Actions/GeneratesFile.php @@ -5,7 +5,7 @@ use Illuminate\Console\View\Components\Factory as ComponentsFactory; use Illuminate\Filesystem\Filesystem; -use function Illuminate\Filesystem\join_paths; +use function Orchestra\Testbench\join_paths; use function Laravel\Prompts\confirm; class GeneratesFile extends Action From 79ff43a628ab73b3161b688ae5ee9d100596cc14 Mon Sep 17 00:00:00 2001 From: Mior Muhammad Zaki Date: Fri, 23 Aug 2024 08:42:47 +0800 Subject: [PATCH 31/37] wip Signed-off-by: Mior Muhammad Zaki --- src/Foundation/Console/Actions/GeneratesFile.php | 2 +- tests/Integrations/ArtisanTest.php | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Foundation/Console/Actions/GeneratesFile.php b/src/Foundation/Console/Actions/GeneratesFile.php index 1a75eb575..ca11c2cd5 100644 --- a/src/Foundation/Console/Actions/GeneratesFile.php +++ b/src/Foundation/Console/Actions/GeneratesFile.php @@ -5,8 +5,8 @@ use Illuminate\Console\View\Components\Factory as ComponentsFactory; use Illuminate\Filesystem\Filesystem; -use function Orchestra\Testbench\join_paths; use function Laravel\Prompts\confirm; +use function Orchestra\Testbench\join_paths; class GeneratesFile extends Action { diff --git a/tests/Integrations/ArtisanTest.php b/tests/Integrations/ArtisanTest.php index fdbb0c484..265c6c275 100644 --- a/tests/Integrations/ArtisanTest.php +++ b/tests/Integrations/ArtisanTest.php @@ -13,6 +13,7 @@ class ArtisanTest extends TestCase { /** * @test + * * @group core */ public function it_can_generate_the_same_output() From 2dbb0702cd01c8720228b9d00752334b938e2370 Mon Sep 17 00:00:00 2001 From: Mior Muhammad Zaki Date: Sat, 24 Aug 2024 11:17:49 +0800 Subject: [PATCH 32/37] wip Signed-off-by: Mior Muhammad Zaki --- src/Concerns/Testing.php | 6 +++--- tests/Integrations/ArtisanTest.php | 1 + 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/Concerns/Testing.php b/src/Concerns/Testing.php index 5fe523f1c..d425da1a8 100644 --- a/src/Concerns/Testing.php +++ b/src/Concerns/Testing.php @@ -248,7 +248,7 @@ protected function tearDownParallelTestingCallbacks(): void * @param callable():void $callback * @return void */ - protected function afterApplicationRefreshed(callable $callback): void + public function afterApplicationRefreshed(callable $callback): void { $this->afterApplicationRefreshedCallbacks[] = $callback; @@ -263,7 +263,7 @@ protected function afterApplicationRefreshed(callable $callback): void * @param callable():void $callback * @return void */ - protected function afterApplicationCreated(callable $callback): void + public function afterApplicationCreated(callable $callback): void { $this->afterApplicationCreatedCallbacks[] = $callback; @@ -278,7 +278,7 @@ protected function afterApplicationCreated(callable $callback): void * @param callable():void $callback * @return void */ - protected function beforeApplicationDestroyed(callable $callback): void + public function beforeApplicationDestroyed(callable $callback): void { array_unshift($this->beforeApplicationDestroyedCallbacks, $callback); } diff --git a/tests/Integrations/ArtisanTest.php b/tests/Integrations/ArtisanTest.php index 761001539..396c9a9e2 100644 --- a/tests/Integrations/ArtisanTest.php +++ b/tests/Integrations/ArtisanTest.php @@ -13,6 +13,7 @@ class ArtisanTest extends TestCase { /** * @test + * * @group core */ public function it_can_generate_the_same_output() From c5c3006005b18950020de30e49a3e711056f8349 Mon Sep 17 00:00:00 2001 From: Mior Muhammad Zaki Date: Mon, 26 Aug 2024 12:02:06 +0800 Subject: [PATCH 33/37] Prepare 6.52.0 release Signed-off-by: Mior Muhammad Zaki --- CHANGELOG-6.x.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/CHANGELOG-6.x.md b/CHANGELOG-6.x.md index eaa98134c..3b76145d4 100644 --- a/CHANGELOG-6.x.md +++ b/CHANGELOG-6.x.md @@ -2,6 +2,20 @@ This changelog references the relevant changes (bug and security fixes) done to `orchestra/testbench-core`. +## 6.52.0 + +Released: 2024-08-26 + +### Added + +* Added `artisan` binary to Laravel skeleton. +* Added `Orchestra\Testbench\join_paths()` function. + +### Changes + +* Change `afterApplicationCreated()`, `afterApplicationRefreshed()`, and `beforeApplicationDestroyed()` methods visibility from `protected` to `public`. +* Improvements to `Orchestra\Testbench\default_skeleton_path()`, `Orchestra\Testbench\package_path()`, and `Orchestra\Testbench\workbench_path()` usage based on new `Orchestra\Testbench\join_paths()` function. + ## 6.51.2 Released: 2024-08-14 From 2b12c28730311e9f048f9730cf54d4b1e136c267 Mon Sep 17 00:00:00 2001 From: Mior Muhammad Zaki Date: Mon, 26 Aug 2024 12:16:03 +0800 Subject: [PATCH 34/37] wip Signed-off-by: Mior Muhammad Zaki --- src/Concerns/HandlesRoutes.php | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/Concerns/HandlesRoutes.php b/src/Concerns/HandlesRoutes.php index db91020c5..d6fa077e0 100644 --- a/src/Concerns/HandlesRoutes.php +++ b/src/Concerns/HandlesRoutes.php @@ -20,6 +20,13 @@ */ trait HandlesRoutes { + /** + * Indicates if we have made it through the requireApplicationCachedRoutes function. + * + * @var bool + */ + protected $requireApplicationCachedRoutesHasRun = false; + /** * Setup routes requirements. * @@ -130,6 +137,10 @@ protected function defineCacheRoutes(Closure|string $route, bool $cached = true) */ protected function requireApplicationCachedRoutes(Filesystem $files, bool $cached): void { + if ($this->requireApplicationCachedRoutesHasRun === true) { + return; + } + $this->afterApplicationCreated(function () use ($cached) { $app = $this->app; @@ -152,5 +163,7 @@ protected function requireApplicationCachedRoutes(Filesystem $files, bool $cache sleep(1); }); + + $this->requireApplicationCachedRoutesHasRun = true; } } From c3861b172a7f912215485f2bd91f93b2870e5df5 Mon Sep 17 00:00:00 2001 From: Mior Muhammad Zaki Date: Mon, 26 Aug 2024 12:19:12 +0800 Subject: [PATCH 35/37] Prepare 7.46.0 release Signed-off-by: Mior Muhammad Zaki --- CHANGELOG-7.x.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/CHANGELOG-7.x.md b/CHANGELOG-7.x.md index 3884ec9ef..20119cc04 100644 --- a/CHANGELOG-7.x.md +++ b/CHANGELOG-7.x.md @@ -2,6 +2,22 @@ This changelog references the relevant changes (bug and security fixes) done to `orchestra/testbench-core`. +## 7.46.0 + +Released: 2024-08-26 + +### Added + +* Added `artisan` binary to Laravel skeleton. +* Added `Orchestra\Testbench\join_paths()` function. +* Added `Orchestra\Testbench\Attributes\UsesVendor` attribute class. +* Added `defineStashRoutes()` method to register adhoc route for test. + +### Changes + +* Change `afterApplicationCreated()`, `afterApplicationRefreshed()`, and `beforeApplicationDestroyed()` methods visibility from `protected` to `public`. +* Improvements to `Orchestra\Testbench\default_skeleton_path()`, `Orchestra\Testbench\package_path()`, and `Orchestra\Testbench\workbench_path()` usage based on new `Orchestra\Testbench\join_paths()` function. + ## 7.45.0 Released: 2024-08-14 From 95185200e654c75e4d5d6626f6ec139c5a4699ca Mon Sep 17 00:00:00 2001 From: Mior Muhammad Zaki Date: Mon, 26 Aug 2024 12:43:39 +0800 Subject: [PATCH 36/37] Prepare 8.27.0 release Signed-off-by: Mior Muhammad Zaki --- CHANGELOG-8.x.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/CHANGELOG-8.x.md b/CHANGELOG-8.x.md index 1e94cbf0a..21b2dd9e3 100644 --- a/CHANGELOG-8.x.md +++ b/CHANGELOG-8.x.md @@ -2,6 +2,21 @@ This changelog references the relevant changes (bug and security fixes) done to `orchestra/testbench-core`. +## 8.27.0 + +Released: 2024-08-26 + +### Added + +* Added `artisan` binary to Laravel skeleton. +* Added `Orchestra\Testbench\join_paths()` function. +* Added `Orchestra\Testbench\Attributes\UsesVendor` attribute class. +* Added `defineStashRoutes()` method to register adhoc route for test. + +### Changes + +* Improvements to `Orchestra\Testbench\default_skeleton_path()`, `Orchestra\Testbench\package_path()`, and `Orchestra\Testbench\workbench_path()` usage based on new `Orchestra\Testbench\join_paths()` function. + ## 8.26.0 Released: 2024-08-14 From 422827e195741ca397408eced09ca473ebbb4086 Mon Sep 17 00:00:00 2001 From: Mior Muhammad Zaki Date: Mon, 26 Aug 2024 13:01:33 +0800 Subject: [PATCH 37/37] Prepare 9.4.0 release Signed-off-by: Mior Muhammad Zaki --- CHANGELOG-9.x.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/CHANGELOG-9.x.md b/CHANGELOG-9.x.md index 05e8e02f2..7f7d922db 100644 --- a/CHANGELOG-9.x.md +++ b/CHANGELOG-9.x.md @@ -2,6 +2,21 @@ This changelog references the relevant changes (bug and security fixes) done to `orchestra/testbench-core`. +## 9.4.0 + +Released: 2024-08-26 + +### Added + +* Added `artisan` binary to Laravel skeleton. +* Added `Orchestra\Testbench\join_paths()` function. +* Added `Orchestra\Testbench\Attributes\UsesVendor` attribute class. +* Added `defineStashRoutes()` method to register adhoc route for test. + +### Changes + +* Improvements to `Orchestra\Testbench\default_skeleton_path()`, `Orchestra\Testbench\package_path()`, and `Orchestra\Testbench\workbench_path()` usage based on new `Orchestra\Testbench\join_paths()` function. + ## 9.3.0 Released: 2024-08-14