-
-
Notifications
You must be signed in to change notification settings - Fork 114
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ElasticSearchEngine feature tests improved
- Loading branch information
Showing
1 changed file
with
48 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Tests\Feature; | ||
|
||
use App\Product; | ||
use Illuminate\Support\Facades\Artisan; | ||
use Tests\IntegrationTestCase; | ||
|
||
final class ElasticSearchEngineTest extends IntegrationTestCase | ||
{ | ||
public function test_pass_empty_response(): void | ||
{ | ||
$dispatcher = Product::getEventDispatcher(); | ||
Product::unsetEventDispatcher(); | ||
|
||
$productsAmount = random_int(1, 5); | ||
$products = factory(Product::class, $productsAmount)->states(['iphone'])->create(); | ||
Product::setEventDispatcher($dispatcher); | ||
|
||
Artisan::call('scout:import'); | ||
|
||
$results = Product::search('Quia', static function($client, $body) { | ||
return $client->search(['index' => 'products', 'body' => $body->toArray()]); | ||
})->raw(); | ||
|
||
$this->assertEmpty($results['hits']['hits']); | ||
} | ||
|
||
public function test_pass_with_response(): void | ||
{ | ||
$dispatcher = Product::getEventDispatcher(); | ||
Product::unsetEventDispatcher(); | ||
|
||
$productsAmount = random_int(1, 5); | ||
factory(Product::class, $productsAmount)->states(['iphone'])->create(); | ||
Product::setEventDispatcher($dispatcher); | ||
|
||
Artisan::call('scout:import'); | ||
|
||
$results = Product::search('iphone', static function($client, $body) { | ||
return $client->search(['index' => 'products', 'body' => $body->toArray()]); | ||
})->raw(); | ||
|
||
$this->assertNotEmpty($results['hits']['hits']); | ||
} | ||
} |