ArrayFieldTest   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 70
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 4
dl 0
loc 70
c 0
b 0
f 0
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A testGetDocumentValueForArray() 0 10 1
A testGetDocumentValueForIterator() 0 12 1
A testGetDocumentValueForIteratorAggregate() 0 12 1
A testGetDocumentValueForScalar() 0 25 1
1
<?php
2
3
namespace Mdiyakov\DoctrineSolrBundle\Tests\Schema\Field\Entity;
4
5
use Mdiyakov\DoctrineSolrBundle\Schema\Field\Entity\ArrayField;
6
7
8
class ArrayFieldTest extends \PHPUnit_Framework_TestCase
9
{
10
11
    public function testGetDocumentValueForScalar()
12
    {
13
        $string = 'string';
14
        $int = 123;
15
        $bool = false;
16
        $null = null;
17
18
        $entity = new \stdClass();
19
        $field = new ArrayField('tags', 'd_tags', false, 10, false);
0 ignored issues
show
Bug introduced by
false of type false is incompatible with the type string expected by parameter $suggester of Mdiyakov\DoctrineSolrBun...rayField::__construct(). ( Ignorable by Annotation )

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

19
        $field = new ArrayField('tags', 'd_tags', false, 10, /** @scrutinizer ignore-type */ false);
Loading history...
20
21
        $entity->tags = $string;
22
        $fieldValue = $field->getDocumentFieldValue($entity);
23
        $this->assertEquals([$string] ,$fieldValue);
24
25
        $entity->tags = $int;
26
        $fieldValue = $field->getDocumentFieldValue($entity);
27
        $this->assertEquals([$int] ,$fieldValue);
28
29
        $entity->tags = $bool;
30
        $fieldValue = $field->getDocumentFieldValue($entity);
31
        $this->assertEquals([$bool] ,$fieldValue);
32
33
        $entity->tags = $null;
34
        $fieldValue = $field->getDocumentFieldValue($entity);
35
        $this->assertEquals([] ,$fieldValue);
36
    }
37
38
39
    public function testGetDocumentValueForArray()
40
    {
41
        $array = [1,'string', false];
42
43
        $entity = new \stdClass();
44
        $field = new ArrayField('tags', 'd_tags', false, 10, false);
0 ignored issues
show
Bug introduced by
false of type false is incompatible with the type string expected by parameter $suggester of Mdiyakov\DoctrineSolrBun...rayField::__construct(). ( Ignorable by Annotation )

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

44
        $field = new ArrayField('tags', 'd_tags', false, 10, /** @scrutinizer ignore-type */ false);
Loading history...
45
46
        $entity->tags = $array;
47
        $fieldValue = $field->getDocumentFieldValue($entity);
48
        $this->assertEquals($array ,$fieldValue);
49
    }
50
51
52
    public function testGetDocumentValueForIterator()
53
    {
54
        $array = [1,3,4,4,5,6,9];
55
        $iterator = new \ArrayIterator($array);
56
57
        $entity = new \stdClass();
58
        $field = new ArrayField('tags', 'd_tags', false, 10, false);
0 ignored issues
show
Bug introduced by
false of type false is incompatible with the type string expected by parameter $suggester of Mdiyakov\DoctrineSolrBun...rayField::__construct(). ( Ignorable by Annotation )

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

58
        $field = new ArrayField('tags', 'd_tags', false, 10, /** @scrutinizer ignore-type */ false);
Loading history...
59
60
        $entity->tags = $iterator;
61
        $fieldValue = $field->getDocumentFieldValue($entity);
62
63
        $this->assertEquals($array ,$fieldValue);
64
    }
65
66
    public function testGetDocumentValueForIteratorAggregate()
67
    {
68
        $array = [1,3,4,4,5,6,9];
69
        $arrayObject = new \ArrayObject($array);
70
71
        $entity = new \stdClass();
72
        $field = new ArrayField('tags', 'd_tags', false, 10, false);
0 ignored issues
show
Bug introduced by
false of type false is incompatible with the type string expected by parameter $suggester of Mdiyakov\DoctrineSolrBun...rayField::__construct(). ( Ignorable by Annotation )

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

72
        $field = new ArrayField('tags', 'd_tags', false, 10, /** @scrutinizer ignore-type */ false);
Loading history...
73
74
        $entity->tags = $arrayObject;
75
        $fieldValue = $field->getDocumentFieldValue($entity);
76
77
        $this->assertEquals($array ,$fieldValue);
78
    }
79
}