|
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); |
|
|
|
|
|
|
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); |
|
|
|
|
|
|
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); |
|
|
|
|
|
|
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); |
|
|
|
|
|
|
73
|
|
|
|
|
74
|
|
|
$entity->tags = $arrayObject; |
|
75
|
|
|
$fieldValue = $field->getDocumentFieldValue($entity); |
|
76
|
|
|
|
|
77
|
|
|
$this->assertEquals($array ,$fieldValue); |
|
78
|
|
|
} |
|
79
|
|
|
} |