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 <[email protected]>
  • Loading branch information
crynobone committed Aug 26, 2024
2 parents 62d4498 + 422827e commit 0f5cd57
Show file tree
Hide file tree
Showing 36 changed files with 435 additions and 78 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/analyse.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
experimental:
- false

name: PHP${{ matrix.php }} PHPStan & Pint
name: PHP:${{ matrix.php }} PHPStan & Pint

steps:
- name: Checkout code
Expand Down Expand Up @@ -50,6 +50,7 @@ jobs:
os:
- "ubuntu-latest"
php:
- 8.2
- 8.3
dependencies:
- "highest"
Expand Down
15 changes: 15 additions & 0 deletions CHANGELOG-8.x.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,21 @@

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

## 8.27.0

Released: 2024-08-26

### Added

* Added `artisan` binary to Laravel skeleton.
* Added `Orchestra\Testbench\join_paths()` function.
* Added `Orchestra\Testbench\Attributes\UsesVendor` attribute class.
* Added `defineStashRoutes()` method to register adhoc route for test.

### Changes

* Improvements to `Orchestra\Testbench\default_skeleton_path()`, `Orchestra\Testbench\package_path()`, and `Orchestra\Testbench\workbench_path()` usage based on new `Orchestra\Testbench\join_paths()` function.

## 8.26.0

Released: 2024-08-14
Expand Down
15 changes: 15 additions & 0 deletions CHANGELOG-9.x.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,21 @@

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

## 9.4.0

Released: 2024-08-26

### Added

* Added `artisan` binary to Laravel skeleton.
* Added `Orchestra\Testbench\join_paths()` function.
* Added `Orchestra\Testbench\Attributes\UsesVendor` attribute class.
* Added `defineStashRoutes()` method to register adhoc route for test.

### Changes

* Improvements to `Orchestra\Testbench\default_skeleton_path()`, `Orchestra\Testbench\package_path()`, and `Orchestra\Testbench\workbench_path()` usage based on new `Orchestra\Testbench\join_paths()` function.

## 9.3.0

Released: 2024-08-14
Expand Down
1 change: 1 addition & 0 deletions bin/sync
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ Symfony\Component\Process\Process::fromShellCommandline(
)->mustRun();

Illuminate\Support\Collection::make([
'artisan',
'.env.example',
'database/.gitignore',
'database/migrations/0001_01_01_000000_create_users_table.php',
Expand Down
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
"conflict": {
"brianium/paratest": "<7.3.0 || >=8.0.0",
"laravel/framework": "<12.0.0 || >=13.0.0",
"laravel/serializable-closure": "<1.3.0 || >=2.0.0",
"nunomaduro/collision": "<8.0.0 || >=9.0.0",
"phpunit/phpunit": "<10.5.0 || 11.0.0 || >=11.4.0"
},
Expand Down
15 changes: 15 additions & 0 deletions laravel/artisan
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/usr/bin/env php
<?php

use Symfony\Component\Console\Input\ArgvInput;

define('LARAVEL_START', microtime(true));

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

// Bootstrap Laravel and handle the command...
$status = (require_once __DIR__.'/bootstrap/app.php')
->handleCommand(new ArgvInput);

exit($status);
11 changes: 3 additions & 8 deletions laravel/bootstrap/app.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
<?php

use Orchestra\Testbench\Foundation\Application;
use Orchestra\Testbench\Foundation\Bootstrap\SyncTestbenchCachedRoutes;
use Orchestra\Testbench\Foundation\Config;
use Orchestra\Testbench\Workbench\Workbench;

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

/**
* Create Laravel application.
Expand Down Expand Up @@ -39,12 +40,6 @@

unset($createApp);

/** @var \Illuminate\Routing\Router $router */
$router = $app->make('router');

collect(glob(join_paths(__DIR__, '..', 'routes', 'testbench-*.php')))
->each(static function ($routeFile) use ($app, $router) {
require $routeFile;
});
(new SyncTestbenchCachedRoutes)->bootstrap($app);

return $app;
13 changes: 8 additions & 5 deletions laravel/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,15 @@
"license": "MIT",
"type": "project",
"autoload": {
"classmap": [
"database",
"tests/TestCase.php"
],
"psr-4": {
"App\\": "app/"
"App\\": "app/",
"Database\\Factories\\": "database/factories/",
"Database\\Seeders\\": "database/seeders/"
}
},
"autoload-dev": {
"psr-4": {
"Tests\\": "tests/"
}
},
"extra": {
Expand Down
49 changes: 49 additions & 0 deletions src/Attributes/UsesVendor.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php

namespace Orchestra\Testbench\Attributes;

use Attribute;
use Orchestra\Testbench\Contracts\Attributes\AfterEach as AfterEachContract;
use Orchestra\Testbench\Contracts\Attributes\BeforeEach as BeforeEachContract;
use Orchestra\Testbench\Foundation\Application;

use function Orchestra\Testbench\package_path;

#[Attribute(Attribute::TARGET_CLASS | Attribute::TARGET_METHOD)]
final class UsesVendor implements AfterEachContract, BeforeEachContract
{
/**
* Determine if vendor symlink was created via this attribute.
*/
public bool $vendorSymlinkCreated = false;

/**
* Handle the attribute.
*
* @param \Illuminate\Foundation\Application $app
* @return void
*/
public function beforeEach($app): void
{
$vendorPath = $app->basePath('vendor');

$laravel = Application::createVendorSymlink(base_path(), package_path('vendor'));

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

/**
* Handle the attribute.
*
* @param \Illuminate\Foundation\Application $app
* @return void
*/
public function afterEach($app): void
{
$vendorPath = $app->basePath('vendor');

if (is_link($vendorPath) && $this->vendorSymlinkCreated === true) {
$app['files']->delete($vendorPath);
}
}
}
2 changes: 1 addition & 1 deletion src/Bootstrap/HandleExceptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use Orchestra\Testbench\Exceptions\DeprecatedException;
use Orchestra\Testbench\Foundation\Env;

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

/**
* @internal
Expand Down
2 changes: 1 addition & 1 deletion src/Bootstrap/LoadConfigurationWithWorkbench.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public function __construct()
#[\Override]
protected function resolveConfigurationFile(string $path, string $key): string
{
$config = workbench_path(['config', "{$key}.php"]);
$config = workbench_path('config', "{$key}.php");

return $this->usesWorkbenchConfigFile === true && is_file($config) ? $config : $path;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Bootstrap/LoadEnvironmentVariables.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use Dotenv\Dotenv;
use Orchestra\Testbench\Foundation\Env;

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

/**
* @internal
Expand Down
69 changes: 56 additions & 13 deletions src/Concerns/HandlesRoutes.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,27 @@

namespace Orchestra\Testbench\Concerns;

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

use function Illuminate\Filesystem\join_paths;
use function Orchestra\Testbench\join_paths;
use function Orchestra\Testbench\refresh_router_lookups;
use function Orchestra\Testbench\remote;

trait HandlesRoutes
{
/**
* Indicates if we have made it through the requireApplicationCachedRoutes function.
*
* @var bool
*/
protected $requireApplicationCachedRoutesHasRun = false;

/**
* Setup routes requirements.
*
Expand Down Expand Up @@ -79,15 +88,29 @@ protected function defineWebRoutes($router)
// Define routes.
}

/**
* Define stash routes setup.
*
* @api
*
* @param \Closure|string $route
* @return void
*/
protected function defineStashRoutes(Closure|string $route): void
{
$this->defineCacheRoutes($route, false);
}

/**
* Define cache routes setup.
*
* @api
*
* @param string $route
* @param \Closure|string $route
* @param bool $cached
* @return void
*/
protected function defineCacheRoutes(string $route)
protected function defineCacheRoutes(Closure|string $route, bool $cached = true): void
{
$files = new Filesystem;

Expand All @@ -98,21 +121,29 @@ protected function defineCacheRoutes(string $route)
? join_paths($basePath, '.laravel')
: join_paths($basePath, 'bootstrap');

if ($route instanceof Closure) {
$cached = false;
/** @var string $serializeRoute */
$serializeRoute = serialize(SerializableClosure::unsigned($route));
$stub = $files->get(join_paths(__DIR__, 'stubs', 'routes.stub'));
$route = str_replace('{{routes}}', var_export($serializeRoute, true), $stub);
}

$files->put(
join_paths($basePath, 'routes', "testbench-{$time}.php"), $route
);

remote('route:cache')->mustRun();
if ($cached === true) {
remote('route:cache')->mustRun();

$this->assertTrue(
$files->exists(join_paths($bootstrapPath, 'cache', 'routes-v7.php'))
);
\assert($files->exists(join_paths($bootstrapPath, 'cache', 'routes-v7.php')) === true);
}

if ($this->app instanceof LaravelApplication) {
$this->reloadApplication();
}

$this->requireApplicationCachedRoutes($files);
$this->requireApplicationCachedRoutes($files, $cached);
}

/**
Expand All @@ -123,11 +154,21 @@ protected function defineCacheRoutes(string $route)
* @param \Illuminate\Filesystem\Filesystem $files
* @return void
*/
protected function requireApplicationCachedRoutes(Filesystem $files): void
protected function requireApplicationCachedRoutes(Filesystem $files, bool $cached): void
{
$this->afterApplicationCreated(function () {
if ($this->app instanceof LaravelApplication) {
require $this->app->getCachedRoutesPath();
if ($this->requireApplicationCachedRoutesHasRun === true) {
return;
}

$this->afterApplicationCreated(function () use ($cached) {
$app = $this->app;

if ($app instanceof LaravelApplication) {
if ($cached === true) {
require $app->getCachedRoutesPath();
} else {
(new SyncTestbenchCachedRoutes)->bootstrap($app);
}
}
});

Expand All @@ -141,5 +182,7 @@ protected function requireApplicationCachedRoutes(Filesystem $files): void

sleep(1);
});

$this->requireApplicationCachedRoutesHasRun = true;
}
}
2 changes: 1 addition & 1 deletion src/Concerns/InteractsWithPublishedFiles.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use Illuminate\Support\Collection;

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

/**
* @internal
Expand Down
9 changes: 9 additions & 0 deletions src/Concerns/stubs/routes.stub
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

use Illuminate\Support\Facades\Route;

transform(unserialize({{routes}})->getClosure(), function ($serializedClosure) use ($router) {
if ($serializedClosure instanceof Closure) {
value($serializedClosure, $router);
}
});
2 changes: 1 addition & 1 deletion src/Console/Commander.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
use Symfony\Component\Console\SignalRegistry\SignalRegistry;
use Throwable;

use function Illuminate\Filesystem\join_paths;
use function Orchestra\Testbench\join_paths;
use function Orchestra\Testbench\transform_relative_path;

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Foundation/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
use Orchestra\Testbench\Contracts\Config as ConfigContract;
use Orchestra\Testbench\Workbench\Workbench;

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

/**
* @api
Expand Down
Loading

0 comments on commit 0f5cd57

Please sign in to comment.