Completed
Push — master ( 5ad7ea...0c833f )
by Ema
02:22
created

WildcardTest::testConstruct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.9332
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Elastica\Test\Query;
4
5
use Elastica\Document;
6
use Elastica\Mapping;
7
use Elastica\Query\Wildcard;
8
use Elastica\Test\Base as BaseTest;
9
10
/**
11
 * @internal
12
 */
13
class WildcardTest extends BaseTest
14
{
15
    /**
16
     * @group unit
17
     */
18
    public function testConstruct(): void
19
    {
20
        $wildcard = new Wildcard('name', 'aaa*');
21
22
        $data = $wildcard->getParam('name');
23
        $this->assertIsArray($data);
24
25
        $this->assertSame('aaa*', $data['value']);
26
        $this->assertSame(1.0, $data['boost']);
27
    }
28
29
    /**
30
     * @group unit
31
     */
32 View Code Duplication
    public function testToArray(): void
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
33
    {
34
        $wildcard = new Wildcard('name', 'value*', 2.0);
35
        $wildcard->setRewrite(Wildcard::REWRITE_SCORING_BOOLEAN);
36
37
        $expectedArray = [
38
            'wildcard' => [
39
                'name' => [
40
                    'value' => 'value*',
41
                    'boost' => 2.0,
42
                    'rewrite' => 'scoring_boolean',
43
                ],
44
            ],
45
        ];
46
47
        $this->assertEquals($expectedArray, $wildcard->toArray());
48
    }
49
50
    /**
51
     * @group functional
52
     */
53
    public function testSearchWithAnalyzer(): void
54
    {
55
        $client = $this->_getClient();
56
        $index = $client->getIndex('test');
57
58
        $indexParams = [
59
            'settings' => [
60
                'analysis' => [
61
                    'analyzer' => [
62
                        'lw' => [
63
                            'type' => 'custom',
64
                            'tokenizer' => 'keyword',
65
                            'filter' => ['lowercase'],
66
                        ],
67
                    ],
68
                ],
69
            ],
70
        ];
71
72
        $index->create($indexParams, true);
73
74
        $mapping = new Mapping([
75
            'name' => ['type' => 'text', 'analyzer' => 'lw'],
76
        ]);
77
        $index->setMapping($mapping);
78
79
        $index->addDocuments([
80
            new Document(1, ['name' => 'Basel-Stadt']),
81
            new Document(2, ['name' => 'New York']),
82
            new Document(3, ['name' => 'Baden']),
83
            new Document(4, ['name' => 'Baden Baden']),
84
            new Document(5, ['name' => 'New Orleans']),
85
        ]);
86
87
        $index->refresh();
88
89
        $query = new Wildcard('name', 'ba*');
90
        $resultSet = $index->search($query);
0 ignored issues
show
Documentation introduced by
$query is of type object<Elastica\Query\Wildcard>, but the function expects a string|array|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...
91
92
        $this->assertEquals(3, $resultSet->count());
93
94
        $query = new Wildcard('name', 'baden*');
95
        $resultSet = $index->search($query);
0 ignored issues
show
Documentation introduced by
$query is of type object<Elastica\Query\Wildcard>, but the function expects a string|array|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...
96
97
        $this->assertEquals(2, $resultSet->count());
98
99
        $query = new Wildcard('name', 'baden b*');
100
        $resultSet = $index->search($query);
0 ignored issues
show
Documentation introduced by
$query is of type object<Elastica\Query\Wildcard>, but the function expects a string|array|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...
101
102
        $this->assertEquals(1, $resultSet->count());
103
104
        $query = new Wildcard('name', 'baden bas*');
105
        $resultSet = $index->search($query);
0 ignored issues
show
Documentation introduced by
$query is of type object<Elastica\Query\Wildcard>, but the function expects a string|array|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...
106
107
        $this->assertEquals(0, $resultSet->count());
108
    }
109
}
110