|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace SumoCoders\FrameworkSearchBundle\Tests\Entity; |
|
4
|
|
|
|
|
5
|
|
|
use SumoCoders\FrameworkSearchBundle\Entity\IndexItem; |
|
6
|
|
|
|
|
7
|
|
|
class IndexItemTest extends \PHPUnit_Framework_TestCase |
|
8
|
|
|
{ |
|
9
|
|
|
/** |
|
10
|
|
|
* @var SumoCoders\FrameworkSearchBundle\Entity\IndexItem |
|
11
|
|
|
*/ |
|
12
|
|
|
private $indexItem; |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* @var array |
|
16
|
|
|
*/ |
|
17
|
|
|
private $defaultData = array( |
|
18
|
|
|
'objectType' => 'User', |
|
19
|
|
|
'otherId' => 1, |
|
20
|
|
|
'field' => 'nickname', |
|
21
|
|
|
'value' => 'J. Doe', |
|
22
|
|
|
); |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* Test the getters and setters |
|
26
|
|
|
*/ |
|
27
|
|
|
public function testGettersAndSetters() |
|
28
|
|
|
{ |
|
29
|
|
|
$this->indexItem = new IndexItem( |
|
|
|
|
|
|
30
|
|
|
$this->defaultData['objectType'], |
|
31
|
|
|
$this->defaultData['otherId'], |
|
32
|
|
|
$this->defaultData['field'], |
|
33
|
|
|
$this->defaultData['value'] |
|
34
|
|
|
); |
|
35
|
|
|
|
|
36
|
|
|
$this->assertEquals($this->defaultData['objectType'], $this->indexItem->getObjectType()); |
|
37
|
|
|
$this->assertEquals($this->defaultData['otherId'], $this->indexItem->getOtherId()); |
|
38
|
|
|
$this->assertEquals($this->defaultData['field'], $this->indexItem->getField()); |
|
39
|
|
|
$this->assertEquals($this->defaultData['value'], $this->indexItem->getValue()); |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
public function testCreateMultipleObjectsBasedOnProperties() |
|
43
|
|
|
{ |
|
44
|
|
|
$properties = array( |
|
45
|
|
|
'name' => 'John', |
|
46
|
|
|
'surname' => 'Doe', |
|
47
|
|
|
'email' => '[email protected]', |
|
48
|
|
|
'nickname' => 'J. Doe', |
|
49
|
|
|
); |
|
50
|
|
|
|
|
51
|
|
|
$fakeObject = new \stdClass(); |
|
52
|
|
|
$fakeObject->name = 'John'; |
|
53
|
|
|
$fakeObject->surname = 'Doe'; |
|
54
|
|
|
$fakeObject->email = '[email protected]'; |
|
55
|
|
|
$fakeObject->nickname = 'J. Doe'; |
|
56
|
|
|
|
|
57
|
|
|
$indexItems = IndexItem::createMultipleObjectsBasedOnProperties( |
|
58
|
|
|
$this->defaultData['objectType'], |
|
59
|
|
|
$this->defaultData['otherId'], |
|
60
|
|
|
array_keys($properties), |
|
61
|
|
|
$fakeObject |
|
62
|
|
|
); |
|
63
|
|
|
|
|
64
|
|
|
foreach ($indexItems as $index) { |
|
65
|
|
|
/** @var SumoCoders\FrameworkSearchBundle\Entity\IndexItem $index*/ |
|
66
|
|
|
$this->assertInstanceOf('\SumoCoders\FrameworkSearchBundle\Entity\IndexItem', $index); |
|
67
|
|
|
$this->assertEquals($properties[$index->getField()], $index->getValue()); |
|
68
|
|
|
} |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
public function testCreateMultipleObjectsBasedOnPropertiesFromObject() |
|
72
|
|
|
{ |
|
73
|
|
|
$properties = array( |
|
74
|
|
|
'name' => 'John', |
|
75
|
|
|
'surname' => 'Doe', |
|
76
|
|
|
); |
|
77
|
|
|
$object = new Person('John', 'Doe'); |
|
78
|
|
|
|
|
79
|
|
|
$indexItems = IndexItem::createMultipleObjectsBasedOnProperties( |
|
80
|
|
|
$this->defaultData['objectType'], |
|
81
|
|
|
$this->defaultData['otherId'], |
|
82
|
|
|
array_keys($properties), |
|
83
|
|
|
$object |
|
84
|
|
|
); |
|
85
|
|
|
|
|
86
|
|
|
foreach ($indexItems as $index) { |
|
87
|
|
|
/** @var SumoCoders\FrameworkSearchBundle\Entity\IndexItem $index*/ |
|
88
|
|
|
$this->assertInstanceOf('\SumoCoders\FrameworkSearchBundle\Entity\IndexItem', $index); |
|
89
|
|
|
$this->assertEquals($properties[$index->getField()], $index->getValue()); |
|
90
|
|
|
} |
|
91
|
|
|
} |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
/** |
|
95
|
|
|
* Test class to test building an index item from a real object |
|
96
|
|
|
*/ |
|
97
|
|
|
final class Person |
|
|
|
|
|
|
98
|
|
|
{ |
|
99
|
|
|
private $name; |
|
100
|
|
|
private $surname; |
|
101
|
|
|
|
|
102
|
|
|
public function __construct($name, $surname) |
|
103
|
|
|
{ |
|
104
|
|
|
$this->name = $name; |
|
105
|
|
|
$this->surname = $surname; |
|
106
|
|
|
} |
|
107
|
|
|
|
|
108
|
|
|
public function getName() |
|
109
|
|
|
{ |
|
110
|
|
|
return $this->name; |
|
111
|
|
|
} |
|
112
|
|
|
|
|
113
|
|
|
public function getSurname() |
|
114
|
|
|
{ |
|
115
|
|
|
return $this->surname; |
|
116
|
|
|
} |
|
117
|
|
|
} |
|
118
|
|
|
|
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..