1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the Stinger Enity Search package. |
5
|
|
|
* |
6
|
|
|
* (c) Oliver Kotte <[email protected]> |
7
|
|
|
* (c) Florian Meyer <[email protected]> |
8
|
|
|
* |
9
|
|
|
* For the full copyright and license information, please view the LICENSE |
10
|
|
|
* file that was distributed with this source code. |
11
|
|
|
*/ |
12
|
|
|
namespace StingerSoft\EntitySearchBundle\Tests\Services; |
13
|
|
|
|
14
|
|
|
use StingerSoft\EntitySearchBundle\Model\Document; |
15
|
|
|
use StingerSoft\EntitySearchBundle\Services\AbstractSearchService; |
16
|
|
|
use StingerSoft\EntitySearchBundle\Services\DummySearchService; |
17
|
|
|
use StingerSoft\EntitySearchBundle\Services\Mapping\EntityToDocumentMapper; |
18
|
|
|
use StingerSoft\EntitySearchBundle\Tests\AbstractORMTestCase; |
19
|
|
|
use StingerSoft\EntitySearchBundle\Tests\DependencyInjection\StingerSoftEntitySearchExtensionTest; |
20
|
|
|
use StingerSoft\EntitySearchBundle\Tests\Fixtures\ORM\Beer; |
21
|
|
|
use StingerSoft\EntitySearchBundle\Tests\Fixtures\ORM\Potato; |
22
|
|
|
use StingerSoft\EntitySearchBundle\Tests\Fixtures\ORM\Whiskey; |
23
|
|
|
|
24
|
|
|
class EntityToDocumentMapperTest extends AbstractORMTestCase { |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* |
28
|
|
|
* {@inheritDoc} |
29
|
|
|
* |
30
|
|
|
* @see PHPUnit_Framework_TestCase::setUp() |
31
|
|
|
*/ |
32
|
|
|
public function setUp() { |
33
|
|
|
parent::setUp(); |
34
|
|
|
$this->getMockSqliteEntityManager(); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* |
39
|
|
|
* @return \StingerSoft\EntitySearchBundle\Services\EntityToDocumentMapper |
40
|
|
|
*/ |
41
|
|
|
protected function getEntityToDocumentMapper() { |
42
|
|
|
$eh = new EntityToDocumentMapper(new DummySearchService(), StingerSoftEntitySearchExtensionTest::$mockConfiguration['stinger_soft.entity_search']['types']); |
43
|
|
|
return $eh; |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @expectedException \InvalidArgumentException |
48
|
|
|
*/ |
49
|
|
|
public function testFuckedUpConfiguration() { |
50
|
|
|
$searchService = $this->getMockBuilder(AbstractSearchService::class)->getMockForAbstractClass(); |
51
|
|
|
new EntityToDocumentMapper($searchService, array( |
52
|
|
|
'beer' => array() |
53
|
|
|
)); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* @expectedException \InvalidArgumentException |
58
|
|
|
*/ |
59
|
|
|
public function testFuckedUpConfigurationWithoutMapping() { |
60
|
|
|
$searchService = $this->getMockBuilder(AbstractSearchService::class)->getMockForAbstractClass(); |
61
|
|
|
new EntityToDocumentMapper($searchService, array( |
62
|
|
|
'beer' => array( |
63
|
|
|
'persistance' => array( |
64
|
|
|
'model' => Beer::class |
65
|
|
|
) |
66
|
|
|
) |
67
|
|
|
)); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* @expectedException \InvalidArgumentException |
72
|
|
|
*/ |
73
|
|
|
public function testFuckedUpConfigurationWithoutModel() { |
74
|
|
|
$searchService = $this->getMockBuilder(AbstractSearchService::class)->getMockForAbstractClass(); |
75
|
|
|
new EntityToDocumentMapper($searchService, array( |
76
|
|
|
'beer' => array( |
77
|
|
|
'persistance' => array() |
78
|
|
|
) |
79
|
|
|
)); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* @expectedException \InvalidArgumentException |
84
|
|
|
*/ |
85
|
|
|
public function testFuckedUpConfigurationWithoutPersistance() { |
86
|
|
|
$searchService = $this->getMockBuilder(AbstractSearchService::class)->getMockForAbstractClass(); |
87
|
|
|
new EntityToDocumentMapper($searchService, array( |
88
|
|
|
'beer' => array( |
89
|
|
|
'mapping' => array( |
90
|
|
|
'title' => array( |
91
|
|
|
'propertyPath' => false |
92
|
|
|
) |
93
|
|
|
) |
94
|
|
|
) |
95
|
|
|
)); |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
public function testIsIndexable() { |
99
|
|
|
$eh = $this->getEntityToDocumentMapper(); |
100
|
|
|
$this->assertTrue($eh->isIndexable(new Beer())); |
101
|
|
|
$this->assertFalse($eh->isIndexable(new Potato())); |
102
|
|
|
$this->assertTrue($eh->isIndexable(new Whiskey())); |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
public function testCreateDocument() { |
106
|
|
|
$eh = $this->getEntityToDocumentMapper(); |
107
|
|
|
|
108
|
|
|
$beer = new Beer(); |
109
|
|
|
$beer->setTitle('Hemelinger'); |
110
|
|
|
$this->em->persist($beer); |
111
|
|
|
$this->em->flush(); |
112
|
|
|
$document = $eh->createDocument($this->em, $beer); |
113
|
|
|
$this->assertInstanceOf(Document::class, $document); |
114
|
|
|
$this->assertEquals('Hemelinger', $document->getFieldValue(Document::FIELD_TITLE)); |
115
|
|
|
|
116
|
|
|
$whiskey = new Whiskey(); |
117
|
|
|
$whiskey->setTitle('Laphroaig'); |
118
|
|
|
$this->em->persist($whiskey); |
119
|
|
|
$this->em->flush(); |
120
|
|
|
$document = $eh->createDocument($this->em, $whiskey); |
121
|
|
|
$this->assertInstanceOf(Document::class, $document); |
122
|
|
|
$this->assertEquals('Laphroaig', $document->getFieldValue(Document::FIELD_TITLE)); |
123
|
|
|
|
124
|
|
|
$potato = new Potato(); |
125
|
|
|
$potato->setTitle('Erna'); |
126
|
|
|
$this->em->persist($potato); |
127
|
|
|
$this->em->flush(); |
128
|
|
|
$document = $eh->createDocument($this->em, $potato); |
129
|
|
|
$this->assertFalse($document); |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
/** |
133
|
|
|
* |
134
|
|
|
* {@inheritDoc} |
135
|
|
|
* |
136
|
|
|
* @see \StingerSoft\EntitySearchBundle\Tests\AbstractTestCase::getUsedEntityFixtures() |
137
|
|
|
*/ |
138
|
|
|
protected function getUsedEntityFixtures() { |
139
|
|
|
return array( |
140
|
|
|
Beer::class, |
141
|
|
|
Potato::class, |
142
|
|
|
Whiskey::class |
143
|
|
|
); |
144
|
|
|
} |
145
|
|
|
} |