summaryrefslogtreecommitdiff
path: root/vendor/ruflin/elastica/test/lib/Elastica/Test/Transport/NullTest.php
blob: c07f5da158a42eb3a881bd509396b3de32ffbf9e (plain)
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
<?php

namespace Elastica\Test\Transport;

use Elastica\Client;
use Elastica\Connection;
use Elastica\Query;
use Elastica\Test\Base as BaseTest;

/**
 * Elastica Null Transport Test
 *
 * @package Elastica
 * @author James Boehmer <james.boehmer@jamesboehmer.com>
 */
class NullTest extends BaseTest
{

    public function testEmptyResult()
    {
        // Creates a client with any destination, and verify it returns a response object when executed
        $client = $this->_getClient();
        $connection = new Connection(array('transport' => 'Null'));
        $client->setConnections(array($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"]);
    }
}