Passed
Push — master ( b27371...d3bd6c )
by Simon
03:17 queued 01:23
created

testAddFulltextFields()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 5
c 1
b 0
f 0
dl 0
loc 9
rs 10
cc 1
nc 1
nop 0
1
<?php
2
3
4
namespace Firesphere\SolrCompatibility\Tests;
5
6
use Firesphere\SolrCompatibility\Extensions\FulltextSearchExtension;
7
use Firesphere\SolrSearch\Indexes\BaseIndex;
8
use Firesphere\SolrSearch\Queries\BaseQuery;
9
use Firesphere\SolrSearch\Tasks\SolrConfigureTask;
10
use Firesphere\SolrSearch\Tests\TestIndex;
11
use Psr\Log\NullLogger;
12
use SilverStripe\Control\NullHTTPRequest;
13
use SilverStripe\Core\Injector\Injector;
14
use SilverStripe\Dev\SapphireTest;
15
use SilverStripe\View\ArrayData;
16
17
class FulltextSearchExtensionTest extends SapphireTest
18
{
19
20
    /**
21
     * @var BaseIndex
22
     */
23
    protected $index;
24
25
    public function testSearch()
26
    {
27
        $query = new BaseQuery();
28
        $query->addTerm('Test');
29
30
        $result = $this->index->search($query, 0, 10, [], true);
31
32
        $this->assertInstanceOf(ArrayData::class, $result);
33
    }
34
35
    public function testSearchWithFields()
36
    {
37
        $query = new BaseQuery();
38
        $query->addTerm('Test');
39
40
        $result = $this->index->search($query, 0, 10, ['fq' => 'Title'], true);
41
42
        $this->assertInstanceOf(ArrayData::class, $result);
43
44
        $this->assertEquals(['Title'], $query->getFields());
45
    }
46
47
    public function testAddFulltextFields()
48
    {
49
        $index = new TestIndex();
50
        $index2 = new TestIndex();
51
52
        $extension1 = new FulltextSearchExtension();
53
        $extension1->setOwner($index);
54
55
        $this->assertEquals($extension1->addFulltextFields(), $index2->addAllFulltextFields());
0 ignored issues
show
Deprecated Code introduced by
The function Firesphere\SolrCompatibi...on::addFulltextFields() has been deprecated: Please use addAllFulltextFields(). IncludeSubClasses is not used anymore ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

55
        $this->assertEquals(/** @scrutinizer ignore-deprecated */ $extension1->addFulltextFields(), $index2->addAllFulltextFields());

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
Bug introduced by
Are you sure the usage of $extension1->addFulltextFields() targeting Firesphere\SolrCompatibi...on::addFulltextFields() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
Bug introduced by
Are you sure the usage of $index2->addAllFulltextFields() targeting Firesphere\SolrSearch\In...:addAllFulltextFields() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
56
    }
57
58
    /**
59
     * @expectedException \LogicException
60
     */
61
    public function testInitToYml()
62
    {
63
        $this->index->initToYml();
64
    }
65
66
67
    protected function setUp()
68
    {
69
        $task = new SolrConfigureTask();
70
        $task->setLogger(new NullLogger());
71
        $task->run(new NullHTTPRequest());
72
73
        $this->index = Injector::inst()->get(TestIndex::class, false);
74
75
        parent::setUp();
76
    }
77
}
78