Completed
Push — master ( de4a58...150ab8 )
by GBProd
02:18
created

DeleteIndexHandler::newConfigRepository()   A

Complexity

Conditions 2
Paths 1

Size

Total Lines 21
Code Lines 11

Duplication

Lines 21
Ratio 100 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 21
loc 21
rs 9.3142
cc 2
eloc 11
nc 1
nop 2
1
<?php
2
3
namespace GBProd\Tests\Units\ElasticsearchExtraBundle\Handler;
4
5
use atoum;
6
use mock\Elasticsearch\Client;
7
use mock\Elasticsearch\Namespaces\IndicesNamespace;
8
use mock\GBProd\ElasticsearchExtraBundle\Repository\ClientRepository;
9
use mock\GBProd\ElasticsearchExtraBundle\Repository\IndexConfigurationRepository;
10
11
/**
12
 * Tests for DeleteIndexHandler
13
 *
14
 * @author gbprod <[email protected]>
15
 */
16
class DeleteIndexHandler extends atoum
17
{
18
    public function testHandle()
19
    {
20
        $this
21
            ->given($config = ['my' => ['awesome' => 'config']])
22
                ->and($indices = $this->newIndices())
23
                ->and($client = $this->newClient($indices))
24
                ->and($this->newTestedInstance())
25
            ->if($this->testedInstance->handle($client, 'my_index'))
26
            ->then
27
                ->mock($indices)
28
                    ->call('delete')
29
                        ->withArguments([
30
                                'index' => 'my_index',
31
                            ]
32
                        )
33
                        ->once()
34
        ;
35
    }
36
37
    private function newIndices()
38
    {
39
        $this->mockGenerator->shuntParentClassCalls();
40
        $this->mockGenerator->orphanize('__construct');
41
42
        return new IndicesNamespace();
43
    }
44
45
    private function newClient($indices)
46
    {
47
        $this->mockGenerator->shuntParentClassCalls();
48
        $this->mockGenerator->orphanize('__construct');
49
50
        $client = new Client();
51
52
        $this->calling($client)->indices = function() use ($indices) {
53
            return $indices;
54
        };
55
56
        return $client;
57
    }
58
}
59