Skip to content

Commit

Permalink
Merge branch '9.x' into laravel-54737
Browse files Browse the repository at this point in the history
  • Loading branch information
crynobone authored Mar 7, 2025
2 parents 25e564d + 9c1f590 commit acf78f1
Show file tree
Hide file tree
Showing 29 changed files with 275 additions and 80 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/audits.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ on:
push:
branches:
- '*.x'
- '!7.x'
- '!8.x'
pull_request:
workflow_dispatch:

Expand Down
20 changes: 20 additions & 0 deletions CHANGELOG-8.x.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,26 @@

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

## 8.35.0

Released: 2025-03-06

### Added

* Added `resolvePhpUnitTestClassName()` and `resolvePhpUnitTestMethodName()` to `Orchestra\Testbench\Concerns\InteractsWithPHPUnit` trait.

### Changes

* Allows `usesTestingFeature()` to register attribute directly on test method.
* Improves `vendor` detection on the default skeleton.
* Utilise `Orchestra\Sidekick\is_symlink()` function instead of `is_link()` to improves support on Windows.
* Use `::class` instead of `get_class()`.
* Delete `vendor` symlink via `package:purge-skeleton` command.

### Fixes

* Fix static variable via `Orchestra\Testbench\Attributes\UsesVendor::beforeEach()` method.

## 8.34.0

Released: 2025-02-19
Expand Down
36 changes: 36 additions & 0 deletions CHANGELOG-9.x.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,42 @@

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

## 9.12.0

Released: 2025-03-06

### Added

* Added `resolvePhpUnitTestClassName()` and `resolvePhpUnitTestMethodName()` to `Orchestra\Testbench\Concerns\InteractsWithPHPUnit` trait.

### Changes

* Allows `usesTestingFeature()` to register attribute directly on test method.
* Improves `vendor` detection on the default skeleton.
* Utilise `Orchestra\Sidekick\is_symlink()` function instead of `is_link()` to improves support on Windows.
* Use `::class` instead of `get_class()`.
* Delete `vendor` symlink via `package:purge-skeleton` command.

### Fixes

* Fix static variable via `Orchestra\Testbench\Attributes\UsesVendor::beforeEach()` method.

### Deprecate

* Deprecate following PHPUnit annotations:
- `@environment-setup`
- `@define-env`
- `@define-database`
- `@define-route`

## 9.11.2

Released: 2025-03-03

### Fixes

* Fix `Orchestra\Testbench\Attributes\UsesVendor` causes IoC Container to be out of sync.

## 9.11.1

Released: 2025-02-25
Expand Down
8 changes: 8 additions & 0 deletions bin/configure-skeleton.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,14 @@
$files->replaceInFile(['{{tableClassName}}', '{{table}}'], [Illuminate\Support\Str::studly($table), $table], "{$workingPath}/laravel/migrations/{$migration}.php");
});

transform([
line("require __DIR__.'/vendor/autoload.php';") => line("require __DIR__.'/bootstrap/autoload.php';"),
], fn ($changes) => $files->replaceInFile(array_keys($changes), array_values($changes), "{$workingPath}/laravel/artisan"));

transform([
line("require __DIR__.'/../vendor/autoload.php';") => line("require __DIR__.'/../bootstrap/autoload.php';"),
], fn ($changes) => $files->replaceInFile(array_keys($changes), array_values($changes), "{$workingPath}/laravel/public/index.php"));

transform([
line('APP_KEY=', 0) => line('APP_KEY=AckfSECXIvnK5r28GVIWUAxmbBSjTsmF', 0),
line('DB_CONNECTION=mysql', 0) => line('DB_CONNECTION=sqlite', 0),
Expand Down
24 changes: 12 additions & 12 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"require": {
"php": "^8.2",
"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",
"symfony/polyfill-php84": "^1.31"
Expand All @@ -47,22 +47,22 @@
"fakerphp/faker": "^1.24",
"laravel/framework": "dev-markdown-string as 11.999.999",
"laravel/pint": "^1.20",
"laravel/serializable-closure": "^1.3 || ^2.0",
"laravel/serializable-closure": "^1.3|^2.0",
"mockery/mockery": "^1.6.10",
"phpstan/phpstan": "^2.1",
"phpunit/phpunit": "^10.5.35 || ^11.3.6 || ^12.0.1",
"phpunit/phpunit": "^10.5.35|^11.3.6|^12.0.1",
"spatie/laravel-ray": "^1.39",
"symfony/process": "^7.0.3",
"symfony/yaml": "^7.0.3",
"vlucas/phpdotenv": "^5.6.1"
},
"conflict": {
"brianium/paratest": "<7.3.0 || >=8.0.0",
"laravel/framework": "<11.44.0 || >=12.0.0",
"laravel/serializable-closure": "<1.3.0 || >=3.0.0",
"nunomaduro/collision": "<8.0.0 || >=9.0.0",
"orchestra/testbench-dusk": "<9.10.0 || >=10.0.0",
"phpunit/phpunit": "<10.5.35 || >=11.0.0 <11.3.6 || >=12.0.0 <12.0.1 || >=12.1.0"
"brianium/paratest": "<7.3.0|>=8.0.0",
"laravel/framework": "<11.44.1|>=12.0.0",
"laravel/serializable-closure": "<1.3.0|>=3.0.0",
"nunomaduro/collision": "<8.0.0|>=9.0.0",
"orchestra/testbench-dusk": "<9.10.0|>=10.0.0",
"phpunit/phpunit": "<10.5.35|>=11.0.0 <11.3.6|>=12.0.0 <12.0.1|>=12.1.0"
},
"suggest": {
"ext-pcntl": "Required to use all features of the console signal trapping.",
Expand All @@ -71,11 +71,11 @@
"laravel/framework": "Required for testing (^11.44.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).",
"phpunit/phpunit": "Allow using PHPUnit for testing (^10.5 || ^11.0).",
"orchestra/testbench-dusk": "Allow using Laravel Dusk for testing (^9.10).",
"phpunit/phpunit": "Allow using PHPUnit for testing (^10.5|^11.0).",
"symfony/process": "Required to use Orchestra\\Testbench\\remote function (^7.0).",
"symfony/yaml": "Required for Testbench CLI (^7.0).",
"vlucas/phpdotenv": "Required for Testbench CLI (^5.4.1)."
"vlucas/phpdotenv": "Required for Testbench CLI (^5.6.1)."
},
"config": {
"preferred-install": {
Expand Down
2 changes: 1 addition & 1 deletion laravel/artisan
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use Symfony\Component\Console\Input\ArgvInput;
define('LARAVEL_START', microtime(true));

// Register the Composer autoloader...
require __DIR__.'/vendor/autoload.php';
require __DIR__.'/bootstrap/autoload.php';

// Bootstrap Laravel and handle the command...
/** @var Application $app */
Expand Down
4 changes: 0 additions & 4 deletions laravel/bootstrap/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,6 @@
);
};

if (! defined('TESTBENCH_WORKING_PATH') && is_string(getenv('TESTBENCH_WORKING_PATH'))) {
define('TESTBENCH_WORKING_PATH', getenv('TESTBENCH_WORKING_PATH'));
}

$app = $createApp(realpath(join_paths(__DIR__, '..')));

unset($createApp);
Expand Down
9 changes: 9 additions & 0 deletions laravel/bootstrap/autoload.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

if (! defined('TESTBENCH_WORKING_PATH') && is_string(getenv('TESTBENCH_WORKING_PATH'))) {
define('TESTBENCH_WORKING_PATH', getenv('TESTBENCH_WORKING_PATH'));
}

$workingPath = defined('TESTBENCH_WORKING_PATH') ? TESTBENCH_WORKING_PATH : realpath(__DIR__.'/../');

require $workingPath.'/vendor/autoload.php';
2 changes: 1 addition & 1 deletion laravel/public/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
}

// Register the Composer autoloader...
require __DIR__.'/../vendor/autoload.php';
require __DIR__.'/../bootstrap/autoload.php';

// Bootstrap Laravel and handle the request...
/** @var Application $app */
Expand Down
11 changes: 9 additions & 2 deletions src/Attributes/UsesVendor.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
namespace Orchestra\Testbench\Attributes;

use Attribute;
use Illuminate\Foundation\Application;
use Illuminate\Support\Facades\Facade;
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\Application as Testbench;

use function Orchestra\Testbench\package_path;

Expand All @@ -26,9 +28,14 @@ final class UsesVendor implements AfterEachContract, BeforeEachContract
*/
public function beforeEach($app): void
{
$laravel = Application::createVendorSymlink(base_path(), package_path('vendor'));
$laravel = Testbench::createVendorSymlink(base_path(), package_path('vendor'));

$this->vendorSymlinkCreated = $laravel['TESTBENCH_VENDOR_SYMLINK'] ?? false;

Facade::clearResolvedInstances();
Facade::setFacadeApplication($app);

Application::setInstance($app);
}

/**
Expand Down
6 changes: 3 additions & 3 deletions src/Concerns/CreatesApplication.php
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ protected function getPackageProviders($app)
/**
* Resolve the application's base path.
*
* @api
* @internal
*
* @return string
*/
Expand All @@ -258,11 +258,11 @@ protected function getApplicationBasePath()
*
* @return string|null
*
* @deprecated 6.22.0 Use `getApplicationBasePath()` instead.
* @deprecated 6.22.0 Use `applicationBasePath()` static method instead.
*/
protected function getBasePath()
{
trigger_deprecation('orchestra/testbench-core', '6.22.0', 'Use `%s` instead.', 'getApplicationBasePath()');
trigger_deprecation('orchestra/testbench-core', '6.22.0', 'Use `%s` static method instead.', 'applicationBasePath()');

return static::applicationBasePath();
}
Expand Down
13 changes: 12 additions & 1 deletion src/Concerns/HandlesAnnotations.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Closure;
use Illuminate\Support\Collection;
use Orchestra\Testbench\Attributes;

/**
* @internal
Expand All @@ -24,12 +25,22 @@ trait HandlesAnnotations
*/
protected function parseTestMethodAnnotations($app, string $name, ?Closure $callback = null): void
{
/** @phpstan-ignore match.unhandled */
$attribute = match ($name) {
'environment-setup' => Attributes\DefineEnvironment::class,
'define-env' => Attributes\DefineEnvironment::class,
'define-db' => Attributes\DefineDatabase::class,
'define-route' => Attributes\DefineRoute::class,
};

$this->resolvePhpUnitAnnotations()
->lazy()
->filter(static fn ($actions, string $key) => $key === $name && ! empty($actions))
->flatten()
->filter(fn ($method) => \is_string($method) && method_exists($this, $method))
->each($callback ?? function ($method) use ($app) {
->each($callback ?? function ($method) use ($app, $name, $attribute) {
trigger_deprecation('orchestra/testbench-core', '9.12.0', 'Use #[%s] attribute instead of deprecated @%s annotation', $attribute, $name);

$this->{$method}($app);
});
}
Expand Down
15 changes: 15 additions & 0 deletions src/Concerns/HandlesRoutes.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@

namespace Orchestra\Testbench\Concerns;

use Attribute;
use Closure;
use Illuminate\Filesystem\Filesystem;
use Illuminate\Foundation\Application as LaravelApplication;
use Laravel\SerializableClosure\SerializableClosure;
use Orchestra\Testbench\Attributes\DefineRoute;
use Orchestra\Testbench\Attributes\UsesVendor;
use Orchestra\Testbench\Features\TestingFeature;
use Orchestra\Testbench\Foundation\Bootstrap\SyncTestbenchCachedRoutes;

Expand All @@ -16,6 +18,9 @@

trait HandlesRoutes
{
use InteractsWithPHPUnit;
use InteractsWithTestCase;

/**
* Indicates if we have made it through the requireApplicationCachedRoutes function.
*
Expand Down Expand Up @@ -112,6 +117,16 @@ protected function defineStashRoutes(Closure|string $route): void
*/
protected function defineCacheRoutes(Closure|string $route, bool $cached = true): void
{
static::usesTestingFeature($attribute = new UsesVendor, Attribute::TARGET_METHOD);

if (
$this->app instanceof LaravelApplication
&& property_exists($this, 'setUpHasRun')
&& $this->setUpHasRun === true
) {
$attribute->beforeEach($this->app);
}

$files = new Filesystem;

$time = time();
Expand Down
Loading

0 comments on commit acf78f1

Please sign in to comment.