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\Command; |
13
|
|
|
|
14
|
|
|
use StingerSoft\EntitySearchBundle\Command\SyncCommand; |
15
|
|
|
use StingerSoft\EntitySearchBundle\Tests\Fixtures\ORM\Beer; |
16
|
|
|
use Symfony\Component\Console\Application; |
17
|
|
|
use Symfony\Component\Console\Tester\CommandTester; |
18
|
|
|
use Symfony\Component\DependencyInjection\Container; |
19
|
|
|
use StingerSoft\EntitySearchBundle\Tests\AbstractORMTestCase; |
20
|
|
|
use StingerSoft\EntitySearchBundle\Services\Mapping\EntityToDocumentMapperInterface; |
21
|
|
|
use StingerSoft\EntitySearchBundle\Services\Mapping\EntityToDocumentMapper; |
22
|
|
|
use StingerSoft\EntitySearchBundle\Services\DummySearchService; |
23
|
|
|
use StingerSoft\EntitySearchBundle\Services\SearchService; |
24
|
|
|
|
25
|
|
|
class SyncCommandTest extends AbstractORMTestCase { |
26
|
|
|
|
27
|
|
|
public function getRootDir() { |
28
|
|
|
return ''; |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
public function setUp() { |
32
|
|
|
parent::setUp(); |
33
|
|
|
$this->getMockSqliteEntityManager(); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* |
38
|
|
|
* @return CommandTester |
39
|
|
|
*/ |
40
|
|
|
protected function createCommander() { |
41
|
|
|
$that = $this; |
42
|
|
|
$container = $this->getMockBuilder(Container::class)->setMethods(array( |
43
|
|
|
'get' |
44
|
|
|
))->disableOriginalConstructor()->getMock(); |
45
|
|
|
|
46
|
|
|
$container->method('get')->willReturnCallback(function ($serviceId) use ($that) { |
47
|
|
|
switch($serviceId) { |
48
|
|
|
case 'kernel': |
49
|
|
|
return $that; |
50
|
|
|
case 'doctrine.orm.entity_manager': |
51
|
|
|
return $that->em; |
52
|
|
|
case EntityToDocumentMapperInterface::SERVICE_ID: |
53
|
|
|
return new EntityToDocumentMapper(new DummySearchService()); |
54
|
|
|
case SearchService::SERVICE_ID: |
55
|
|
|
return new DummySearchService(); |
56
|
|
|
} |
57
|
|
|
}); |
58
|
|
|
|
59
|
|
|
$syncCommand = new SyncCommand(); |
60
|
|
|
$syncCommand->setContainer($container); |
61
|
|
|
|
62
|
|
|
$application = new Application(); |
63
|
|
|
$application->add($syncCommand); |
64
|
|
|
|
65
|
|
|
$command = $application->find('stinger:search:sync'); |
66
|
|
|
$commandTester = new CommandTester($command); |
67
|
|
|
return $commandTester; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
public function testExecuteEmpty() { |
71
|
|
|
$commandTester = $this->createCommander(); |
72
|
|
|
|
73
|
|
|
$commandTester->execute(array( |
74
|
|
|
'command' => 'stinger:search:sync', |
75
|
|
|
'entity' => Beer::class |
76
|
|
|
)); |
77
|
|
|
|
78
|
|
|
$output = $commandTester->getDisplay(); |
79
|
|
|
$this->assertContains(Beer::class, $output); |
80
|
|
|
$this->assertContains('No entities found for indexing', $output); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
public function testExecuteNonEmpty() { |
84
|
|
|
$beer = new Beer(); |
85
|
|
|
$beer->setTitle('Grebhan\'s'); |
86
|
|
|
$this->em->persist($beer); |
87
|
|
|
$this->em->flush(); |
88
|
|
|
|
89
|
|
|
$commandTester = $this->createCommander(); |
90
|
|
|
|
91
|
|
|
$commandTester->execute(array( |
92
|
|
|
'command' => 'stinger:search:sync', |
93
|
|
|
'entity' => Beer::class |
94
|
|
|
)); |
95
|
|
|
|
96
|
|
|
$output = $commandTester->getDisplay(); |
97
|
|
|
$this->assertContains(Beer::class, $output); |
98
|
|
|
$this->assertContains('Indexed 1 entities', $output); |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* |
103
|
|
|
* {@inheritdoc} |
104
|
|
|
* |
105
|
|
|
* @see \StingerSoft\EntitySearchBundle\Tests\AbstractTestCase::getUsedEntityFixtures() |
106
|
|
|
*/ |
107
|
|
|
protected function getUsedEntityFixtures() { |
108
|
|
|
return array( |
109
|
|
|
Beer::class |
110
|
|
|
); |
111
|
|
|
} |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
|