Skip to content

Commit

Permalink
Merge branch '7.x' into 8.x
Browse files Browse the repository at this point in the history
  • Loading branch information
crynobone committed Mar 3, 2025
2 parents 199dc8e + 9588396 commit 8b99652
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 26 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"require": {
"php": "^8.1",
"composer-runtime-api": "^2.2",
"orchestra/sidekick": "^1.0.2",
"orchestra/sidekick": "^1.0.5",
"symfony/deprecation-contracts": "^2.5|^3.0",
"symfony/polyfill-php83": "^1.31"
},
Expand Down
13 changes: 7 additions & 6 deletions src/Console/Commander.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
use Symfony\Component\Console\SignalRegistry\SignalRegistry;
use Throwable;

use function Orchestra\Sidekick\is_symlink;
use function Orchestra\Sidekick\join_paths;
use function Orchestra\Sidekick\transform_relative_path;

Expand Down Expand Up @@ -140,19 +141,19 @@ public function laravel()
$APP_BASE_PATH = $this->getApplicationBasePath();
$VENDOR_PATH = join_paths($this->workingPath, 'vendor');

$filesystem = new Filesystem;

$hasEnvironmentFile = fn () => is_file(join_paths($APP_BASE_PATH, '.env'));

TerminatingConsole::beforeWhen(
! $filesystem->isFile(join_paths($VENDOR_PATH, 'autoload.php')),
! is_symlink(join_paths($APP_BASE_PATH, 'vendor')),
static function () use ($APP_BASE_PATH) {
static::$testbench::deleteVendorSymlink($APP_BASE_PATH);
}
);

$filesystem = new Filesystem;

$hasEnvironmentFile = static fn () => is_file(join_paths($APP_BASE_PATH, '.env'));

tap(
static::$testbench::createVendorSymlink($APP_BASE_PATH, join_paths($this->workingPath, 'vendor')),
static::$testbench::createVendorSymlink($APP_BASE_PATH, $VENDOR_PATH),
function ($app) use ($filesystem, $hasEnvironmentFile) {
$this->copyTestbenchConfigurationFile($app, $filesystem, $this->workingPath);

Expand Down
3 changes: 3 additions & 0 deletions src/Foundation/Actions/CreateVendorSymlink.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use ErrorException;
use Illuminate\Contracts\Foundation\Application;
use Illuminate\Filesystem\Filesystem;
use Illuminate\Foundation\PackageManifest;

use function Orchestra\Sidekick\join_paths;
use function Orchestra\Testbench\laravel_vendor_exists;
Expand Down Expand Up @@ -47,6 +48,8 @@ public function handle(Application $app): void
try {
$filesystem->link($this->workingPath, $appVendorPath);

$app->make(PackageManifest::class)->build();

$vendorLinkCreated = true;
} catch (ErrorException $e) {
//
Expand Down
8 changes: 4 additions & 4 deletions src/Foundation/Actions/DeleteVendorSymlink.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

use Illuminate\Contracts\Foundation\Application;

use function Orchestra\Sidekick\is_symlink;

/**
* @internal
*/
Expand All @@ -18,10 +20,8 @@ final class DeleteVendorSymlink
public function handle(Application $app): void
{
tap($app->basePath('vendor'), static function ($appVendorPath) {
if (windows_os() && is_dir($appVendorPath) && readlink($appVendorPath) !== $appVendorPath) {
@rmdir($appVendorPath);
} elseif (is_link($appVendorPath)) {
@unlink($appVendorPath);
if (is_symlink($appVendorPath)) {
windows_os() ? @rmdir($appVendorPath) : @unlink($appVendorPath);
}

clearstatcache(false, \dirname($appVendorPath));
Expand Down
5 changes: 3 additions & 2 deletions src/Workbench/Actions/AddAssetSymlinkFolders.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Illuminate\Support\Str;
use Orchestra\Testbench\Contracts\Config as ConfigContract;

use function Orchestra\Sidekick\is_symlink;
use function Orchestra\Testbench\package_path;

/**
Expand Down Expand Up @@ -61,8 +62,8 @@ public function handle(): void
/** @var string $to */
$to = $pair['to'];

if (is_link($to)) {
$this->files->delete($to);
if (is_symlink($to)) {
windows_os() ? $this->files->deleteDirectory($to) : $this->files->delete($to);
} elseif ($this->files->isDirectory($to)) {
$this->files->deleteDirectory($to);
}
Expand Down
13 changes: 5 additions & 8 deletions src/Workbench/Actions/RemoveAssetSymlinkFolders.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Illuminate\Support\Collection;
use Orchestra\Testbench\Contracts\Config as ConfigContract;

use function Orchestra\Sidekick\is_symlink;
use function Orchestra\Testbench\package_path;

/**
Expand Down Expand Up @@ -37,7 +38,7 @@ public function handle(): void
$sync = $this->config->getWorkbenchAttributes()['sync'] ?? [];

Collection::make($sync)
->map(static function ($pair) {
->map(function ($pair) {
/** @var bool $reverse */
$reverse = isset($pair['reverse']) && \is_bool($pair['reverse']) ? $pair['reverse'] : false;

Expand All @@ -47,13 +48,9 @@ public function handle(): void
/** @var string $to */
$to = $reverse === false ? base_path($pair['to']) : package_path($pair['to']);

if (windows_os() && is_dir($to) && readlink($to) !== $to) {
return [$to, static function ($to) {
@rmdir($to);
}];
} elseif (is_link($to)) {
return [$to, static function ($to) {
@unlink($to);
if (is_symlink($to)) {
return [$to, function ($to) {
windows_os() ? $this->files->deleteDirectory($to) : $this->files->delete($to);
}];
}

Expand Down
6 changes: 1 addition & 5 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,5 @@

abstract class TestCase extends \Orchestra\Testbench\TestCase
{
/** {@inheritDoc} */
protected function getApplicationBasePath()
{
return static::applicationBasePath();
}
//
}

0 comments on commit 8b99652

Please sign in to comment.