1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Mdiyakov\DoctrineSolrBundle\Tests\Schema\Field\Entity; |
4
|
|
|
|
5
|
|
|
use Mdiyakov\DoctrineSolrBundle\Schema\Field\Entity\StringField; |
6
|
|
|
|
7
|
|
|
class StringObject |
8
|
|
|
{ |
9
|
|
|
private $value; |
10
|
|
|
|
11
|
|
|
public function __construct($value) |
12
|
|
|
{ |
13
|
|
|
$this->value = strval($value); |
14
|
|
|
} |
15
|
|
|
|
16
|
|
|
public function __toString() |
17
|
|
|
{ |
18
|
|
|
return $this->value; |
19
|
|
|
} |
20
|
|
|
} |
21
|
|
|
|
22
|
|
|
class StringFieldTest extends \PHPUnit_Framework_TestCase |
23
|
|
|
{ |
24
|
|
|
|
25
|
|
|
public function testGetDocumentValueForScalar() |
26
|
|
|
{ |
27
|
|
|
$string = 'string'; |
28
|
|
|
$int = 123; |
29
|
|
|
$bool = false; |
30
|
|
|
$null = null; |
31
|
|
|
|
32
|
|
|
$entity = new \stdClass(); |
33
|
|
|
$field = new StringField('title', 'd_title', false, 10, false); |
|
|
|
|
34
|
|
|
|
35
|
|
|
$entity->title = $string; |
36
|
|
|
$fieldValue = $field->getDocumentFieldValue($entity); |
37
|
|
|
$this->assertEquals($string, $fieldValue); |
38
|
|
|
|
39
|
|
|
$entity->title = $int; |
40
|
|
|
$fieldValue = $field->getDocumentFieldValue($entity); |
41
|
|
|
$this->assertEquals(strval($int) ,$fieldValue); |
42
|
|
|
|
43
|
|
|
$entity->title = $bool; |
44
|
|
|
$fieldValue = $field->getDocumentFieldValue($entity); |
45
|
|
|
$this->assertEquals(strval($bool) ,$fieldValue); |
46
|
|
|
|
47
|
|
|
$entity->title = $null; |
48
|
|
|
$fieldValue = $field->getDocumentFieldValue($entity); |
49
|
|
|
|
50
|
|
|
$this->assertEquals($null ,$fieldValue); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
public function testGetDocumentValueForObject() |
54
|
|
|
{ |
55
|
|
|
$value = 'value'; |
56
|
|
|
$object = new StringObject($value); |
57
|
|
|
|
58
|
|
|
$entity = new \stdClass(); |
59
|
|
|
$field = new StringField('title', 'd_title', false, 10, false); |
|
|
|
|
60
|
|
|
|
61
|
|
|
$entity->title = $object; |
62
|
|
|
$fieldValue = $field->getDocumentFieldValue($entity); |
63
|
|
|
$this->assertEquals($value, $fieldValue); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
public function testGetDocumentValueForArrayOfObjects() |
67
|
|
|
{ |
68
|
|
|
$value1 = 'value'; |
69
|
|
|
$value2 = 'value2'; |
70
|
|
|
|
71
|
|
|
$array = [new StringObject($value1), new StringObject($value2)]; |
72
|
|
|
|
73
|
|
|
$entity = new \stdClass(); |
74
|
|
|
$field = new StringField('title', 'd_title', false, 10, false); |
|
|
|
|
75
|
|
|
|
76
|
|
|
$entity->title = $array; |
77
|
|
|
$fieldValue = $field->getDocumentFieldValue($entity); |
78
|
|
|
$this->assertEquals(join(',', [$value1, $value2]), $fieldValue); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
|
82
|
|
|
public function testGetDocumentValueForMixedArray() |
83
|
|
|
{ |
84
|
|
|
$value1 = 'value'; |
85
|
|
|
$value2 = 'value2'; |
86
|
|
|
|
87
|
|
|
$array = [new StringObject($value1), $value2]; |
88
|
|
|
|
89
|
|
|
$entity = new \stdClass(); |
90
|
|
|
$field = new StringField('title', 'd_title', false, 10, false); |
|
|
|
|
91
|
|
|
|
92
|
|
|
$entity->title = $array; |
93
|
|
|
$fieldValue = $field->getDocumentFieldValue($entity); |
94
|
|
|
$this->assertEquals(join(',', [$value1, $value2]), $fieldValue); |
95
|
|
|
} |
96
|
|
|
} |