Skip to content

Commit

Permalink
[7.x] Add new package:sync-skeleton command (#269)
Browse files Browse the repository at this point in the history
* wip

Signed-off-by: Mior Muhammad Zaki <[email protected]>

* wip

Signed-off-by: Mior Muhammad Zaki <[email protected]>

* wip

Signed-off-by: Mior Muhammad Zaki <[email protected]>

* wip

Signed-off-by: Mior Muhammad Zaki <[email protected]>

* wip

Signed-off-by: Mior Muhammad Zaki <[email protected]>

* wip

Signed-off-by: Mior Muhammad Zaki <[email protected]>

* wip

Signed-off-by: Mior Muhammad Zaki <[email protected]>

* wip

Signed-off-by: Mior Muhammad Zaki <[email protected]>

* wip

Signed-off-by: Mior Muhammad Zaki <[email protected]>

* wip

Signed-off-by: Mior Muhammad Zaki <[email protected]>

* wip

Signed-off-by: Mior Muhammad Zaki <[email protected]>

* wip

Signed-off-by: Mior Muhammad Zaki <[email protected]>

* wip

Signed-off-by: Mior Muhammad Zaki <[email protected]>

* wip

Signed-off-by: Mior Muhammad Zaki <[email protected]>

* wip

Signed-off-by: Mior Muhammad Zaki <[email protected]>

---------

Signed-off-by: Mior Muhammad Zaki <[email protected]>
  • Loading branch information
crynobone authored Nov 29, 2024
1 parent 676ab12 commit 81bd5b7
Show file tree
Hide file tree
Showing 16 changed files with 433 additions and 132 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG-7.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 9 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.

## 7.48.0

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 @@ -118,7 +119,7 @@ public function handle()
} catch (Throwable $error) {
$status = $this->handleException($output, $error);
} finally {
$this->handleTerminatingConsole();
TerminatingConsole::handle();
Workbench::flush();
static::$testbench::flushState();

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

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

return $this->app;
Expand Down Expand Up @@ -251,7 +254,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 @@ -272,7 +275,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(
public 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
48 changes: 6 additions & 42 deletions src/Foundation/Bootstrap/CreateVendorSymlink.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,22 @@

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
{
/**
* The project working path.
*
* @var string
*/
public $workingPath;

/**
* Construct a new Create Vendor Symlink bootstrapper.
*
* @param string $workingPath
*/
public function __construct(string $workingPath)
{
$this->workingPath = $workingPath;
}
public function __construct(
public string $workingPath
) {}

/**
* Bootstrap the given application.
Expand All @@ -39,30 +27,6 @@ public function __construct(string $workingPath)
*/
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 $e) {
//
}
}

$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 81bd5b7

Please sign in to comment.