1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the FOSElasticaBundle package. |
5
|
|
|
* |
6
|
|
|
* (c) FriendsOfSymfony <http://friendsofsymfony.github.com/> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* This file is part of the FOSElasticaBundle project. |
14
|
|
|
* |
15
|
|
|
* (c) Infinite Networks Pty Ltd <http://www.infinite.net.au> |
16
|
|
|
* |
17
|
|
|
* For the full copyright and license information, please view the LICENSE |
18
|
|
|
* file that was distributed with this source code. |
19
|
|
|
*/ |
20
|
|
|
|
21
|
|
|
namespace FOS\ElasticaBundle\Tests\Provider; |
22
|
|
|
|
23
|
|
|
use FOS\ElasticaBundle\Provider\Indexable; |
24
|
|
|
|
25
|
|
|
class IndexableTest extends \PHPUnit_Framework_TestCase |
26
|
|
|
{ |
27
|
|
View Code Duplication |
public function testIndexableUnknown() |
28
|
|
|
{ |
29
|
|
|
$indexable = new Indexable([]); |
30
|
|
|
$index = $indexable->isObjectIndexable('index', 'type', new Entity()); |
31
|
|
|
|
32
|
|
|
$this->assertTrue($index); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @dataProvider provideIsIndexableCallbacks |
37
|
|
|
*/ |
38
|
|
View Code Duplication |
public function testValidIndexableCallbacks($callback, $return) |
39
|
|
|
{ |
40
|
|
|
$indexable = new Indexable([ |
41
|
|
|
'index/type' => $callback, |
42
|
|
|
]); |
43
|
|
|
$index = $indexable->isObjectIndexable('index', 'type', new Entity()); |
44
|
|
|
|
45
|
|
|
$this->assertSame($return, $index); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* @dataProvider provideInvalidIsIndexableCallbacks |
50
|
|
|
* @expectedException \InvalidArgumentException |
51
|
|
|
*/ |
52
|
|
|
public function testInvalidIsIndexableCallbacks($callback) |
53
|
|
|
{ |
54
|
|
|
$indexable = new Indexable([ |
55
|
|
|
'index/type' => $callback, |
56
|
|
|
]); |
57
|
|
|
$indexable->isObjectIndexable('index', 'type', new Entity()); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
public function provideInvalidIsIndexableCallbacks() |
61
|
|
|
{ |
62
|
|
|
return [ |
63
|
|
|
['nonexistentEntityMethod'], |
64
|
|
|
[[new IndexableDecider(), 'internalMethod']], |
65
|
|
|
[42], |
66
|
|
|
['entity.getIsIndexable() && nonexistentEntityFunction()'], |
67
|
|
|
]; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
public function provideIsIndexableCallbacks() |
71
|
|
|
{ |
72
|
|
|
return [ |
73
|
|
|
['isIndexable', false], |
74
|
|
|
[[new IndexableDecider(), 'isIndexable'], true], |
75
|
|
|
[new IndexableDecider(), true], |
76
|
|
|
[function (Entity $entity) { |
77
|
|
|
return $entity->maybeIndex(); |
78
|
|
|
}, true], |
79
|
|
|
['entity.maybeIndex()', true], |
80
|
|
|
['!object.isIndexable() && entity.property == "abc"', true], |
81
|
|
|
['entity.property != "abc"', false], |
82
|
|
|
['["array", "values"]', true], |
83
|
|
|
['[]', false], |
84
|
|
|
]; |
85
|
|
|
} |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
class Entity |
89
|
|
|
{ |
90
|
|
|
public $property = 'abc'; |
91
|
|
|
|
92
|
|
|
public function isIndexable() |
93
|
|
|
{ |
94
|
|
|
return false; |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
public function maybeIndex() |
98
|
|
|
{ |
99
|
|
|
return true; |
100
|
|
|
} |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
class IndexableDecider |
104
|
|
|
{ |
105
|
|
|
public function __invoke($object) |
106
|
|
|
{ |
107
|
|
|
return true; |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
public function isIndexable(Entity $entity) |
111
|
|
|
{ |
112
|
|
|
return !$entity->isIndexable(); |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
protected function internalMethod() |
116
|
|
|
{ |
117
|
|
|
} |
118
|
|
|
} |
119
|
|
|
|