Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
Signed-off-by: Mior Muhammad Zaki <[email protected]>
  • Loading branch information
crynobone committed Nov 29, 2024
2 parents ed606cf + 5196822 commit 5f14834
Show file tree
Hide file tree
Showing 18 changed files with 441 additions and 126 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/audits.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ jobs:
- 8.3
experimental:
- true
exclude:
- php: '8.0'

name: PHP:${{ matrix.php }} Code Audit

Expand Down
9 changes: 9 additions & 0 deletions CHANGELOG-8.x.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ This changelog references the relevant changes (bug and security fixes) done to
* 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 +18,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
9 changes: 9 additions & 0 deletions CHANGELOG-9.x.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,24 @@ This changelog references the relevant changes (bug and security fixes) done to
* 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
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);
}
}
}
9 changes: 6 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 @@ -112,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 @@ -152,6 +153,8 @@ public function laravel()
'extra' => $this->config->getExtraAttributes(),
]),
);

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

return $this->app;
Expand Down Expand Up @@ -243,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 @@ -264,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);
}
}
44 changes: 0 additions & 44 deletions src/Foundation/Bootstrap/SyncTestbenchConfigurationFiles.php

This file was deleted.

Loading

0 comments on commit 5f14834

Please sign in to comment.