Completed
Pull Request — master (#213)
by Olivier
05:46
created

testGetNbResultsWithMaxResultsSet()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 10
c 1
b 0
f 0
rs 9.4285
cc 1
eloc 6
nc 1
nop 0
1
<?php
2
3
namespace Pagerfanta\Tests\Adapter;
4
5
use Elastica\Response;
6
use Elastica\ResultSet;
7
use Pagerfanta\Adapter\ElasticaAdapter;
8
9
class ElasticaAdapterTest extends \PHPUnit_Framework_TestCase
10
{
11
    /**
12
     * @var ElasticaAdapter
13
     */
14
    private $adapter;
15
    private $resultSet;
16
    private $searchable;
17
    private $query;
18
19
    protected function setUp()
20
    {
21
        $this->query = $this->getMockBuilder('Elastica\\Query')->disableOriginalConstructor()->getMock();
22
        $this->resultSet = $this->getMockBuilder('Elastica\\ResultSet')->disableOriginalConstructor()->getMock();
23
        $this->searchable = $this->getMockBuilder('Elastica\\SearchableInterface')->disableOriginalConstructor()->getMock();
24
25
        $this->adapter = new ElasticaAdapter($this->searchable, $this->query);
26
27
        $this->searchable->expects($this->any())
28
            ->method('search')
29
            ->with($this->query)
30
            ->will($this->returnValue($this->resultSet));
31
    }
32
33
    public function testGetResultSet()
34
    {
35
        $this->assertNull($this->adapter->getResultSet());
36
37
        $this->searchable->expects($this->any())
38
            ->method('search')
39
            ->with($this->query, array('from' => 0, 'size' => 1))
40
            ->will($this->returnValue($this->resultSet));
41
42
        $this->adapter->getSlice(0, 1);
43
44
        $this->assertSame($this->resultSet, $this->adapter->getResultSet());
45
    }
46
47
    public function testGetSlice()
48
    {
49
        $this->searchable->expects($this->any())
50
            ->method('search')
51
            ->with($this->query, array('from' => 10, 'size' => 30))
52
            ->will($this->returnValue($this->resultSet));
53
54
        $resultSet = $this->adapter->getSlice(10, 30);
55
56
        $this->assertSame($this->resultSet, $resultSet);
57
        $this->assertSame($this->resultSet, $this->adapter->getResultSet());
58
    }
59
60
    public function testGetNbResults()
61
    {
62
        $this->resultSet->expects($this->once())
63
            ->method('getTotalHits')
64
            ->will($this->returnValue(100));
65
66
        $this->assertSame(100, $this->adapter->getNbResults());
67
    }
68
69
    public function testGetNbResultsWithMaxResultsSet()
70
    {
71
        $adapter = new ElasticaAdapter($this->searchable, $this->query, 10);
72
73
        $this->resultSet->expects($this->once())
74
            ->method('getTotalHits')
75
            ->will($this->returnValue(100));
76
77
        $this->assertSame(10, $adapter->getNbResults());
78
    }
79
}
80