Completed
Push — master ( cb7970...970861 )
by Colin
12:52 queued 03:09
created

IndexExistsCommandTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 78
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 2
dl 0
loc 78
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A testIndexExists() 0 20 1
A testIndexDoesntExists() 0 20 1
A testArgumentIndexNameIsInValid() 0 7 1
A invalidIndexNameDataProvider() 0 22 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Cviebrock\LaravelElasticsearch\Tests\Console\Command;
6
7
use Cviebrock\LaravelElasticsearch\Tests\TestCase;
8
use Elasticsearch\Client;
9
use Elasticsearch\Namespaces\IndicesNamespace;
10
use Generator;
11
use Mockery\MockInterface;
12
13
final class IndexExistsCommandTest extends TestCase
0 ignored issues
show
Bug introduced by
There is at least one abstract method in this class. Maybe declare it as abstract, or implement the remaining methods: artisan, be, call, seed
Loading history...
14
{
15
    public function testIndexExists(): void
16
    {
17
        $this->mock(Client::class, function (MockInterface $mock) {
0 ignored issues
show
Bug introduced by
The method mock() does not seem to exist on object<Cviebrock\Laravel...IndexExistsCommandTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
18
            $mock->shouldReceive('indices')
19
                ->once()
20
                ->andReturn(
21
                    $this->mock(IndicesNamespace::class, function (MockInterface $mock) {
0 ignored issues
show
Bug introduced by
The method mock() does not seem to exist on object<Cviebrock\Laravel...IndexExistsCommandTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
22
                        $mock->shouldReceive('exists')
23
                            ->once()
24
                            ->andReturn(true);
25
                    })
26
                );
27
        });
28
29
        $this->artisan(
30
            'laravel-elasticsearch:utils:index-exists',
31
            ['index-name' => 'index_name_exists']
32
        )->assertExitCode(0)
33
            ->expectsOutput('Index index_name_exists exists.');
34
    }
35
36
    public function testIndexDoesntExists(): void
37
    {
38
        $this->mock(Client::class, function (MockInterface $mock) {
0 ignored issues
show
Bug introduced by
The method mock() does not seem to exist on object<Cviebrock\Laravel...IndexExistsCommandTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
39
            $mock->shouldReceive('indices')
40
                ->once()
41
                ->andReturn(
42
                    $this->mock(IndicesNamespace::class, function (MockInterface $mock) {
0 ignored issues
show
Bug introduced by
The method mock() does not seem to exist on object<Cviebrock\Laravel...IndexExistsCommandTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
43
                        $mock->shouldReceive('exists')
44
                            ->once()
45
                            ->andReturn(false);
46
                    })
47
                );
48
        });
49
50
        $this->artisan(
51
            'laravel-elasticsearch:utils:index-exists',
52
            ['index-name' => 'test_index_name_doesnt_exists']
53
        )->assertExitCode(0)
54
            ->expectsOutput('Index test_index_name_doesnt_exists doesn\'t exists.');
55
    }
56
57
    /**
58
     * @dataProvider invalidIndexNameDataProvider
59
     */
60
    public function testArgumentIndexNameIsInValid($invalidIndexName): void
61
    {
62
        $this->artisan('laravel-elasticsearch:utils:index-exists',
63
            ['index-name' => $invalidIndexName]
64
        )->assertExitCode(1)
65
            ->expectsOutput('Argument index-name must be a non empty string.');
66
    }
67
68
    public function invalidIndexNameDataProvider(): Generator
69
    {
70
        yield [
71
            null
72
        ];
73
74
        yield [
75
            ''
76
        ];
77
78
        yield [
79
            true
80
        ];
81
82
        yield [
83
            1
84
        ];
85
86
        yield [
87
            []
88
        ];
89
    }
90
}
91