Completed
Push — master ( 9146c8...39ecb4 )
by Nicolas
04:52
created

SuggestTest::testCreateWithSuggest()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
c 0
b 0
f 0
rs 10
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Elastica\Test;
4
5
use Elastica\Exception\NotImplementedException;
6
use Elastica\Query\BoolQuery;
7
use Elastica\Suggest;
8
use Elastica\Suggest\Term;
9
use Elastica\Test\Base as BaseTest;
10
11
/**
12
 * @internal
13
 */
14
class SuggestTest extends BaseTest
15
{
16
    /**
17
     * Create self test.
18
     *
19
     * @group functional
20
     */
21
    public function testCreateSelf(): void
22
    {
23
        $suggest = new Suggest();
24
25
        $selfSuggest = Suggest::create($suggest);
26
27
        $this->assertSame($suggest, $selfSuggest);
28
    }
29
30
    /**
31
     * Create with suggest test.
32
     *
33
     * @group functional
34
     */
35
    public function testCreateWithSuggest(): void
36
    {
37
        $suggest1 = new Term('suggest1', '_all');
38
39
        $suggest = Suggest::create($suggest1);
40
41
        $this->assertTrue($suggest->hasParam('suggestion'));
42
    }
43
44
    /**
45
     * Create with non suggest test.
46
     *
47
     * @group functional
48
     */
49
    public function testCreateWithNonSuggest(): void
50
    {
51
        try {
52
            Suggest::create(new BoolQuery());
0 ignored issues
show
Documentation introduced by
new \Elastica\Query\BoolQuery() is of type object<Elastica\Query\BoolQuery>, but the function expects a object<Elastica\Suggest\...bject<Elastica\Suggest>.

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...
53
            $this->fail();
54
        } catch (NotImplementedException $e) {
0 ignored issues
show
Coding Style Comprehensibility introduced by
Consider adding a comment why this CATCH block is empty.
Loading history...
55
        }
56
    }
57
}
58