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\Tests\AbstractORMTestCase; |
15
|
|
|
use StingerSoft\EntitySearchBundle\Tests\Fixtures\ORM\Beer; |
16
|
|
|
use StingerSoft\EntitySearchBundle\Services\AbstractSearchService; |
17
|
|
|
use Doctrine\Common\Persistence\ObjectManager; |
18
|
|
|
use StingerSoft\EntitySearchBundle\Model\Document; |
19
|
|
|
use StingerSoft\EntitySearchBundle\Tests\Fixtures\ORM\Car; |
20
|
|
|
|
21
|
|
|
class AbstractSearchServiceTest extends AbstractORMTestCase { |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* |
25
|
|
|
* {@inheritDoc} |
26
|
|
|
* |
27
|
|
|
* @see PHPUnit_Framework_TestCase::setUp() |
28
|
|
|
*/ |
29
|
|
|
public function setUp() { |
30
|
|
|
parent::setUp(); |
31
|
|
|
$this->getMockSqliteEntityManager(); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
public function testSetObjectManager() { |
35
|
|
|
/** |
36
|
|
|
* |
37
|
|
|
* @var AbstractSearchService $service |
38
|
|
|
*/ |
39
|
|
|
$service = $this->getMockBuilder(AbstractSearchService::class)->getMockForAbstractClass(); |
40
|
|
|
$this->assertNotNull($this->em); |
41
|
|
|
$service->setObjectManager($this->em); |
42
|
|
|
$this->assertNotNull($service->getObjectManager()); |
43
|
|
|
$this->assertInstanceOf(ObjectManager::class, $service->getObjectManager()); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
public function testCreateEmptyDocumentFromEntity() { |
47
|
|
|
$beer = new Beer(); |
48
|
|
|
$beer->setTitle('Hemelinger'); |
49
|
|
|
$this->em->persist($beer); |
50
|
|
|
$this->em->flush(); |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* |
54
|
|
|
* @var AbstractSearchService $service |
55
|
|
|
*/ |
56
|
|
|
$service = $this->getMockBuilder(AbstractSearchService::class)->getMockForAbstractClass(); |
57
|
|
|
$service->setObjectManager($this->em); |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* |
61
|
|
|
* @var Document $doc |
62
|
|
|
*/ |
63
|
|
|
$doc = $service->createEmptyDocumentFromEntity($beer); |
64
|
|
|
$this->assertNotNull($doc); |
65
|
|
|
$this->assertInstanceOf(Document::class, $doc); |
66
|
|
|
$this->assertEquals($beer->getId(), $doc->getEntityId()); |
67
|
|
|
$this->assertEquals(Beer::class, $doc->getEntityClass()); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
public function testCreateEmptyDocumentFromCompositeEntity() { |
71
|
|
|
$car = new Car('S500', 2016); |
72
|
|
|
$this->em->persist($car); |
73
|
|
|
$this->em->flush(); |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* |
77
|
|
|
* @var AbstractSearchService $service |
78
|
|
|
*/ |
79
|
|
|
$service = $this->getMockBuilder(AbstractSearchService::class)->getMockForAbstractClass(); |
80
|
|
|
$service->setObjectManager($this->em); |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* |
84
|
|
|
* @var Document $doc |
85
|
|
|
*/ |
86
|
|
|
$doc = $service->createEmptyDocumentFromEntity($car); |
87
|
|
|
$this->assertNotNull($doc); |
88
|
|
|
$this->assertInstanceOf(Document::class, $doc); |
89
|
|
|
$this->assertInternalType('array', $doc->getEntityId()); |
90
|
|
|
$this->assertCount(2, $doc->getEntityId()); |
91
|
|
|
$this->assertEquals(Car::class, $doc->getEntityClass()); |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* |
96
|
|
|
* {@inheritDoc} |
97
|
|
|
* |
98
|
|
|
* @see \StingerSoft\EntitySearchBundle\Tests\AbstractTestCase::getUsedEntityFixtures() |
99
|
|
|
*/ |
100
|
|
|
protected function getUsedEntityFixtures() { |
101
|
|
|
return array( |
102
|
|
|
Beer::class, |
103
|
|
|
Car::class |
104
|
|
|
); |
105
|
|
|
} |
106
|
|
|
} |