-
Notifications
You must be signed in to change notification settings - Fork 733
/
NullTransportTest.php
135 lines (113 loc) · 4.04 KB
/
NullTransportTest.php
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
<?php
namespace Elastica\Test\Transport;
use Elastica\Connection;
use Elastica\Query;
use Elastica\Request;
use Elastica\Response;
use Elastica\Test\Base as BaseTest;
use Elastica\Transport\NullTransport;
/**
* Elastica Null Transport Test.
*
* @author James Boehmer <james.boehmer@jamesboehmer.com>
* @author Jan Domanski <jandom@gmail.com>
*/
class NullTransportTest extends BaseTest
{
/** @var NullTransport NullTransport */
protected $transport;
public function setUp()
{
parent::setUp();
$this->transport = new NullTransport();
}
/**
* @group functional
*/
public function testEmptyResult()
{
// Creates a client with any destination, and verify it returns a response object when executed
$client = $this->_getClient();
$connection = new Connection(['transport' => 'NullTransport']);
$client->setConnections([$connection]);
$index = $client->getIndex('elasticaNullTransportTest1');
$resultSet = $index->search(new Query());
$this->assertNotNull($resultSet);
$response = $resultSet->getResponse();
$this->assertNotNull($response);
// Validate most of the expected fields in the response data. Consumers of the response
// object have a reasonable expectation of finding "hits", "took", etc
$responseData = $response->getData();
$this->assertContains('took', $responseData);
$this->assertEquals(0, $responseData['took']);
$this->assertContains('_shards', $responseData);
$this->assertContains('hits', $responseData);
$this->assertContains('total', $responseData['hits']);
$this->assertEquals(0, $responseData['hits']['total']);
$this->assertContains('params', $responseData);
$took = $response->getEngineTime();
$this->assertEquals(0, $took);
$errorString = $response->getError();
$this->assertEmpty($errorString);
$shards = $response->getShardsStatistics();
$this->assertContains('total', $shards);
$this->assertEquals(0, $shards['total']);
$this->assertContains('successful', $shards);
$this->assertEquals(0, $shards['successful']);
$this->assertContains('failed', $shards);
$this->assertEquals(0, $shards['failed']);
}
/**
* @group functional
*/
public function testExec()
{
$request = new Request('/test');
$params = ['name' => 'ruflin'];
$transport = new NullTransport();
$response = $transport->exec($request, $params);
$this->assertInstanceOf(Response::class, $response);
$data = $response->getData();
$this->assertEquals($params, $data['params']);
}
/**
* @group functional
*/
public function testOldObject()
{
if (version_compare(phpversion(), 7, '>=')) {
self::markTestSkipped('These objects are not supported in PHP 7');
}
$request = new Request('/test');
$params = ['name' => 'ruflin'];
$this->hideDeprecated();
$transport = new \Elastica\Transport\Null();
$this->showDeprecated();
$response = $transport->exec($request, $params);
$this->assertInstanceOf(Response::class, $response);
$data = $response->getData();
$this->assertEquals($params, $data['params']);
}
/**
* @group unit
*/
public function testResponse()
{
$resposeString = '';
$response = new Response($resposeString);
$this->transport->setResponse($response);
$this->assertEquals($response, $this->transport->getResponse());
}
/**
* @group unit
*/
public function testGenerateDefaultResponse()
{
$params = [ 'blah' => 123 ];
$response = $this->transport->generateDefaultResponse($params);
$this->assertEquals([], $response->getTransferInfo());
$responseData = $response->getData();
$this->assertContains('params', $responseData);
$this->assertEquals($params, $responseData['params']);
}
}