|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Tests\GBProd\ElasticsearchDataProviderBundle\Command; |
|
4
|
|
|
|
|
5
|
|
|
use Elasticsearch\Client; |
|
6
|
|
|
use GBProd\ElasticsearchDataProviderBundle\Command\ProvideCommand; |
|
7
|
|
|
use GBProd\ElasticsearchDataProviderBundle\DataProvider\Handler; |
|
8
|
|
|
use Symfony\Component\Console\Application; |
|
9
|
|
|
use Symfony\Component\Console\Tester\CommandTester; |
|
10
|
|
|
use Symfony\Component\DependencyInjection\Container; |
|
11
|
|
|
use Symfony\Component\EventDispatcher\EventDispatcherInterface; |
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* Tests for ProvideCommand |
|
15
|
|
|
* |
|
16
|
|
|
* @author gbprod <[email protected]> |
|
17
|
|
|
*/ |
|
18
|
|
|
class ProvideCommandTest extends \PHPUnit_Framework_TestCase |
|
19
|
|
|
{ |
|
20
|
|
|
private $commandTester; |
|
21
|
|
|
private $handler; |
|
22
|
|
|
private $client; |
|
23
|
|
|
|
|
24
|
|
|
public function setUp() |
|
25
|
|
|
{ |
|
26
|
|
|
$application = new Application(); |
|
27
|
|
|
$application->add(new ProvideCommand()); |
|
28
|
|
|
|
|
29
|
|
|
$command = $application->find('elasticsearch:provide'); |
|
30
|
|
|
$this->commandTester = new CommandTester($command); |
|
31
|
|
|
|
|
32
|
|
|
$this->handler = $this |
|
33
|
|
|
->getMockBuilder(Handler::class) |
|
34
|
|
|
->disableOriginalConstructor() |
|
35
|
|
|
->getMock() |
|
36
|
|
|
; |
|
37
|
|
|
|
|
38
|
|
|
$container = new Container(); |
|
39
|
|
|
|
|
40
|
|
|
$container->set( |
|
41
|
|
|
'gbprod.elasticsearch_dataprovider.handler', |
|
42
|
|
|
$this->handler |
|
43
|
|
|
); |
|
44
|
|
|
|
|
45
|
|
|
|
|
46
|
|
|
$container->set( |
|
47
|
|
|
'event_dispatcher', |
|
48
|
|
|
$this->getMock(EventDispatcherInterface::class) |
|
49
|
|
|
); |
|
50
|
|
|
|
|
51
|
|
|
$this->client = $this |
|
52
|
|
|
->getMockBuilder(Client::class) |
|
53
|
|
|
->disableOriginalConstructor() |
|
54
|
|
|
->getMock() |
|
55
|
|
|
; |
|
56
|
|
|
|
|
57
|
|
|
$container->set( |
|
58
|
|
|
'm6web_elasticsearch.client.default', |
|
59
|
|
|
$this->client |
|
60
|
|
|
); |
|
61
|
|
|
|
|
62
|
|
|
$command->setContainer($container); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
public function testExecute() |
|
66
|
|
|
{ |
|
67
|
|
|
$this->handler |
|
68
|
|
|
->expects($this->once()) |
|
69
|
|
|
->method('handle') |
|
70
|
|
|
->with($this->client, 'my_index', 'my_type') |
|
71
|
|
|
; |
|
72
|
|
|
|
|
73
|
|
|
$this->commandTester->execute([ |
|
74
|
|
|
'command' => 'elasticsearch:provide', |
|
75
|
|
|
'index' => 'my_index', |
|
76
|
|
|
'type' => 'my_type', |
|
77
|
|
|
]); |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
public function testExecuteThrowExceptionIfClientNotFound() |
|
81
|
|
|
{ |
|
82
|
|
|
$this->setExpectedException('\InvalidArgumentException'); |
|
83
|
|
|
|
|
84
|
|
|
$this->commandTester->execute([ |
|
85
|
|
|
'command' => 'elasticsearch:provide', |
|
86
|
|
|
'index' => 'my_index', |
|
87
|
|
|
'type' => 'my_type', |
|
88
|
|
|
'--client' => 'foo', |
|
89
|
|
|
]); |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
} |
|
93
|
|
|
|