Skip to content

Commit

Permalink
Merge branch '9.x' into 9/phpunit11-5
Browse files Browse the repository at this point in the history
  • Loading branch information
crynobone committed Dec 4, 2024
2 parents a4e03d3 + 4df0568 commit 411a88b
Show file tree
Hide file tree
Showing 43 changed files with 704 additions and 236 deletions.
27 changes: 27 additions & 0 deletions CHANGELOG-8.x.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,33 @@

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

## 8.30.0

Released: 2024-12-01

### Added

* 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 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

Released: 2024-11-18
Expand Down
27 changes: 27 additions & 0 deletions CHANGELOG-9.x.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,33 @@

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

## 9.7.0

Released: 2024-12-01

### Added

* 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
19 changes: 12 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Testing Helper for Laravel Development
Testing Framework for Laravel Development
==============

Testbench Component is a simple package that has been designed to help you write tests for your Laravel package.
Testbench Core is a framework designed to help you write tests and interact with your Laravel package.

[![tests](https://github.com/orchestral/testbench-core/workflows/tests/badge.svg?branch=9.x)](https://github.com/orchestral/testbench-core/actions?query=workflow%3Atests+branch%3A9.x)
[![Latest Stable Version](https://poser.pugx.org/orchestra/testbench-core/v/stable)](https://packagist.org/packages/orchestra/testbench-core)
Expand All @@ -22,25 +22,30 @@ Testbench Component is a simple package that has been designed to help you write

## Usage

**Testbench Core** is being built to enable [Laravel Framework](https://github.com/laravel/framework) to build and run integration tests for the framework itself. For package developers please use any of the following testbench projects:

### [Testbench](https://github.com/orchestral/testbench)

It loads Laravel apps and enable you to run artisan commands, migrations, factories and basic routing from within your tests.
It loads a Laravel application within your package repository and enables you to run artisan commands, migrations, factories, and basic routing from within your tests.

[![Latest Stable Version](https://poser.pugx.org/orchestra/testbench/v/stable)](https://packagist.org/packages/orchestra/testbench)
[![Total Downloads](https://poser.pugx.org/orchestra/testbench/downloads)](https://packagist.org/packages/orchestra/testbench)

### [Testbench BrowserKit](https://github.com/orchestral/testbench-browser-kit)

It extends **Testbench** and allows you to interact with views using CSS selectors (interacting with form, button, link etc) but without JavaScript being loaded.
It extends **Testbench** and allows you to interact with views using CSS selectors (form, button, link, etc.) without loading JavaScript.

[![Latest Stable Version](https://poser.pugx.org/orchestra/testbench-browser-kit/v/stable)](https://packagist.org/packages/orchestra/testbench-browser-kit)
[![Total Downloads](https://poser.pugx.org/orchestra/testbench-browser-kit/downloads)](https://packagist.org/packages/orchestra/testbench-browser-kit)

### [Testbench Dusk](https://github.com/orchestral/testbench-dusk)

It extends **Testbench** and allows you to interact with views using CSS selectors (interacting with form, button, link etc). By loading the pages using Google Chrome it enable you to interacts with JavaScript powered content.
It extends **Testbench** and allows you to interact with views using CSS selectors (form, button, link, etc). Loading the pages using Google Chrome enables you to interact with JavaScript-powered content.

[![Latest Stable Version](https://poser.pugx.org/orchestra/testbench-dusk/v/stable)](https://packagist.org/packages/orchestra/testbench-dusk)
[![Total Downloads](https://poser.pugx.org/orchestra/testbench-dusk/downloads)](https://packagist.org/packages/orchestra/testbench-dusk)

### [Workbench](https://github.com/orchestral/workbench)

It loads a Laravel application within your package repository and enables you to preview the package directly within the repository.

[![Latest Stable Version](https://poser.pugx.org/orchestra/workbench/v/stable)](https://packagist.org/packages/orchestra/workbench)
[![Total Downloads](https://poser.pugx.org/orchestra/workbench/downloads)](https://packagist.org/packages/orchestra/workbench)
2 changes: 2 additions & 0 deletions bin/sync
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ $files->ensureDirectoryExists("{$workingPath}/laravel/migrations/notifications")
$files->ensureDirectoryExists("{$workingPath}/laravel/migrations/queue");
$files->ensureDirectoryExists("{$workingPath}/laravel/migrations/session");

$files->put("{$workingPath}/laravel/bootstrap/.testbench-default-skeleton", '@testbench'.PHP_EOL);

/**
* ----------------------------------------------------------------------
* Copy files from `laravel/laravel`
Expand Down
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
},
"require-dev": {
"fakerphp/faker": "^1.24",
"laravel/framework": "^11.33.2",
"laravel/framework": "^11.35.0",
"laravel/pint": "^1.17",
"laravel/serializable-closure": "^1.3 || ^2.0",
"mockery/mockery": "^1.6.10",
Expand All @@ -54,7 +54,7 @@
},
"conflict": {
"brianium/paratest": "<7.3.0 || >=8.0.0",
"laravel/framework": "<11.33.2 || >=12.0.0",
"laravel/framework": "<11.35.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",
Expand All @@ -64,7 +64,7 @@
"ext-pcntl": "Required to use all features of the console signal trapping.",
"brianium/paratest": "Allow using parallel testing (^7.3).",
"fakerphp/faker": "Allow using Faker for testing (^1.23).",
"laravel/framework": "Required for testing (^11.33.2).",
"laravel/framework": "Required for testing (^11.35.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).",
Expand Down
1 change: 1 addition & 0 deletions laravel/bootstrap/.testbench-default-skeleton
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@testbench
7 changes: 4 additions & 3 deletions laravel/bootstrap/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,13 @@
*/
$createApp = static function (string $workingPath) {
$config = Config::loadFromYaml(
defined('TESTBENCH_WORKING_PATH') ? TESTBENCH_WORKING_PATH : $workingPath
workingPath: defined('TESTBENCH_WORKING_PATH') ? TESTBENCH_WORKING_PATH : $workingPath,
filename: defined('TESTBENCH_WORKING_PATH') ? 'testbench.yaml' : join_paths($workingPath, 'bootstrap', 'cache', 'testbench.yaml')
);

$hasEnvironmentFile = ! is_null($config['laravel'])
? file_exists(join_paths($config['laravel'], '.env'))
: file_exists(join_paths($workingPath, '.env'));
? is_file(join_paths($config['laravel'], '.env'))
: is_file(join_paths($workingPath, '.env'));

return Application::create(
basePath: $config['laravel'],
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);
}
}
}
2 changes: 1 addition & 1 deletion src/Bootstrap/ConfigureRay.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function bootstrap(Application $app): void
/** @var \Illuminate\Contracts\Config\Repository $config */
$config = $app->make('config');

if ($config->get('database.default') === 'sqlite' && ! file_exists($config->get('database.connections.sqlite.database'))) {
if ($config->get('database.default') === 'sqlite' && ! is_file($config->get('database.connections.sqlite.database'))) {
$settings->send_queries_to_ray = false; /** @phpstan-ignore property.notFound */
$settings->send_duplicate_queries_to_ray = false; /** @phpstan-ignore property.notFound */
$settings->send_slow_queries_to_ray = false; /** @phpstan-ignore property.notFound */
Expand Down
2 changes: 1 addition & 1 deletion src/Bootstrap/LoadConfiguration.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ protected function extendsLoadedConfiguration(Collection $configurations): Colle
*/
protected function configureDefaultDatabaseConnection(RepositoryContract $config): void
{
if ($config->get('database.default') === 'sqlite' && ! file_exists($config->get('database.connections.sqlite.database'))) {
if ($config->get('database.default') === 'sqlite' && ! is_file($config->get('database.connections.sqlite.database'))) {
$config->set('database.default', 'testing');
}
}
Expand Down
7 changes: 6 additions & 1 deletion src/Bootstrap/LoadConfigurationWithWorkbench.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Orchestra\Testbench\Workbench\Workbench;
use Symfony\Component\Finder\Finder;

use function Orchestra\Testbench\join_paths;
use function Orchestra\Testbench\workbench_path;

/**
Expand Down Expand Up @@ -40,7 +41,11 @@ public function bootstrap(Application $app): void

$userModel = Workbench::applicationUserModel();

if ($userModel !== false && is_a($userModel, Authenticatable::class, true)) {
if (\is_null($userModel) && is_file($app->basePath(join_paths('Models', 'User.php')))) {
$userModel = 'App\Models\User';
}

if (! \is_null($userModel) && is_a($userModel, Authenticatable::class, true)) {
$app->make('config')->set('auth.providers.users.model', $userModel);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Bootstrap/LoadEnvironmentVariables.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ final class LoadEnvironmentVariables extends \Illuminate\Foundation\Bootstrap\Lo
protected function createDotenv($app)
{
/** @phpstan-ignore method.notFound, method.notFound */
if (! file_exists(join_paths($app->environmentPath(), $app->environmentFile()))) {
if (! is_file(join_paths($app->environmentPath(), $app->environmentFile()))) {
return Dotenv::create(
Env::getRepository(), (string) realpath(join_paths(__DIR__, 'stubs')), '.env.testbench'
);
Expand Down
3 changes: 3 additions & 0 deletions src/Concerns/CreatesApplication.php
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,10 @@ protected function getBasePath()
*
* @param string $filename
* @return string|false
*
* @deprecated
*/
#[\Deprecated('Removed unreliable method to determine default skeleton', since: '9.7.0')]
protected function getDefaultApplicationBootstrapFile(string $filename): string|false
{
return realpath(default_skeleton_path(join_paths('bootstrap', $filename)));
Expand Down
11 changes: 4 additions & 7 deletions src/Concerns/HandlesDatabases.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@
use Orchestra\Testbench\Attributes\DefineDatabase;
use Orchestra\Testbench\Attributes\RequiresDatabase;
use Orchestra\Testbench\Attributes\WithMigration;
use Orchestra\Testbench\Exceptions\ApplicationNotAvailableException;
use Orchestra\Testbench\Features\TestingFeature;

use function Orchestra\Testbench\laravel_or_fail;

/**
* @internal
*/
Expand All @@ -24,9 +25,7 @@ trait HandlesDatabases
*/
protected function setUpDatabaseRequirements(Closure $callback): void
{
if (\is_null($app = $this->app)) {
throw ApplicationNotAvailableException::make(__METHOD__);
}
$app = laravel_or_fail($this->app);

TestingFeature::run(
testCase: $this,
Expand Down Expand Up @@ -81,9 +80,7 @@ protected function setUpDatabaseRequirements(Closure $callback): void
*/
protected function usesSqliteInMemoryDatabaseConnection(?string $connection = null): bool
{
if (\is_null($app = $this->app)) {
throw ApplicationNotAvailableException::make(__METHOD__);
}
$app = laravel_or_fail($this->app);

/** @var \Illuminate\Contracts\Config\Repository $config */
$config = $app->make('config');
Expand Down
33 changes: 11 additions & 22 deletions src/Concerns/InteractsWithMigrations.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
use InvalidArgumentException;
use Orchestra\Testbench\Attributes\ResetRefreshDatabaseState;
use Orchestra\Testbench\Database\MigrateProcessor;
use Orchestra\Testbench\Exceptions\ApplicationNotAvailableException;

use function Orchestra\Testbench\default_migration_path;
use function Orchestra\Testbench\laravel_or_fail;
use function Orchestra\Testbench\load_migration_paths;

/**
Expand Down Expand Up @@ -67,33 +67,28 @@ protected function tearDownInteractsWithMigrations(): void
*/
protected function loadMigrationsFrom(array|string $paths): void
{
$app = laravel_or_fail($this->app);

if (
(\is_string($paths) || Arr::isList($paths))
&& static::usesRefreshDatabaseTestingConcern()
&& RefreshDatabaseState::$migrated === false
&& RefreshDatabaseState::$lazilyRefreshed === false
) {
if (\is_null($this->app)) {
throw ApplicationNotAvailableException::make(__METHOD__);
}

/** @var array<int, string>|string $paths */
load_migration_paths($this->app, $paths);
load_migration_paths($app, $paths);

return;
}

if (\is_null($this->app)) {
throw ApplicationNotAvailableException::make(__METHOD__);
}

/** @var array<string, mixed>|string $paths */
$migrator = new MigrateProcessor($this, $this->resolvePackageMigrationsOptions($paths));
$migrator->up();

array_unshift($this->cachedTestMigratorProcessors, $migrator);

$this->resetApplicationArtisanCommands($this->app);
$this->resetApplicationArtisanCommands($app);
}

/**
Expand All @@ -109,16 +104,14 @@ protected function loadMigrationsFrom(array|string $paths): void
#[\Deprecated(message: 'Use `loadMigrationsFrom()` instead', since: '9.0.7')]
protected function loadMigrationsWithoutRollbackFrom(array|string $paths): void
{
if (\is_null($this->app)) {
throw ApplicationNotAvailableException::make(__METHOD__);
}
$app = laravel_or_fail($this->app);

$migrator = new MigrateProcessor($this, $this->resolvePackageMigrationsOptions($paths));
$migrator->up();

array_unshift($this->cachedTestMigratorProcessors, $migrator);

$this->resetApplicationArtisanCommands($this->app);
$this->resetApplicationArtisanCommands($app);
}

/**
Expand Down Expand Up @@ -154,9 +147,7 @@ protected function resolvePackageMigrationsOptions(array|string $paths = []): ar
*/
protected function loadLaravelMigrations(array|string $database = []): void
{
if (\is_null($this->app)) {
throw ApplicationNotAvailableException::make(__METHOD__);
}
$app = laravel_or_fail($this->app);

$options = $this->resolveLaravelMigrationsOptions($database);
$options['--path'] = default_migration_path();
Expand All @@ -167,7 +158,7 @@ protected function loadLaravelMigrations(array|string $database = []): void

array_unshift($this->cachedTestMigratorProcessors, $migrator);

$this->resetApplicationArtisanCommands($this->app);
$this->resetApplicationArtisanCommands($app);
}

/**
Expand Down Expand Up @@ -196,16 +187,14 @@ protected function loadLaravelMigrationsWithoutRollback(array|string $database =
*/
protected function runLaravelMigrations(array|string $database = []): void
{
if (\is_null($this->app)) {
throw ApplicationNotAvailableException::make(__METHOD__);
}
$app = laravel_or_fail($this->app);

$migrator = new MigrateProcessor($this, $this->resolveLaravelMigrationsOptions($database));
$migrator->up();

array_unshift($this->cachedTestMigratorProcessors, $migrator);

$this->resetApplicationArtisanCommands($this->app);
$this->resetApplicationArtisanCommands($app);
}

/**
Expand Down
Loading

0 comments on commit 411a88b

Please sign in to comment.