From 29b1b8edd8b69bce49cca758348a64c1940a5e71 Mon Sep 17 00:00:00 2001 From: Mior Muhammad Zaki Date: Wed, 20 Sep 2023 21:58:43 +0800 Subject: [PATCH] Test Improvements (#765) Signed-off-by: Mior Muhammad Zaki --- composer.json | 2 +- testbench.yaml | 4 ++++ tests/Feature/BuilderTest.php | 14 +++++--------- tests/Feature/CollectionEngineTest.php | 17 +++++------------ tests/Feature/DatabaseEngineTest.php | 16 +++++----------- tests/Feature/MeilisearchEngineTest.php | 7 ++----- 6 files changed, 22 insertions(+), 38 deletions(-) create mode 100644 testbench.yaml diff --git a/composer.json b/composer.json index b751c545..d9ee6f63 100644 --- a/composer.json +++ b/composer.json @@ -27,7 +27,7 @@ "algolia/algoliasearch-client-php": "^3.2", "meilisearch/meilisearch-php": "^1.0", "mockery/mockery": "^1.0", - "orchestra/testbench": "^7.0|^8.0", + "orchestra/testbench": "^7.31|^8.11", "php-http/guzzle7-adapter": "^1.0", "phpstan/phpstan": "^1.10", "phpunit/phpunit": "^9.3" diff --git a/testbench.yaml b/testbench.yaml new file mode 100644 index 00000000..91cd677b --- /dev/null +++ b/testbench.yaml @@ -0,0 +1,4 @@ +providers: + - Laravel\Scout\ScoutServiceProvider + +migrations: true diff --git a/tests/Feature/BuilderTest.php b/tests/Feature/BuilderTest.php index dc3b9eb9..7d11dab4 100644 --- a/tests/Feature/BuilderTest.php +++ b/tests/Feature/BuilderTest.php @@ -4,33 +4,29 @@ use Illuminate\Database\Eloquent\Factories\Sequence; use Illuminate\Foundation\Auth\User; +use Illuminate\Foundation\Testing\LazilyRefreshDatabase; use Illuminate\Foundation\Testing\WithFaker; use Laravel\Scout\EngineManager; use Laravel\Scout\Engines\MeilisearchEngine; -use Laravel\Scout\ScoutServiceProvider; use Laravel\Scout\Tests\Fixtures\SearchableUserModel; use Mockery as m; +use Orchestra\Testbench\Concerns\WithLaravelMigrations; +use Orchestra\Testbench\Concerns\WithWorkbench; use Orchestra\Testbench\Factories\UserFactory; use Orchestra\Testbench\TestCase; class BuilderTest extends TestCase { - use WithFaker; - - protected function getPackageProviders($app) - { - return [ScoutServiceProvider::class]; - } + use LazilyRefreshDatabase, WithFaker, WithLaravelMigrations, WithWorkbench; protected function defineEnvironment($app) { $app->make('config')->set('scout.driver', 'fake'); } - protected function defineDatabaseMigrations() + protected function afterRefreshingDatabase() { $this->setUpFaker(); - $this->loadLaravelMigrations(); UserFactory::new()->count(50)->state(new Sequence(function () { return ['name' => 'Laravel '.$this->faker()->name()]; diff --git a/tests/Feature/CollectionEngineTest.php b/tests/Feature/CollectionEngineTest.php index 71d9edfe..049670a6 100644 --- a/tests/Feature/CollectionEngineTest.php +++ b/tests/Feature/CollectionEngineTest.php @@ -2,32 +2,25 @@ namespace Laravel\Scout\Tests\Feature; -use Illuminate\Foundation\Testing\WithFaker; -use Laravel\Scout\ScoutServiceProvider; +use Illuminate\Foundation\Testing\LazilyRefreshDatabase; use Laravel\Scout\Tests\Fixtures\SearchableUserModel; use Laravel\Scout\Tests\Fixtures\SearchableUserModelWithCustomSearchableData; +use Orchestra\Testbench\Concerns\WithLaravelMigrations; +use Orchestra\Testbench\Concerns\WithWorkbench; use Orchestra\Testbench\Factories\UserFactory; use Orchestra\Testbench\TestCase; class CollectionEngineTest extends TestCase { - use WithFaker; - - protected function getPackageProviders($app) - { - return [ScoutServiceProvider::class]; - } + use LazilyRefreshDatabase, WithLaravelMigrations, WithWorkbench; protected function defineEnvironment($app) { $app->make('config')->set('scout.driver', 'collection'); } - protected function defineDatabaseMigrations() + protected function afterRefreshingDatabase() { - $this->setUpFaker(); - $this->loadLaravelMigrations(); - UserFactory::new()->create([ 'name' => 'Taylor Otwell', 'email' => 'taylor@laravel.com', diff --git a/tests/Feature/DatabaseEngineTest.php b/tests/Feature/DatabaseEngineTest.php index ae306f5e..e3f6df12 100644 --- a/tests/Feature/DatabaseEngineTest.php +++ b/tests/Feature/DatabaseEngineTest.php @@ -2,31 +2,25 @@ namespace Laravel\Scout\Tests\Feature; +use Illuminate\Foundation\Testing\LazilyRefreshDatabase; use Illuminate\Foundation\Testing\WithFaker; -use Laravel\Scout\ScoutServiceProvider; use Laravel\Scout\Tests\Fixtures\SearchableUserDatabaseModel; +use Orchestra\Testbench\Concerns\WithLaravelMigrations; +use Orchestra\Testbench\Concerns\WithWorkbench; use Orchestra\Testbench\Factories\UserFactory; use Orchestra\Testbench\TestCase; class DatabaseEngineTest extends TestCase { - use WithFaker; - - protected function getPackageProviders($app) - { - return [ScoutServiceProvider::class]; - } + use LazilyRefreshDatabase, WithFaker, WithLaravelMigrations, WithWorkbench; protected function defineEnvironment($app) { $app->make('config')->set('scout.driver', 'database'); } - protected function defineDatabaseMigrations() + protected function afterRefreshingDatabase() { - $this->setUpFaker(); - $this->loadLaravelMigrations(); - UserFactory::new()->create([ 'name' => 'Taylor Otwell', 'email' => 'taylor@laravel.com', diff --git a/tests/Feature/MeilisearchEngineTest.php b/tests/Feature/MeilisearchEngineTest.php index d5ce1551..7ea798b1 100644 --- a/tests/Feature/MeilisearchEngineTest.php +++ b/tests/Feature/MeilisearchEngineTest.php @@ -2,16 +2,13 @@ namespace Laravel\Scout\Tests\Feature; -use Laravel\Scout\ScoutServiceProvider; use Meilisearch\Client; +use Orchestra\Testbench\Concerns\WithWorkbench; use Orchestra\Testbench\TestCase; class MeilisearchEngineTest extends TestCase { - protected function getPackageProviders($app) - { - return [ScoutServiceProvider::class]; - } + use WithWorkbench; protected function defineEnvironment($app) {