Skip to content

Commit 370cb32

Browse files
committed
#105512 Рефакторинг тестов
1 parent 1828014 commit 370cb32

File tree

3 files changed

+18
-22
lines changed

3 files changed

+18
-22
lines changed

composer.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,10 @@
4343

4444
},
4545
"config": {
46-
"sort-packages": true
46+
"sort-packages": true,
47+
"allow-plugins": {
48+
"php-http/discovery": false
49+
}
4750
},
4851
"extra": {
4952
"laravel": {

tests/Seeds/IndexSeeder.php

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace Ensi\LaravelElasticQuery\Tests\Seeds;
44

5-
use Elasticsearch\Client;
5+
use Ensi\LaravelElasticQuery\ElasticClient;
66

77
abstract class IndexSeeder
88
{
@@ -13,14 +13,14 @@ abstract class IndexSeeder
1313

1414
protected bool $recreate;
1515

16-
protected ?Client $client;
16+
protected ?ElasticClient $client;
1717

1818
public function __construct()
1919
{
2020
$this->recreate = config('tests.recreate_index', true);
2121
}
2222

23-
public function setClient(Client $client): void
23+
public function setClient(ElasticClient $client): void
2424
{
2525
$this->client = $client;
2626
}
@@ -49,31 +49,27 @@ public function call(): void
4949

5050
protected function isIndexExists(): bool
5151
{
52-
return $this->client->indices()->exists(['index' => $this->indexName]);
52+
return $this->client->indicesExists($this->indexName);
5353
}
5454

5555
protected function dropIndex(): void
5656
{
57-
$this->client
58-
->indices()
59-
->delete(['index' => $this->indexName]);
57+
$this->client->indicesDelete($this->indexName);
6058
}
6159

6260
protected function createIndex(): void
6361
{
64-
$params = ['index' => $this->indexName];
62+
$settings = [];
6563

6664
if (!empty($this->mappings)) {
67-
data_set($params, 'body.mappings', $this->mappings);
65+
$settings['mappings'] = $this->mappings;
6866
}
6967

7068
if (!empty($this->settings)) {
71-
data_set($params, 'body.settings', $this->settings);
69+
$settings['settings'] = $this->settings;
7270
}
7371

74-
$this->client
75-
->indices()
76-
->create($params);
72+
$this->client->indicesCreate($this->indexName, $settings);
7773
}
7874

7975
protected function loadFixtures(): void
@@ -87,7 +83,7 @@ protected function loadFixtures(): void
8783
);
8884

8985
if ($hasChanges) {
90-
$this->client->indices()->refresh(['index' => $this->indexName]);
86+
$this->client->indicesRefresh($this->indexName);
9187
}
9288
}
9389

@@ -103,7 +99,7 @@ protected function loadFixture(string $path): bool
10399
->flatMap(fn (array $document, int $index) => $this->documentToCommand($document, $index))
104100
->toArray();
105101

106-
$this->client->bulk(['body' => $body]);
102+
$this->client->bulk($this->indexName, $body);
107103

108104
return true;
109105
}

tests/Seeds/SeedRunner.php

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,15 @@
22

33
namespace Ensi\LaravelElasticQuery\Tests\Seeds;
44

5-
use Elasticsearch\Client;
6-
use Elasticsearch\ClientBuilder;
5+
use Ensi\LaravelElasticQuery\ElasticClient;
76

87
class SeedRunner
98
{
109
private static ?self $instance;
1110

1211
private array $processed = [];
1312

14-
protected function __construct(private Client $client)
13+
protected function __construct(private ElasticClient $client)
1514
{
1615
}
1716

@@ -38,9 +37,7 @@ public static function getInstance(): self
3837

3938
private static function createInstance(): self
4039
{
41-
$client = ClientBuilder::create()
42-
->setHosts(config('laravel-elastic-query.connection.hosts'))
43-
->build();
40+
$client = ElasticClient::fromConfig(config('laravel-elastic-query.connection'));
4441

4542
return new self($client);
4643
}

0 commit comments

Comments
 (0)