Skip to content

Commit 8057efb

Browse files
committed
Merge branch 'safecat-master'
2 parents 924e1dc + 8eb350a commit 8057efb

File tree

9 files changed

+347
-122
lines changed

9 files changed

+347
-122
lines changed

src/Elasticsearch/Helper/Iterators/SearchHitIterator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ public function current()
130130
*/
131131
public function key()
132132
{
133-
return $this->current_hit_index;
133+
return $this->current_key;
134134
}
135135

136136
/**

tests/Elasticsearch/Tests/ClientTest.php

Lines changed: 96 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,13 @@ public function testIndexCannotBeNullForDelete()
8686
$this->expectException(Elasticsearch\Common\Exceptions\InvalidArgumentException::class);
8787
$this->expectExceptionMessage('index cannot be null.');
8888

89-
$client->delete([
89+
$client->delete(
90+
[
9091
'index' => null,
9192
'type' => 'test',
9293
'id' => 'test'
93-
]);
94+
]
95+
);
9496
}
9597

9698
public function testTypeCannotBeNullForDelete()
@@ -100,11 +102,13 @@ public function testTypeCannotBeNullForDelete()
100102
$this->expectException(Elasticsearch\Common\Exceptions\InvalidArgumentException::class);
101103
$this->expectExceptionMessage('type cannot be null.');
102104

103-
$client->delete([
105+
$client->delete(
106+
[
104107
'index' => 'test',
105108
'type' => null,
106109
'id' => 'test'
107-
]);
110+
]
111+
);
108112
}
109113

110114
public function testIdCannotBeNullForDelete()
@@ -114,11 +118,13 @@ public function testIdCannotBeNullForDelete()
114118
$this->expectException(Elasticsearch\Common\Exceptions\InvalidArgumentException::class);
115119
$this->expectExceptionMessage('id cannot be null.');
116120

117-
$client->delete([
121+
$client->delete(
122+
[
118123
'index' => 'test',
119124
'type' => 'test',
120125
'id' => null
121-
]);
126+
]
127+
);
122128
}
123129

124130
public function testIndexCannotBeEmptyStringForDelete()
@@ -128,11 +134,13 @@ public function testIndexCannotBeEmptyStringForDelete()
128134
$this->expectException(Elasticsearch\Common\Exceptions\InvalidArgumentException::class);
129135
$this->expectExceptionMessage('index cannot be an empty string');
130136

131-
$client->delete([
137+
$client->delete(
138+
[
132139
'index' => '',
133140
'type' => 'test',
134141
'id' => 'test'
135-
]);
142+
]
143+
);
136144
}
137145

138146
public function testTypeCannotBeEmptyStringForDelete()
@@ -142,11 +150,13 @@ public function testTypeCannotBeEmptyStringForDelete()
142150
$this->expectException(Elasticsearch\Common\Exceptions\InvalidArgumentException::class);
143151
$this->expectExceptionMessage('type cannot be an empty string');
144152

145-
$client->delete([
153+
$client->delete(
154+
[
146155
'index' => 'test',
147156
'type' => '',
148157
'id' => 'test'
149-
]);
158+
]
159+
);
150160
}
151161

152162
public function testIdCannotBeEmptyStringForDelete()
@@ -156,11 +166,13 @@ public function testIdCannotBeEmptyStringForDelete()
156166
$this->expectException(Elasticsearch\Common\Exceptions\InvalidArgumentException::class);
157167
$this->expectExceptionMessage('id cannot be an empty string');
158168

159-
$client->delete([
169+
$client->delete(
170+
[
160171
'index' => 'test',
161172
'type' => 'test',
162173
'id' => ''
163-
]);
174+
]
175+
);
164176
}
165177

166178
public function testIndexCannotBeArrayOfEmptyStringsForDelete()
@@ -170,11 +182,13 @@ public function testIndexCannotBeArrayOfEmptyStringsForDelete()
170182
$this->expectException(Elasticsearch\Common\Exceptions\InvalidArgumentException::class);
171183
$this->expectExceptionMessage('index cannot be an array of empty strings');
172184

173-
$client->delete([
185+
$client->delete(
186+
[
174187
'index' => ['', '', ''],
175188
'type' => 'test',
176189
'id' => 'test'
177-
]);
190+
]
191+
);
178192
}
179193

180194
public function testTypeCannotBeArrayOfEmptyStringsForDelete()
@@ -184,11 +198,13 @@ public function testTypeCannotBeArrayOfEmptyStringsForDelete()
184198
$this->expectException(Elasticsearch\Common\Exceptions\InvalidArgumentException::class);
185199
$this->expectExceptionMessage('type cannot be an array of empty strings');
186200

187-
$client->delete([
201+
$client->delete(
202+
[
188203
'index' => 'test',
189204
'type' => ['', '', ''],
190205
'id' => 'test'
191-
]);
206+
]
207+
);
192208
}
193209

194210
public function testIndexCannotBeArrayOfNullsForDelete()
@@ -198,11 +214,13 @@ public function testIndexCannotBeArrayOfNullsForDelete()
198214
$this->expectException(Elasticsearch\Common\Exceptions\InvalidArgumentException::class);
199215
$this->expectExceptionMessage('index cannot be an array of empty strings');
200216

201-
$client->delete([
217+
$client->delete(
218+
[
202219
'index' => [null, null, null],
203220
'type' => 'test',
204221
'id' => 'test'
205-
]);
222+
]
223+
);
206224
}
207225

208226
public function testTypeCannotBeArrayOfNullsForDelete()
@@ -212,11 +230,13 @@ public function testTypeCannotBeArrayOfNullsForDelete()
212230
$this->expectException(Elasticsearch\Common\Exceptions\InvalidArgumentException::class);
213231
$this->expectExceptionMessage('type cannot be an array of empty strings');
214232

215-
$client->delete([
233+
$client->delete(
234+
[
216235
'index' => 'test',
217236
'type' => [null, null, null],
218237
'id' => 'test'
219-
]);
238+
]
239+
);
220240
}
221241

222242
public function testMaxRetriesException()
@@ -272,39 +292,49 @@ public function testMaxRetriesException()
272292

273293
public function testInlineHosts()
274294
{
275-
$client = Elasticsearch\ClientBuilder::create()->setHosts([
295+
$client = Elasticsearch\ClientBuilder::create()->setHosts(
296+
[
276297
'localhost:9200'
277-
])->build();
298+
]
299+
)->build();
278300
$host = $client->transport->getConnection();
279301
$this->assertSame("localhost:9200", $host->getHost());
280302
$this->assertSame("http", $host->getTransportSchema());
281303

282304

283-
$client = Elasticsearch\ClientBuilder::create()->setHosts([
305+
$client = Elasticsearch\ClientBuilder::create()->setHosts(
306+
[
284307
'http://localhost:9200'
285-
])->build();
308+
]
309+
)->build();
286310
$host = $client->transport->getConnection();
287311
$this->assertSame("localhost:9200", $host->getHost());
288312
$this->assertSame("http", $host->getTransportSchema());
289313

290-
$client = Elasticsearch\ClientBuilder::create()->setHosts([
314+
$client = Elasticsearch\ClientBuilder::create()->setHosts(
315+
[
291316
'http://foo.com:9200'
292-
])->build();
317+
]
318+
)->build();
293319
$host = $client->transport->getConnection();
294320
$this->assertSame("foo.com:9200", $host->getHost());
295321
$this->assertSame("http", $host->getTransportSchema());
296322

297-
$client = Elasticsearch\ClientBuilder::create()->setHosts([
323+
$client = Elasticsearch\ClientBuilder::create()->setHosts(
324+
[
298325
'https://foo.com:9200'
299-
])->build();
326+
]
327+
)->build();
300328
$host = $client->transport->getConnection();
301329
$this->assertSame("foo.com:9200", $host->getHost());
302330
$this->assertSame("https", $host->getTransportSchema());
303331

304332

305-
$client = Elasticsearch\ClientBuilder::create()->setHosts([
333+
$client = Elasticsearch\ClientBuilder::create()->setHosts(
334+
[
306335
'https://user:[email protected]:9200'
307-
])->build();
336+
]
337+
)->build();
308338
$host = $client->transport->getConnection();
309339
$this->assertSame("foo.com:9200", $host->getHost());
310340
$this->assertSame("https", $host->getTransportSchema());
@@ -313,106 +343,124 @@ public function testInlineHosts()
313343

314344
public function testExtendedHosts()
315345
{
316-
$client = Elasticsearch\ClientBuilder::create()->setHosts([
346+
$client = Elasticsearch\ClientBuilder::create()->setHosts(
347+
[
317348
[
318349
'host' => 'localhost',
319350
'port' => 9200,
320351
'scheme' => 'http'
321352
]
322-
])->build();
353+
]
354+
)->build();
323355
$host = $client->transport->getConnection();
324356
$this->assertSame("localhost:9200", $host->getHost());
325357
$this->assertSame("http", $host->getTransportSchema());
326358

327359

328-
$client = Elasticsearch\ClientBuilder::create()->setHosts([
360+
$client = Elasticsearch\ClientBuilder::create()->setHosts(
361+
[
329362
[
330363
'host' => 'foo.com',
331364
'port' => 9200,
332365
'scheme' => 'http'
333366
]
334-
])->build();
367+
]
368+
)->build();
335369
$host = $client->transport->getConnection();
336370
$this->assertSame("foo.com:9200", $host->getHost());
337371
$this->assertSame("http", $host->getTransportSchema());
338372

339373

340-
$client = Elasticsearch\ClientBuilder::create()->setHosts([
374+
$client = Elasticsearch\ClientBuilder::create()->setHosts(
375+
[
341376
[
342377
'host' => 'foo.com',
343378
'port' => 9200,
344379
'scheme' => 'https'
345380
]
346-
])->build();
381+
]
382+
)->build();
347383
$host = $client->transport->getConnection();
348384
$this->assertSame("foo.com:9200", $host->getHost());
349385
$this->assertSame("https", $host->getTransportSchema());
350386

351387

352-
$client = Elasticsearch\ClientBuilder::create()->setHosts([
388+
$client = Elasticsearch\ClientBuilder::create()->setHosts(
389+
[
353390
[
354391
'host' => 'foo.com',
355392
'scheme' => 'http'
356393
]
357-
])->build();
394+
]
395+
)->build();
358396
$host = $client->transport->getConnection();
359397
$this->assertSame("foo.com:9200", $host->getHost());
360398
$this->assertSame("http", $host->getTransportSchema());
361399

362400

363-
$client = Elasticsearch\ClientBuilder::create()->setHosts([
401+
$client = Elasticsearch\ClientBuilder::create()->setHosts(
402+
[
364403
[
365404
'host' => 'foo.com'
366405
]
367-
])->build();
406+
]
407+
)->build();
368408
$host = $client->transport->getConnection();
369409
$this->assertSame("foo.com:9200", $host->getHost());
370410
$this->assertSame("http", $host->getTransportSchema());
371411

372412

373-
$client = Elasticsearch\ClientBuilder::create()->setHosts([
413+
$client = Elasticsearch\ClientBuilder::create()->setHosts(
414+
[
374415
[
375416
'host' => 'foo.com',
376417
'port' => 9500,
377418
'scheme' => 'https'
378419
]
379-
])->build();
420+
]
421+
)->build();
380422
$host = $client->transport->getConnection();
381423
$this->assertSame("foo.com:9500", $host->getHost());
382424
$this->assertSame("https", $host->getTransportSchema());
383425

384426

385427
try {
386-
$client = Elasticsearch\ClientBuilder::create()->setHosts([
428+
$client = Elasticsearch\ClientBuilder::create()->setHosts(
429+
[
387430
[
388431
'port' => 9200,
389432
'scheme' => 'http'
390433
]
391-
])->build();
434+
]
435+
)->build();
392436
$this->fail("Expected RuntimeException from missing host, none thrown");
393437
} catch (Elasticsearch\Common\Exceptions\RuntimeException $e) {
394438
// good
395439
}
396440

397441
// Underscore host, questionably legal, but inline method would break
398-
$client = Elasticsearch\ClientBuilder::create()->setHosts([
442+
$client = Elasticsearch\ClientBuilder::create()->setHosts(
443+
[
399444
[
400445
'host' => 'the_foo.com'
401446
]
402-
])->build();
447+
]
448+
)->build();
403449
$host = $client->transport->getConnection();
404450
$this->assertSame("the_foo.com:9200", $host->getHost());
405451
$this->assertSame("http", $host->getTransportSchema());
406452

407453

408454
// Special characters in user/pass, would break inline
409-
$client = Elasticsearch\ClientBuilder::create()->setHosts([
455+
$client = Elasticsearch\ClientBuilder::create()->setHosts(
456+
[
410457
[
411458
'host' => 'foo.com',
412459
'user' => 'user',
413460
'pass' => 'abc#$@?%!abc'
414461
]
415-
])->build();
462+
]
463+
)->build();
416464
$host = $client->transport->getConnection();
417465
$this->assertSame("foo.com:9200", $host->getHost());
418466
$this->assertSame("http", $host->getTransportSchema());

0 commit comments

Comments
 (0)