Completed
Pull Request — master (#1911)
by Sam
03:08
created

BoostingTest   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 3
dl 0
loc 52
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A testToArray() 0 21 1
A testNegativeBoost() 0 21 1
1
<?php
2
3
namespace Elastica\Test\Query;
4
5
use Elastica\Query\Boosting;
6
use Elastica\Query\Term;
7
use Elastica\Test\Base as BaseTest;
8
9
/**
10
 * @internal
11
 */
12
class BoostingTest extends BaseTest
13
{
14
    /**
15
     * @group unit
16
     */
17
    public function testToArray(): void
18
    {
19
        $keyword = 'vital';
20
        $negativeKeyword = 'Mercury';
21
22
        $query = new Boosting();
23
        $positiveQuery = new Term(['name' => $keyword]);
24
        $negativeQuery = new Term(['name' => $negativeKeyword]);
25
        $query->setPositiveQuery($positiveQuery);
26
        $query->setNegativeQuery($negativeQuery);
27
        $query->setNegativeBoost(0.3);
28
29
        $expected = [
30
            'boosting' => [
31
                'positive' => $positiveQuery->toArray(),
32
                'negative' => $negativeQuery->toArray(),
33
                'negative_boost' => 0.3,
34
            ],
35
        ];
36
        $this->assertEquals($expected, $query->toArray());
37
    }
38
39
    /**
40
     * @group unit
41
     */
42
    public function testNegativeBoost(): void
43
    {
44
        $keyword = 'vital';
45
        $negativeKeyword = 'mercury';
46
47
        $query = new Boosting();
48
        $positiveQuery = new Term();
49
        $positiveQuery->setTerm('name', $keyword, 5.0);
50
        $negativeQuery = new Term();
51
        $negativeQuery->setTerm('name', $negativeKeyword, 8.0);
52
        $query->setPositiveQuery($positiveQuery);
53
        $query->setNegativeQuery($negativeQuery);
54
        $query->setNegativeBoost(23.0);
55
        $query->setParam('boost', 42.0);
56
57
        $queryToCheck = $query->toArray();
58
        $this->assertEquals(42.0, $queryToCheck['boosting']['boost']);
59
        $this->assertEquals(5.0, $queryToCheck['boosting']['positive']['term']['name']['boost']);
60
        $this->assertEquals(8.0, $queryToCheck['boosting']['negative']['term']['name']['boost']);
61
        $this->assertEquals(23.0, $queryToCheck['boosting']['negative_boost']);
62
    }
63
}
64