1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace ElasticsearchDataProviderBundle\Command; |
4
|
|
|
|
5
|
|
|
use GBProd\ElasticsearchDataProviderBundle\Command\ProvidingProgressBar; |
6
|
|
|
use GBProd\ElasticsearchDataProviderBundle\DataProvider\DataProviderInterface; |
7
|
|
|
use GBProd\ElasticsearchDataProviderBundle\DataProvider\RegistryEntry; |
8
|
|
|
use GBProd\ElasticsearchDataProviderBundle\Event\HasFinishedProviding; |
9
|
|
|
use GBProd\ElasticsearchDataProviderBundle\Event\HasIndexedDocument; |
10
|
|
|
use GBProd\ElasticsearchDataProviderBundle\Event\HasStartedHandling; |
11
|
|
|
use GBProd\ElasticsearchDataProviderBundle\Event\HasStartedProviding; |
12
|
|
|
use Symfony\Component\Console\Helper\ProgressBar; |
13
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
14
|
|
|
use Symfony\Component\EventDispatcher\EventDispatcherInterface; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Tests for ProvidingProgressBar |
18
|
|
|
* |
19
|
|
|
* @author gbprod <[email protected]> |
20
|
|
|
*/ |
21
|
|
|
class ProvidingProgressBarTest extends \PHPUnit_Framework_TestCase |
22
|
|
|
{ |
23
|
|
|
private $testedInstance; |
24
|
|
|
private $dispatcher; |
25
|
|
|
private $output; |
|
|
|
|
26
|
|
|
|
27
|
|
|
public function setUp() |
28
|
|
|
{ |
29
|
|
|
$this->dispatcher = $this->getMock(EventDispatcherInterface::class); |
30
|
|
|
$this->output = $this->getMock(OutputInterface::class); |
31
|
|
|
|
32
|
|
|
$this->testedInstance = new ProvidingProgressBar( |
33
|
|
|
$this->dispatcher, |
34
|
|
|
$this->output |
35
|
|
|
); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
public function testOnStartedHandlingDisplayNumberOfEntries() |
39
|
|
|
{ |
40
|
|
|
$event = new HasStartedHandling([1, 2, 3]); |
|
|
|
|
41
|
|
|
|
42
|
|
|
$this |
43
|
|
|
->output |
44
|
|
|
->expects($this->once()) |
45
|
|
|
->method('writeln') |
46
|
|
|
->with( |
47
|
|
|
$this->stringContains('<comment>3</comment>') |
48
|
|
|
) |
49
|
|
|
; |
50
|
|
|
|
51
|
|
|
$this->testedInstance->onStartedHandling($event); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
public function testOnStartedProvidingDisplayProviderName() |
55
|
|
|
{ |
56
|
|
|
$provider = $this->getMock(DataProviderInterface::class); |
57
|
|
|
$entry = new RegistryEntry($provider, 'my_index', 'my_type'); |
58
|
|
|
|
59
|
|
|
$event = new HasStartedProviding($entry); |
60
|
|
|
|
61
|
|
|
$this |
62
|
|
|
->output |
63
|
|
|
->expects($this->once()) |
64
|
|
|
->method('writeln') |
65
|
|
|
->with($this->stringContains(get_class($provider))) |
66
|
|
|
; |
67
|
|
|
|
68
|
|
|
$this->testedInstance->onStartedProviding($event); |
69
|
|
|
|
70
|
|
|
$this->assertEmpty($this->testedInstance->progressBar); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
public function testOnStartedProvidingCreateProgressBar() |
74
|
|
|
{ |
75
|
|
|
$provider = $this->getMock(DataProviderInterface::class); |
76
|
|
|
$provider |
77
|
|
|
->expects($this->any()) |
78
|
|
|
->method('count') |
79
|
|
|
->willReturn(42) |
80
|
|
|
; |
81
|
|
|
|
82
|
|
|
$entry = new RegistryEntry($provider, 'my_index', 'my_type'); |
83
|
|
|
$event = new HasStartedProviding($entry); |
84
|
|
|
|
85
|
|
|
$this->testedInstance->onStartedProviding($event); |
86
|
|
|
|
87
|
|
|
$this->assertNotEmpty($this->testedInstance->progressBar); |
88
|
|
|
$this->assertInstanceOf( |
89
|
|
|
ProgressBar::class, |
90
|
|
|
$this->testedInstance->progressBar |
91
|
|
|
); |
92
|
|
|
$this->assertEquals(42, $this->testedInstance->progressBar->getMaxSteps()); |
93
|
|
|
} |
94
|
|
|
|
95
|
|
View Code Duplication |
public function testOnIndexedDocumentAdvanceProgress() |
|
|
|
|
96
|
|
|
{ |
97
|
|
|
$provider = $this->getMock(DataProviderInterface::class); |
98
|
|
|
$entry = new RegistryEntry($provider, 'my_index', 'my_type'); |
99
|
|
|
$event = new HasIndexedDocument($entry); |
|
|
|
|
100
|
|
|
|
101
|
|
|
$this->testedInstance->progressBar = $this |
102
|
|
|
->getMock(ProgressBar::class, [], [$this->output]) |
103
|
|
|
; |
104
|
|
|
|
105
|
|
|
$this->testedInstance |
106
|
|
|
->progressBar |
107
|
|
|
->expects($this->once()) |
108
|
|
|
->method('advance') |
109
|
|
|
; |
110
|
|
|
|
111
|
|
|
$this->testedInstance->onIndexedDocument($event); |
112
|
|
|
} |
113
|
|
|
|
114
|
|
View Code Duplication |
public function testOnFinishedProvidingFinishProgress() |
|
|
|
|
115
|
|
|
{ |
116
|
|
|
$provider = $this->getMock(DataProviderInterface::class); |
117
|
|
|
$entry = new RegistryEntry($provider, 'my_index', 'my_type'); |
118
|
|
|
$event = new HasFinishedProviding($entry); |
119
|
|
|
|
120
|
|
|
$this->testedInstance->progressBar = $this |
121
|
|
|
->getMock(ProgressBar::class, [], [$this->output]) |
122
|
|
|
; |
123
|
|
|
|
124
|
|
|
$this->testedInstance |
125
|
|
|
->progressBar |
126
|
|
|
->expects($this->once()) |
127
|
|
|
->method('finish') |
128
|
|
|
; |
129
|
|
|
|
130
|
|
|
$this->testedInstance->onFinishedProviding($event); |
131
|
|
|
|
132
|
|
|
$this->assertEmpty($this->testedInstance->progressBar); |
133
|
|
|
} |
134
|
|
|
} |
135
|
|
|
|