15
15
16
16
use Behat \Behat \Context \Context ;
17
17
use Elastic \Elasticsearch \Client ;
18
+ use Elasticsearch \Client as V7Client ;
18
19
use Symfony \Component \Finder \Finder ;
19
20
20
21
/**
24
25
*/
25
26
final class ElasticsearchContext implements Context
26
27
{
27
- public function __construct (private readonly Client $ client , private readonly string $ elasticsearchMappingsPath , private readonly string $ elasticsearchFixturesPath )
28
- {
28
+ public function __construct (
29
+ private readonly V7Client |Client $ client , // @phpstan-ignore-line
30
+ private readonly string $ elasticsearchMappingsPath ,
31
+ private readonly string $ elasticsearchFixturesPath ,
32
+ ) {
29
33
}
30
34
31
35
/**
@@ -76,7 +80,7 @@ private function createIndexesAndMappings(): void
76
80
$ finder ->files ()->in ($ this ->elasticsearchMappingsPath );
77
81
78
82
foreach ($ finder as $ file ) {
79
- $ this ->client ->indices ()->create ([
83
+ $ this ->client ->indices ()->create ([ // @phpstan-ignore-line
80
84
'index ' => $ file ->getBasename ('.json ' ),
81
85
'body ' => json_decode ($ file ->getContents (), true , 512 , \JSON_THROW_ON_ERROR ),
82
86
]);
@@ -95,7 +99,7 @@ private function deleteIndexes(): void
95
99
}
96
100
97
101
if ([] !== $ indexes ) {
98
- $ this ->client ->indices ()->delete ([
102
+ $ this ->client ->indices ()->delete ([ // @phpstan-ignore-line
99
103
'index ' => implode (', ' , $ indexes ),
100
104
'ignore_unavailable ' => true ,
101
105
]);
@@ -107,7 +111,7 @@ private function loadFixtures(): void
107
111
$ finder = new Finder ();
108
112
$ finder ->files ()->in ($ this ->elasticsearchFixturesPath )->name ('*.json ' );
109
113
110
- $ indexClient = $ this ->client ->indices ();
114
+ $ indexClient = $ this ->client ->indices (); // @phpstan-ignore-line
111
115
112
116
foreach ($ finder as $ file ) {
113
117
$ index = $ file ->getBasename ('.json ' );
@@ -123,13 +127,13 @@ private function loadFixtures(): void
123
127
$ bulk [] = $ document ;
124
128
125
129
if (0 === (\count ($ bulk ) % 50 )) {
126
- $ this ->client ->bulk (['body ' => $ bulk ]);
130
+ $ this ->client ->bulk (['body ' => $ bulk ]); // @phpstan-ignore-line
127
131
$ bulk = [];
128
132
}
129
133
}
130
134
131
135
if ($ bulk ) {
132
- $ this ->client ->bulk (['body ' => $ bulk ]);
136
+ $ this ->client ->bulk (['body ' => $ bulk ]); // @phpstan-ignore-line
133
137
}
134
138
135
139
$ indexClient ->refresh (['index ' => $ index ]);
0 commit comments