Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Testbench configuration feature #11595

Merged
merged 3 commits into from
Feb 27, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
/.github export-ignore
/.gitignore export-ignore
/phpunit.xml.dist export-ignore
/testbench.yaml export-ignore
/tests export-ignore
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"league/flysystem-aws-s3-v3": "^3.0",
"nunomaduro/termwind": "^1.0|^2.0",
"openspout/openspout": "^4.23",
"orchestra/testbench": "^8.0|^9.0",
"orchestra/testbench": "^8.20|^9.0",
"pestphp/pest": "^2.0",
"pestphp/pest-plugin-laravel": "^2.0",
"phpstan/extension-installer": "^1.1",
Expand Down
5 changes: 5 additions & 0 deletions testbench.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
migrations:
- tests/database/migrations

workbench:
install: true
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Having install: true and migrations other than false will migrate the default laravel migrations. Which means we no longer requires create_password_reset_tokens_table and create_users_table.

22 changes: 0 additions & 22 deletions tests/database/migrations/create_password_reset_tokens_table.php

This file was deleted.

26 changes: 0 additions & 26 deletions tests/database/migrations/create_users_table.php

This file was deleted.

9 changes: 3 additions & 6 deletions tests/src/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,14 @@
use Filament\Widgets\WidgetsServiceProvider;
use Illuminate\Foundation\Testing\LazilyRefreshDatabase;
use Livewire\LivewireServiceProvider;
use Orchestra\Testbench\Concerns\WithWorkbench;
use Orchestra\Testbench\TestCase as BaseTestCase;
use RyanChandler\BladeCaptureDirective\BladeCaptureDirectiveServiceProvider;

abstract class TestCase extends BaseTestCase
{
use LazilyRefreshDatabase;
use WithWorkbench;

protected function getPackageProviders($app): array
{
Expand All @@ -49,12 +51,7 @@ protected function getPackageProviders($app): array
];
}

protected function defineDatabaseMigrations(): void
{
$this->loadMigrationsFrom(__DIR__ . '/../database/migrations');
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using this causes Laravel to migrate the database twice, using RefreshDatabase trait (which starts a database transaction) and explicitly via loadMigrationsFrom().

Using testbench.yaml configurations only registers the paths to Migrator and runs the migration once via RefreshDatabase eliminating the issue introduced by caching PDO instances between tests: laravel/framework#47912

}

protected function getEnvironmentSetUp($app): void
protected function defineEnvironment($app): void
{
$app['config']->set('auth.passwords.users.table', 'password_reset_tokens');
$app['config']->set('auth.providers.users.model', User::class);
Expand Down