Skip to content

Commit

Permalink
ElasticSearchEngine feature tests improved
Browse files Browse the repository at this point in the history
  • Loading branch information
hkulekci committed Apr 20, 2022
1 parent 6f89a06 commit 45c9f69
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions tests/Feature/ElasticSearchEngineTest.php
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']);
}
}

0 comments on commit 45c9f69

Please sign in to comment.