Completed
Push — master ( 0f71cc...99d0b0 )
by Karel
15:42
created

CreateCommandTest::setUp()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 16
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 16
rs 9.4285
cc 1
eloc 12
nc 1
nop 0
1
<?php
2
3
/*
4
 * This file is part of the FOSElasticaBundle package.
5
 *
6
 * (c) FriendsOfSymfony <http://friendsofsymfony.github.com/>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace FOS\ElasticaBundle\Tests\Command;
13
14
use FOS\ElasticaBundle\Command\CreateCommand;
15
use FOS\ElasticaBundle\Configuration\ConfigManager;
16
use FOS\ElasticaBundle\Configuration\IndexConfig;
17
use FOS\ElasticaBundle\Elastica\Index;
18
use FOS\ElasticaBundle\Index\AliasProcessor;
19
use FOS\ElasticaBundle\Index\IndexManager;
20
use FOS\ElasticaBundle\Index\MappingBuilder;
21
use PHPUnit\Framework\TestCase;
22
use Symfony\Component\Console\Input\InputInterface;
23
use Symfony\Component\Console\Output\OutputInterface;
24
25
/**
26
 * @author Oleg Andreyev <[email protected]>
27
 */
28
class CreateCommandTest extends TestCase
29
{
30
    /**
31
     * @var IndexManager|\PHPUnit_Framework_MockObject_MockObject
32
     */
33
    private $indexManager;
34
35
    /**
36
     * @var MappingBuilder|\PHPUnit_Framework_MockObject_MockObject
37
     */
38
    private $mappingBuilder;
39
40
    /**
41
     * @var ConfigManager|\PHPUnit_Framework_MockObject_MockObject
42
     */
43
    private $configManager;
44
45
    /**
46
     * @var AliasProcessor|\PHPUnit_Framework_MockObject_MockObject
47
     */
48
    private $aliasProcessor;
49
50
    /**
51
     * @var CreateCommand
52
     */
53
    private $command;
54
55
    /**
56
     * @var IndexConfig|\PHPUnit_Framework_MockObject_MockObject
57
     */
58
    private $indexConfig;
59
60
    /**
61
     * @var Index|\PHPUnit_Framework_MockObject_MockObject
62
     */
63
    private $index;
64
65
    protected function setUp()
66
    {
67
        $this->indexManager = $this->createMock(IndexManager::class);
68
        $this->mappingBuilder = $this->createMock(MappingBuilder::class);
69
        $this->configManager = $this->createMock(ConfigManager::class);
70
        $this->aliasProcessor = $this->createMock(AliasProcessor::class);
71
        $this->indexConfig = $this->createMock(IndexConfig::class);
72
        $this->index = $this->createMock(Index::class);
73
74
        $this->command = new CreateCommand(
75
            $this->indexManager,
0 ignored issues
show
Documentation introduced by
$this->indexManager is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<FOS\ElasticaBundle\Index\IndexManager>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
76
            $this->mappingBuilder,
0 ignored issues
show
Documentation introduced by
$this->mappingBuilder is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<FOS\ElasticaBundle\Index\MappingBuilder>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
77
            $this->configManager,
0 ignored issues
show
Documentation introduced by
$this->configManager is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<FOS\ElasticaBundl...guration\ConfigManager>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
78
            $this->aliasProcessor
0 ignored issues
show
Documentation introduced by
$this->aliasProcessor is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<FOS\ElasticaBundle\Index\AliasProcessor>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
79
        );
80
    }
81
82 View Code Duplication
    public function testExecuteWithIndexProvidedAndWithAlias()
83
    {
84
        $input = $this->createMock(InputInterface::class);
85
        $output = $this->createMock(OutputInterface::class);
86
87
        $indexName = 'foo';
88
        $mapping = ['mapping'];
89
90
        $input->expects($this->once())->method('getOption')->with('index')->willReturn($indexName);
91
        $output->expects($this->once())->method('writeln');
92
        $this->configManager->expects($this->once())->method('getIndexConfiguration')->with($indexName)->willReturn($this->indexConfig);
93
        $this->indexManager->expects($this->once())->method('getIndex')->with($indexName)->willReturn($this->index);
94
        $this->indexConfig->expects($this->once())->method('isUseAlias')->willReturn(true);
95
        $this->aliasProcessor->expects($this->once())->method('setRootName')->with($this->indexConfig, $this->index);
96
        $this->mappingBuilder->expects($this->once())->method('buildIndexMapping')->with($this->indexConfig)->willReturn($mapping);
97
        $this->index->expects($this->once())->method('create')->with(['mapping'], false);
98
99
        $this->command->run($input, $output);
0 ignored issues
show
Documentation introduced by
$input is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Symfony\Component...e\Input\InputInterface>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
Documentation introduced by
$output is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Symfony\Component...Output\OutputInterface>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
100
    }
101
102 View Code Duplication
    public function testExecuteWithIndexProvidedAndWithoutAlias()
103
    {
104
        $input = $this->createMock(InputInterface::class);
105
        $output = $this->createMock(OutputInterface::class);
106
107
        $indexName = 'foo';
108
        $mapping = ['mapping'];
109
110
        $input->expects($this->once())->method('getOption')->with('index')->willReturn($indexName);
111
        $output->expects($this->once())->method('writeln');
112
        $this->configManager->expects($this->once())->method('getIndexConfiguration')->with($indexName)->willReturn($this->indexConfig);
113
        $this->indexManager->expects($this->once())->method('getIndex')->with($indexName)->willReturn($this->index);
114
        $this->indexConfig->expects($this->once())->method('isUseAlias')->willReturn(false);
115
        $this->aliasProcessor->expects($this->never())->method('setRootName');
116
        $this->mappingBuilder->expects($this->once())->method('buildIndexMapping')->with($this->indexConfig)->willReturn($mapping);
117
        $this->index->expects($this->once())->method('create')->with(['mapping'], false);
118
119
        $this->command->run($input, $output);
0 ignored issues
show
Documentation introduced by
$input is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Symfony\Component...e\Input\InputInterface>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
Documentation introduced by
$output is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Symfony\Component...Output\OutputInterface>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
120
    }
121
122
    public function testExecuteAllIndices()
123
    {
124
        $input = $this->createMock(InputInterface::class);
125
        $output = $this->createMock(OutputInterface::class);
126
        $indexConfig1 = clone $this->indexConfig;
127
        $indexConfig2 = clone $this->indexConfig;
128
        $index1 = clone $this->index;
129
        $index2 = clone $this->index;
130
131
        $indexName = null;
132
        $indices = ['foo', 'bar'];
133
        $mapping = ['mapping'];
134
135
        $input->expects($this->once())->method('getOption')->with('index')->willReturn($indexName);
136
        $this->indexManager->expects($this->once())->method('getAllIndexes')->willReturn(array_flip($indices));
137
        $output->expects($this->exactly(2))->method('writeln');
138
139
        $this->configManager->expects($this->exactly(2))->method('getIndexConfiguration')
140
            ->withConsecutive(['foo'], ['bar'])
141
            ->willReturnOnConsecutiveCalls($indexConfig1, $indexConfig2);
142
143
        $this->indexManager->expects($this->exactly(2))->method('getIndex')
144
            ->withConsecutive(['foo'], ['bar'])
145
            ->willReturnOnConsecutiveCalls($index1, $index2);
146
147
        $indexConfig1->expects($this->once())->method('isUseAlias')->willReturn(false);
148
        $indexConfig2->expects($this->once())->method('isUseAlias')->willReturn(false);
149
150
        $this->aliasProcessor->expects($this->never())->method('setRootName');
151
152
        $this->mappingBuilder->expects($this->exactly(2))->method('buildIndexMapping')
153
            ->withConsecutive([$indexConfig1], [$indexConfig2])
154
            ->willReturn($mapping);
155
156
        $index1->expects($this->once())->method('create')->with(['mapping'], false);
157
        $index2->expects($this->once())->method('create')->with(['mapping'], false);
158
159
        $this->command->run($input, $output);
0 ignored issues
show
Documentation introduced by
$input is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Symfony\Component...e\Input\InputInterface>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
Documentation introduced by
$output is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Symfony\Component...Output\OutputInterface>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
160
    }
161
}
162