Completed
Push — master ( 33dbac...15770d )
by
unknown
18s queued 10s
created

ElasticaAdapterTest::setUp()   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
c 1
b 0
f 0
dl 0
loc 10
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
use PHPUnit\Framework\TestCase;
9
10
class ElasticaAdapterTest extends TestCase
11
{
12
    /**
13
     * @var ElasticaAdapter
14
     */
15
    private $adapter;
16
    private $resultSet;
17
    private $searchable;
18
    private $query;
19
    private $options;
20
21
    protected function setUp()
22
    {
23
        $this->query = $this->getMockBuilder('Elastica\\Query')->disableOriginalConstructor()->getMock();
24
        $this->resultSet = $this->getMockBuilder('Elastica\\ResultSet')->disableOriginalConstructor()->getMock();
25
        $this->searchable = $this->getMockBuilder('Elastica\\SearchableInterface')->disableOriginalConstructor()->getMock();
26
27
        $this->options = array("option1" => "value1", "option2" => "value2");
28
29
        $this->adapter = new ElasticaAdapter($this->searchable, $this->query, $this->options);
0 ignored issues
show
Documentation introduced by
$this->searchable is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Elastica\SearchableInterface>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
Documentation introduced by
$this->query is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Elastica\Query>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
30
    }
31
32
    public function testGetResultSet()
33
    {
34
        $this->assertNull($this->adapter->getResultSet());
35
36
        $this->searchable->expects($this->any())
37
            ->method('search')
38
            ->with($this->query, array('from' => 0, 'size' => 1, 'option1' => 'value1', 'option2' => 'value2'))
39
            ->will($this->returnValue($this->resultSet));
40
41
        $this->adapter->getSlice(0, 1);
42
43
        $this->assertSame($this->resultSet, $this->adapter->getResultSet());
44
    }
45
46
    public function testGetSlice()
47
    {
48
        $this->searchable->expects($this->any())
49
            ->method('search')
50
            ->with($this->query, array('from' => 10, 'size' => 30, 'option1' => 'value1', 'option2' => 'value2'))
51
            ->will($this->returnValue($this->resultSet));
52
53
        $resultSet = $this->adapter->getSlice(10, 30);
54
55
        $this->assertSame($this->resultSet, $resultSet);
56
        $this->assertSame($this->resultSet, $this->adapter->getResultSet());
57
    }
58
59
    public function testGetNbResults()
60
    {
61
        $this->searchable->expects($this->any())
62
            ->method('search')
63
            ->with($this->query, $this->options)
64
            ->will($this->returnValue($this->resultSet));
65
66
        $this->resultSet->expects($this->once())
67
            ->method('getTotalHits')
68
            ->will($this->returnValue(100));
69
70
        $this->assertSame(100, $this->adapter->getNbResults());
71
    }
72
73
    public function testGetNbResultsWithMaxResultsSet()
74
    {
75
        $adapter = new ElasticaAdapter($this->searchable, $this->query, [], 10);
0 ignored issues
show
Documentation introduced by
$this->searchable is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Elastica\SearchableInterface>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
Documentation introduced by
$this->query is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Elastica\Query>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
76
77
        $this->searchable->expects($this->any())
78
            ->method('search')
79
            ->with($this->query, [])
80
            ->will($this->returnValue($this->resultSet));
81
82
        $this->resultSet->expects($this->once())
83
            ->method('getTotalHits')
84
            ->will($this->returnValue(100));
85
86
        $this->assertSame(10, $adapter->getNbResults());
87
    }
88
}
89