forked from ruflin/Elastica
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathResponseFunctionalTest.php
More file actions
94 lines (77 loc) · 2.71 KB
/
Copy pathResponseFunctionalTest.php
File metadata and controls
94 lines (77 loc) · 2.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
<?php
namespace Elastica\Test;
use Elastica\Document;
use Elastica\Exception\ResponseException;
use Elastica\Mapping;
use Elastica\Query;
use Elastica\Query\MatchAll;
use Elastica\Request;
use Elastica\Test\Base as BaseTest;
/**
* @group functional
*
* @internal
*/
class ResponseFunctionalTest extends BaseTest
{
public function testResponse(): void
{
$index = $this->_createIndex();
$index->setMapping(new Mapping([
'name' => ['type' => 'text'],
'dtmPosted' => ['type' => 'date', 'format' => 'yyyy-MM-dd HH:mm:ss'],
]));
$index->addDocuments([
new Document('1', ['name' => 'nicolas ruflin', 'dtmPosted' => '2011-06-23 21:53:00']),
new Document('2', ['name' => 'raul martinez jr', 'dtmPosted' => '2011-06-23 09:53:00']),
new Document('3', ['name' => 'rachelle clemente', 'dtmPosted' => '2011-07-08 08:53:00']),
new Document('4', ['name' => 'elastica search', 'dtmPosted' => '2011-07-08 01:53:00']),
]);
$query = new Query();
$query->setQuery(new MatchAll());
$index->refresh();
$resultSet = $index->search($query);
$engineTime = $resultSet->getResponse()->getEngineTime();
$shardsStats = $resultSet->getResponse()->getShardsStatistics();
$this->assertIsInt($engineTime);
$this->assertIsArray($shardsStats);
$this->assertArrayHasKey('total', $shardsStats);
$this->assertArrayHasKey('successful', $shardsStats);
}
public function testIsOk(): void
{
$index = $this->_createIndex();
$doc = new Document('1', ['name' => 'ruflin']);
$response = $index->addDocument($doc);
$this->assertTrue($response->isOk());
}
public function testIsOkMultiple(): void
{
$index = $this->_createIndex();
$docs = [
new Document('1', ['name' => 'ruflin']),
new Document('2', ['name' => 'ruflin']),
];
$response = $index->addDocuments($docs);
$this->assertTrue($response->isOk());
}
public function testGetDataEmpty(): void
{
$index = $this->_createIndex();
$gotException = false;
try {
$index->request(
'non-existent-type/_mapping',
Request::GET,
[],
['include_type_name' => true]
);
} catch (ResponseException $e) {
$error = $e->getResponse()->getFullError();
$this->assertEquals('type_missing_exception', $error['type']);
$this->assertStringContainsString('non-existent-type', $error['reason']);
$gotException = true;
}
$this->assertTrue($gotException);
}
}