IndexerFactoryTest::testFactory()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 33
Code Lines 21

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 21
c 1
b 0
f 0
dl 0
loc 33
rs 9.584
cc 1
nc 1
nop 0
1
<?php declare(strict_types = 1);
2
3
namespace Suilven\FreeTextSearch\Tests\Factory;
4
5
use SilverStripe\CMS\Model\SiteTree;
6
use SilverStripe\Dev\SapphireTest;
7
use Suilven\FreeTextSearch\Factory\IndexerFactory;
8
use Suilven\FreeTextSearch\Tests\Mock\Indexer;
9
10
class IndexerFactoryTest extends SapphireTest
11
{
12
    protected static $fixture_file = ['tests/fixtures/sitetree.yml'];
13
14
    public function testFactory(): void
15
    {
16
        Indexer::resetIndexedPayload();
17
18
        $factory = new IndexerFactory();
19
20
        /** @var \Suilven\FreeTextSearch\Tests\Mock\Indexer $indexer */
21
        $indexer = $factory->getIndexer();
22
        $this->assertInstanceOf('Suilven\FreeTextSearch\Interfaces\Indexer', $indexer);
23
        $this->assertInstanceOf('Suilven\FreeTextSearch\Tests\Mock\Indexer', $indexer);
24
25
        $indexer->setIndexName('sitetree');
26
        $page = $this->objFromFixture(SiteTree::class, 'sitetree_20');
27
        $indexer->index($page);
28
29
        // the mock stores the indexed content.  Firstly check that members and flickrphotos have no updates
30
        $allDocumentsPayload = Indexer::getIndexedPayload();
31
        $this->assertEquals(1, \sizeof($allDocumentsPayload));
0 ignored issues
show
Bug introduced by
It seems like $allDocumentsPayload can also be of type null; however, parameter $value of sizeof() does only seem to accept Countable|array, maybe add an additional type check? ( Ignorable by Annotation )

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

31
        $this->assertEquals(1, \sizeof(/** @scrutinizer ignore-type */ $allDocumentsPayload));
Loading history...
32
        $indexedDocumentPayload = $allDocumentsPayload[0];
33
34
        $this->assertEquals([], $indexedDocumentPayload['members']);
35
        $this->assertEquals([], $indexedDocumentPayload['flickrphotos']);
36
37
        // check non timestamped data for the page in question
38
        $siteTreePayload = $indexedDocumentPayload['sitetree'];
39
        $this->assertEquals('The None In San Marino Is Full', $siteTreePayload['Title']);
40
        $this->assertEquals('The None In San Marino Is Full', $siteTreePayload['MenuTitle']);
41
        $this->assertEquals(
42
            'Ella opened the good and found that it led into a big close, not much larger than a might.',
43
            $siteTreePayload['Content']
44
        );
45
        $this->assertEquals(21, $siteTreePayload['Sort']);
46
        $this->assertEquals(0, $siteTreePayload['ParentID']);
47
    }
48
}
49