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\Services\DummySearchService; |
15
|
|
|
use StingerSoft\EntitySearchBundle\Tests\AbstractORMTestCase; |
16
|
|
|
use StingerSoft\EntitySearchBundle\Tests\Fixtures\ORM\Beer; |
17
|
|
|
use StingerSoft\EntitySearchBundle\Tests\Fixtures\ORM\Car; |
18
|
|
|
use StingerSoft\EntitySearchBundle\Services\SearchService; |
19
|
|
|
use StingerSoft\EntitySearchBundle\Model\Query; |
20
|
|
|
|
21
|
|
|
class DummySearchServiceTest 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
|
|
|
/** |
35
|
|
|
* |
36
|
|
|
* @return \StingerSoft\EntitySearchBundle\Services\DummySearchService |
37
|
|
|
*/ |
38
|
|
|
protected function getSearchService() { |
39
|
|
|
$service = new DummySearchService(); |
40
|
|
|
$service->setObjectManager($this->em); |
41
|
|
|
return $service; |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
protected function indexBeer(SearchService $service) { |
45
|
|
|
$beer = new Beer(); |
46
|
|
|
$beer->setTitle('Hemelinger'); |
47
|
|
|
$this->em->persist($beer); |
48
|
|
|
$this->em->flush(); |
49
|
|
|
|
50
|
|
|
$document = $service->createEmptyDocumentFromEntity($beer); |
51
|
|
|
$this->assertAttributeCount(0, 'index', $service); |
52
|
|
|
$beer->indexEntity($document); |
53
|
|
|
$service->saveDocument($document); |
54
|
|
|
$this->assertAttributeCount(1, 'index', $service); |
55
|
|
|
return array($beer, $document); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
public function testSaveDocument() { |
59
|
|
|
$service = $this->getSearchService(); |
60
|
|
|
$this->indexBeer($service); |
61
|
|
|
$service->clearIndex(); |
62
|
|
|
$this->assertAttributeCount(0, 'index', $service); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
public function testSaveDocumentComposite() { |
66
|
|
|
$car = new Car('S500', 2016); |
67
|
|
|
$this->em->persist($car); |
68
|
|
|
$this->em->flush(); |
69
|
|
|
|
70
|
|
|
$service = $this->getSearchService(); |
71
|
|
|
$document = $service->createEmptyDocumentFromEntity($car); |
72
|
|
|
$this->assertAttributeCount(0, 'index', $service); |
73
|
|
|
$service->saveDocument($document); |
74
|
|
|
|
75
|
|
|
$this->assertAttributeCount(1, 'index', $service); |
76
|
|
|
|
77
|
|
|
$service->clearIndex(); |
78
|
|
|
$this->assertAttributeCount(0, 'index', $service); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
public function testRemoveDocument() { |
82
|
|
|
$service = $this->getSearchService(); |
83
|
|
|
$result = $this->indexBeer($service); |
84
|
|
|
|
85
|
|
|
$service->removeDocument($result[1]); |
86
|
|
|
$this->assertAttributeCount(0, 'index', $service); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
public function testAutocompletion() { |
90
|
|
|
$service = $this->getSearchService(); |
91
|
|
|
$result = $this->indexBeer($service); |
92
|
|
|
|
93
|
|
|
$suggests = $service->autocomplete('He'); |
94
|
|
|
$this->count(1, $suggests); |
|
|
|
|
95
|
|
|
$this->assertContains($result[0]->getTitle(), $suggests); |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
public function testSearch() { |
99
|
|
|
$service = $this->getSearchService(); |
100
|
|
|
$this->indexBeer($service); |
101
|
|
|
$service->search($this->getMockBuilder(Query::class)->getMockForAbstractClass()); |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* |
106
|
|
|
* {@inheritDoc} |
107
|
|
|
* |
108
|
|
|
* @see \StingerSoft\EntitySearchBundle\Tests\AbstractTestCase::getUsedEntityFixtures() |
109
|
|
|
*/ |
110
|
|
|
protected function getUsedEntityFixtures() { |
111
|
|
|
return array( |
112
|
|
|
Beer::class, |
113
|
|
|
Car::class |
114
|
|
|
); |
115
|
|
|
} |
116
|
|
|
} |
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.
In this case you can add the
@ignore
PhpDoc annotation to the duplicate definition and it will be ignored.