|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the Stinger Entity 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 Doctrine\Common\Persistence\AbstractManagerRegistry; |
|
15
|
|
|
use StingerSoft\EntitySearchBundle\Services\Mapping\DocumentToEntityMapper; |
|
16
|
|
|
use StingerSoft\EntitySearchBundle\Tests\AbstractORMTestCase; |
|
17
|
|
|
use StingerSoft\EntitySearchBundle\Tests\Fixtures\ORM\Beer; |
|
18
|
|
|
use StingerSoft\EntitySearchBundle\Tests\Fixtures\ORM\Potato; |
|
19
|
|
|
use StingerSoft\EntitySearchBundle\Tests\Fixtures\ORM\Whiskey; |
|
20
|
|
|
use StingerSoft\EntitySearchBundle\Model\Document; |
|
21
|
|
|
|
|
22
|
|
|
class DocumentToEntityMapperTest extends AbstractORMTestCase { |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* |
|
26
|
|
|
* {@inheritDoc} |
|
27
|
|
|
* |
|
28
|
|
|
* @see PHPUnit_Framework_TestCase::setUp() |
|
29
|
|
|
*/ |
|
30
|
|
|
public function setUp() { |
|
31
|
|
|
parent::setUp(); |
|
32
|
|
|
$this->getMockSqliteEntityManager(); |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* |
|
37
|
|
|
* @return \StingerSoft\EntitySearchBundle\Services\Mapping\DocumentToEntityMapper |
|
38
|
|
|
*/ |
|
39
|
|
|
protected function getDocumentToEntityMapper() { |
|
40
|
|
|
$managerMock = $this->getMockBuilder(AbstractManagerRegistry::class)->setMethods(array( |
|
41
|
|
|
'getManagerForClass' |
|
42
|
|
|
))->disableOriginalConstructor()->getMockForAbstractClass(); |
|
43
|
|
|
$managerMock->expects($this->once())->method('getManagerForClass')->will($this->returnValue($this->em)); |
|
44
|
|
|
$eh = new DocumentToEntityMapper($managerMock); |
|
45
|
|
|
return $eh; |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
public function testGetEntity() { |
|
49
|
|
|
$beer = new Beer(); |
|
50
|
|
|
$beer->setTitle('Hemelinger'); |
|
51
|
|
|
$this->em->persist($beer); |
|
52
|
|
|
$this->em->flush(); |
|
53
|
|
|
|
|
54
|
|
|
$document = $this->getMockBuilder(Document::class)->setMethods(array( |
|
55
|
|
|
'getEntityClass', |
|
56
|
|
|
'getEntityId', |
|
57
|
|
|
))->getMockForAbstractClass(); |
|
58
|
|
|
$document->expects($this->once())->method('getEntityClass')->will($this->returnValue(Beer::class)); |
|
59
|
|
|
$document->expects($this->once())->method('getEntityId')->will($this->returnValue($beer->getId())); |
|
60
|
|
|
|
|
61
|
|
|
$eh = $this->getDocumentToEntityMapper(); |
|
62
|
|
|
|
|
63
|
|
|
$entity = $eh->getEntity($document); |
|
64
|
|
|
$this->assertEquals($beer, $entity); |
|
65
|
|
|
|
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
/** |
|
69
|
|
|
* |
|
70
|
|
|
* {@inheritDoc} |
|
71
|
|
|
* |
|
72
|
|
|
* @see \StingerSoft\EntitySearchBundle\Tests\AbstractTestCase::getUsedEntityFixtures() |
|
73
|
|
|
*/ |
|
74
|
|
|
protected function getUsedEntityFixtures() { |
|
75
|
|
|
return array( |
|
76
|
|
|
Beer::class |
|
77
|
|
|
); |
|
78
|
|
|
} |
|
79
|
|
|
} |