Skip to content

Commit

Permalink
Merge branch '9.x' into 10.x
Browse files Browse the repository at this point in the history
Signed-off-by: Mior Muhammad Zaki <crynobone@gmail.com>
  • Loading branch information
crynobone committed Dec 2, 2024
2 parents 3a23130 + 4b405d3 commit 27a694f
Show file tree
Hide file tree
Showing 25 changed files with 502 additions and 149 deletions.
13 changes: 12 additions & 1 deletion CHANGELOG-8.x.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@

This changelog references the relevant changes (bug and security fixes) done to `orchestra/testbench-core`.

## 8.30.0 (Unreleased)
## 8.30.0

Released: 2024-12-01

### Added

* Added ability to detect Workbench namespace via `Orchestra\Testbench\Workbench\Workbench::detectNamespace()` method.
* Added ability to detect the default user model via `Orchestra\Testbench\Workbench\Workbench::applicationUserModel()` method.
* Added support for authentication routes within Workbench by configurating `workbench.auth` config to `true`.
* Added new `package:sync-skeleton` command.

### Changes

Expand All @@ -17,6 +20,14 @@ This changelog references the relevant changes (bug and security fixes) done to
- Refactor `Orchestra\Testbench\Console\Commander`.
* Add multiple environment variables to Laravel 10 skeleton's configuration files based on changes made for Laravel 11.
* Add `$tty` parameter to `Orchestra\Testbench\remote()` function.
* Refactor `Orchestra\Testbench\Foundation\Bootstrap\CreateVendorSymlink` class and mark it as `@api`.
* Add `$backupExistingFile` and `$resetOnTerminating` parameter to following methods in `Orchestra\Testbench\Foundation\Console\Concerns\CopyTestbenchFiles` trait:
- `copyTestbenchConfigurationFile()`
- `copyTestbenchDotEnvFile()`

### Deprecated

* Deprecate `Orchestra\Testbench\Foundation\Console\Concerns\HandleTerminatingConsole` trait, use `Orchestra\Testbench\Foundation\Console\TerminatingConsole` class instead.

## 8.29.0

Expand Down
13 changes: 12 additions & 1 deletion CHANGELOG-9.x.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,33 @@

This changelog references the relevant changes (bug and security fixes) done to `orchestra/testbench-core`.

## 9.7.0 (Unreleased)
## 9.7.0

Released: 2024-12-01

### Added

* Added ability to detect Workbench namespace via `Orchestra\Testbench\Workbench\Workbench::detectNamespace()` method.
* Added ability to detect the default user model via `Orchestra\Testbench\Workbench\Workbench::applicationUserModel()` method.
* Added support for authentication routes within Workbench by configurating `workbench.auth` config to `true`.
* Added new `package:sync-skeleton` command.

### Changes

* Testbench Dusk integration improvements:
- Refactor `Orchestra\Testbench\Bootstrap\LoadConfiguration` and `Orchestra\Testbench\Bootstrap\LoadConfigurationWithWorkbench` to allow being extended by Testbench Dusk.
- Refactor `Orchestra\Testbench\Console\Commander`.
* Add `$tty` parameter to `Orchestra\Testbench\remote()` function.
* Refactor `Orchestra\Testbench\Foundation\Bootstrap\CreateVendorSymlink` class and mark it as `@api`.
* Add `$backupExistingFile` and `$resetOnTerminating` parameter to following methods in `Orchestra\Testbench\Foundation\Console\Concerns\CopyTestbenchFiles` trait:
- `copyTestbenchConfigurationFile()`
- `copyTestbenchDotEnvFile()`
* Supports `laravel/serializable-closure` v2.

### Deprecated

* Deprecate `Orchestra\Testbench\Foundation\Console\Concerns\HandleTerminatingConsole` trait, use `Orchestra\Testbench\Foundation\Console\TerminatingConsole` class instead.

## 9.6.2

Released: 2024-11-21
Expand Down
2 changes: 2 additions & 0 deletions bin/sync
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ $files->ensureDirectoryExists("{$workingPath}/laravel/migrations/notifications")
$files->ensureDirectoryExists("{$workingPath}/laravel/migrations/queue");
$files->ensureDirectoryExists("{$workingPath}/laravel/migrations/session");

$files->put("{$workingPath}/laravel/bootstrap/.testbench-default-skeleton", '@testbench'.PHP_EOL);

/**
* ----------------------------------------------------------------------
* Copy files from `laravel/laravel`
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
},
"require-dev": {
"fakerphp/faker": "^1.24",
"laravel/framework": "^12.0",
"laravel/framework": "^12.0.0",
"laravel/pint": "^1.17",
"laravel/serializable-closure": "^1.3 || ^2.0",
"mockery/mockery": "^1.6.10",
Expand All @@ -64,7 +64,7 @@
"ext-pcntl": "Required to use all features of the console signal trapping.",
"brianium/paratest": "Allow using parallel testing (^7.3).",
"fakerphp/faker": "Allow using Faker for testing (^1.23).",
"laravel/framework": "Required for testing (^12.0).",
"laravel/framework": "Required for testing (^12.0.0).",
"mockery/mockery": "Allow using Mockery for testing (^1.6).",
"nunomaduro/collision": "Allow using Laravel style tests output and parallel testing (^8.0).",
"orchestra/testbench-dusk": "Allow using Laravel Dusk for testing (^9.0).",
Expand Down
1 change: 1 addition & 0 deletions laravel/bootstrap/.testbench-default-skeleton
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@testbench
7 changes: 4 additions & 3 deletions laravel/bootstrap/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,13 @@
*/
$createApp = static function (string $workingPath) {
$config = Config::loadFromYaml(
defined('TESTBENCH_WORKING_PATH') ? TESTBENCH_WORKING_PATH : $workingPath
workingPath: defined('TESTBENCH_WORKING_PATH') ? TESTBENCH_WORKING_PATH : $workingPath,
filename: defined('TESTBENCH_WORKING_PATH') ? 'testbench.yaml' : join_paths($workingPath, 'bootstrap', 'cache', 'testbench.yaml')
);

$hasEnvironmentFile = ! is_null($config['laravel'])
? file_exists(join_paths($config['laravel'], '.env'))
: file_exists(join_paths($workingPath, '.env'));
? is_file(join_paths($config['laravel'], '.env'))
: is_file(join_paths($workingPath, '.env'));

return Application::create(
basePath: $config['laravel'],
Expand Down
4 changes: 2 additions & 2 deletions src/Attributes/UsesVendor.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
use Attribute;
use Orchestra\Testbench\Contracts\Attributes\AfterEach as AfterEachContract;
use Orchestra\Testbench\Contracts\Attributes\BeforeEach as BeforeEachContract;
use Orchestra\Testbench\Foundation\Actions\DeleteVendorSymlink;
use Orchestra\Testbench\Foundation\Application;
use Orchestra\Testbench\Foundation\Bootstrap\DeleteVendorSymlink;

use function Orchestra\Testbench\package_path;

Expand Down Expand Up @@ -40,7 +40,7 @@ public function beforeEach($app): void
public function afterEach($app): void
{
if ($this->vendorSymlinkCreated === true) {
(new DeleteVendorSymlink)->bootstrap($app);
(new DeleteVendorSymlink)->handle($app);
}
}
}
3 changes: 3 additions & 0 deletions src/Concerns/CreatesApplication.php
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,10 @@ protected function getBasePath()
*
* @param string $filename
* @return string|false
*
* @deprecated
*/
#[\Deprecated('Removed unreliable method to determine default skeleton', since: '9.7.0')]
protected function getDefaultApplicationBootstrapFile(string $filename): string|false
{
return realpath(default_skeleton_path(join_paths('bootstrap', $filename)));
Expand Down
16 changes: 12 additions & 4 deletions src/Concerns/WithLaravelBootstrapFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
use Orchestra\Testbench\Foundation\Application as Testbench;

use function Illuminate\Filesystem\join_paths;
use function Orchestra\Testbench\default_skeleton_path;
use function Orchestra\Testbench\workbench_path;

trait WithLaravelBootstrapFile
Expand All @@ -23,9 +22,8 @@ trait WithLaravelBootstrapFile
protected function getApplicationBootstrapFile(string $filename): string|false
{
$bootstrapFile = realpath(join_paths($this->getBasePath(), 'bootstrap', $filename));
$defaultBootstrapFile = $this->getDefaultApplicationBootstrapFile($filename);

if (\is_string($defaultBootstrapFile) && $defaultBootstrapFile === $bootstrapFile) {
if ($this->usesTestbenchDefaultSkeleton()) {
if (static::usesTestingConcern(WithWorkbench::class) || $this instanceof Testbench) {
return is_file($workbenchFile = workbench_path(join_paths('bootstrap', $filename))) ? (string) realpath($workbenchFile) : false;
}
Expand All @@ -45,10 +43,20 @@ protected function getApplicationBootstrapFile(string $filename): string|false
*/
protected function hasCustomApplicationKernels(): bool
{
return realpath($this->getBasePath()) !== default_skeleton_path()
return ! $this->usesTestbenchDefaultSkeleton()
&& ((static::$cacheApplicationBootstrapFile ??= $this->getApplicationBootstrapFile('app.php')) !== false);
}

/**
* Determine if application is bootstrapped using Testbench's default skeleton.
*
* @return bool
*/
protected function usesTestbenchDefaultSkeleton(): bool
{
return realpath(join_paths($this->getBasePath(), 'bootstrap', '.testbench-default-skeleton')) !== false;
}

/**
* Get base path.
*
Expand Down
11 changes: 8 additions & 3 deletions src/Console/Commander.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use Orchestra\Testbench\Foundation\Config;
use Orchestra\Testbench\Foundation\Console\Concerns\CopyTestbenchFiles;
use Orchestra\Testbench\Foundation\Console\Signals;
use Orchestra\Testbench\Foundation\Console\TerminatingConsole;
use Orchestra\Testbench\Foundation\TestbenchServiceProvider;
use Orchestra\Testbench\Workbench\Workbench;
use Symfony\Component\Console\Application as ConsoleApplication;
Expand Down Expand Up @@ -86,6 +87,8 @@ public function __construct(
protected readonly string $workingPath
) {
$this->config = $config instanceof Config ? $config : new Config($config);

$_ENV['TESTBENCH_ENVIRONMENT_FILE_USING'] = $this->environmentFile;
}

/**
Expand All @@ -110,7 +113,7 @@ public function handle(): void
} catch (Throwable $error) {
$status = $this->handleException($output, $error);
} finally {
$this->handleTerminatingConsole();
TerminatingConsole::handle();
Workbench::flush();
static::$testbench::flushState($this);

Expand Down Expand Up @@ -150,6 +153,8 @@ public function laravel()
'extra' => $this->config->getExtraAttributes(),
]),
);

$this->app->instance('TESTBENCH_COMMANDER', $this);
}

return $this->app;
Expand Down Expand Up @@ -241,7 +246,7 @@ protected function prepareCommandSignals(): void
Collection::make(Arr::wrap([SIGTERM, SIGINT, SIGHUP, SIGUSR1, SIGUSR2, SIGQUIT]))
->each(
fn ($signal) => $this->signals->register($signal, function () use ($signal) {
$this->handleTerminatingConsole();
TerminatingConsole::handle();
Workbench::flush();

$status = match ($signal) {
Expand All @@ -262,7 +267,7 @@ protected function prepareCommandSignals(): void
}, function () {
if (windows_os() && PHP_SAPI === 'cli' && \function_exists('sapi_windows_set_ctrl_handler')) {
sapi_windows_set_ctrl_handler(function ($event) {
$this->handleTerminatingConsole();
TerminatingConsole::handle();
Workbench::flush();

$status = match ($event) {
Expand Down
60 changes: 60 additions & 0 deletions src/Foundation/Actions/CreateVendorSymlink.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?php

namespace Orchestra\Testbench\Foundation\Actions;

use ErrorException;
use Illuminate\Contracts\Foundation\Application;
use Illuminate\Filesystem\Filesystem;

use function Orchestra\Testbench\join_paths;
use function Orchestra\Testbench\laravel_vendor_exists;

/**
* @internal
*/
final class CreateVendorSymlink
{
/**
* Construct a new action.
*
* @param string $workingPath
*/
public function __construct(
protected readonly string $workingPath
) {}

/**
* Execute the command.
*
* @param \Illuminate\Contracts\Foundation\Application $app
* @return void
*/
public function handle(Application $app): void
{
$filesystem = new Filesystem;

$appVendorPath = $app->basePath('vendor');

$vendorLinkCreated = false;

if (! laravel_vendor_exists($app, $this->workingPath)) {
if ($filesystem->exists($app->bootstrapPath(join_paths('cache', 'packages.php')))) {
$filesystem->delete($app->bootstrapPath(join_paths('cache', 'packages.php')));
}

(new DeleteVendorSymlink)->handle($app);

try {
$filesystem->link($this->workingPath, $appVendorPath);

$vendorLinkCreated = true;
} catch (ErrorException $e) {
//
}
}

$app->flush();

$app->instance('TESTBENCH_VENDOR_SYMLINK', $vendorLinkCreated);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Orchestra\Testbench\Foundation\Bootstrap;
namespace Orchestra\Testbench\Foundation\Actions;

use Illuminate\Contracts\Foundation\Application;

Expand All @@ -10,12 +10,12 @@
final class DeleteVendorSymlink
{
/**
* Bootstrap the given application.
* Execute the command.
*
* @param \Illuminate\Contracts\Foundation\Application $app
* @return void
*/
public function bootstrap(Application $app): void
public function handle(Application $app): void
{
tap($app->basePath('vendor'), static function ($appVendorPath) {
if (windows_os() && is_dir($appVendorPath) && readlink($appVendorPath) !== $appVendorPath) {
Expand Down
38 changes: 4 additions & 34 deletions src/Foundation/Bootstrap/CreateVendorSymlink.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,11 @@

namespace Orchestra\Testbench\Foundation\Bootstrap;

use ErrorException;
use Illuminate\Contracts\Foundation\Application;
use Illuminate\Filesystem\Filesystem;

use function Orchestra\Testbench\join_paths;
use function Orchestra\Testbench\laravel_vendor_exists;
use Orchestra\Testbench\Foundation\Actions\CreateVendorSymlink as Action;

/**
* @internal
* @api
*/
final class CreateVendorSymlink
{
Expand All @@ -21,9 +17,7 @@ final class CreateVendorSymlink
*/
public function __construct(
protected readonly string $workingPath
) {
//
}
) {}

/**
* Bootstrap the given application.
Expand All @@ -33,30 +27,6 @@ public function __construct(
*/
public function bootstrap(Application $app): void
{
$filesystem = new Filesystem;

$appVendorPath = $app->basePath('vendor');

$vendorLinkCreated = false;

if (! laravel_vendor_exists($app, $this->workingPath)) {
if ($filesystem->exists($app->bootstrapPath(join_paths('cache', 'packages.php')))) {
$filesystem->delete($app->bootstrapPath(join_paths('cache', 'packages.php')));
}

(new DeleteVendorSymlink)->bootstrap($app);

try {
$filesystem->link($this->workingPath, $appVendorPath);

$vendorLinkCreated = true;
} catch (ErrorException) {
//
}
}

$app->flush();

$app->instance('TESTBENCH_VENDOR_SYMLINK', $vendorLinkCreated);
(new Action($this->workingPath))->handle($app);
}
}
Loading

0 comments on commit 27a694f

Please sign in to comment.