Passed
Pull Request — master (#4)
by Gordon
08:08
created

IndexTest::testHasManyields()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 10
c 0
b 0
f 0
dl 0
loc 12
rs 9.9332
cc 1
nc 1
nop 0
1
<?php declare(strict_types = 1);
2
3
namespace Suilven\FreeTextSearch\Tests;
4
5
use SilverStripe\Dev\SapphireTest;
6
use Suilven\FreeTextSearch\Index;
7
8
class IndexTest extends SapphireTest
9
{
10
    public function testSetGetName(): void
11
    {
12
        $index = new Index();
13
        $index->setName('testname');
14
        $this->assertEquals('testname', $index->getName());
15
    }
16
17
18
    public function testSetClass(): void
19
    {
20
        $index = new Index();
21
        $index->setClass('\Page');
22
        $this->assertEquals('\Page', $index->getClass());
23
    }
24
25
26
    public function testSetClassNull(): void
27
    {
28
        $index = new Index();
29
        $index->setClass(null);
30
        $this->assertNull($index->getClass());
0 ignored issues
show
Bug introduced by
Are you sure the usage of $index->getClass() targeting Suilven\FreeTextSearch\Index::getClass() 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...
31
    }
32
33
34
    public function testHasOneFields(): void
35
    {
36
        $index = new Index();
37
        $this->assertEquals([], $index->getHasOneFields());
38
        $index->addHasOneField('first');
39
        $this->assertEquals(['first'], $index->getHasOneFields());
40
        $index->addHasOneField('second');
41
        $this->assertEquals(['first', 'second'], $index->getHasOneFields());
42
        $index->addHasOneField('third');
43
        $this->assertEquals(['first', 'second', 'third'], $index->getHasOneFields());
44
        $index->addHasOneField('fourth');
45
        $this->assertEquals(['first', 'second', 'third', 'fourth'], $index->getHasOneFields());
46
    }
47
48
49
    public function testHasManyields(): void
50
    {
51
        $index = new Index();
52
        $this->assertEquals([], $index->getHasManyFields());
53
        $index->addHasManyField('first');
54
        $this->assertEquals(['first'], $index->getHasManyFields());
55
        $index->addHasManyField('second');
56
        $this->assertEquals(['first', 'second'], $index->getHasManyFields());
57
        $index->addHasManyField('third');
58
        $this->assertEquals(['first', 'second', 'third'], $index->getHasManyFields());
59
        $index->addHasManyField('fourth');
60
        $this->assertEquals(['first', 'second', 'third', 'fourth'], $index->getHasManyFields());
61
    }
62
63
64
    public function testAddTokens(): void
65
    {
66
        $index = new Index();
67
        $this->assertEquals([], $index->getTokens());
68
        $index->addToken('first');
69
        $this->assertEquals(['first'], $index->getTokens());
70
        $index->addToken('second');
71
        $this->assertEquals(['first', 'second'], $index->getTokens());
72
        $index->addToken('third');
73
        $this->assertEquals(['first', 'second', 'third'], $index->getTokens());
74
        $index->addToken('fourth');
75
        $this->assertEquals(['first', 'second', 'third', 'fourth'], $index->getTokens());
76
    }
77
78
79
    public function testAddFields(): void
80
    {
81
        $index = new Index();
82
        $this->assertEquals([], $index->getFields());
83
        $index->addField('first');
84
        $this->assertEquals(['first'], $index->getFields());
85
        $index->addField('second');
86
        $this->assertEquals(['first', 'second'], $index->getFields());
87
        $index->addField('third');
88
        $this->assertEquals(['first', 'second', 'third'], $index->getFields());
89
        $index->addField('fourth');
90
        $this->assertEquals(['first', 'second', 'third', 'fourth'], $index->getFields());
91
    }
92
}
93