ScrollReaderTest   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A setup() 0 7 1
B testGetItems() 0 27 2
1
<?php 
2
3
namespace Port\Elasticsearch\Tests;
4
5
use PHPUnit\Framework\TestCase;
6
use Elasticsearch\Client;
7
use Port\Elasticsearch\ScrollReader;
8
9
class ScrollReaderTest extends TestCase
10
{
11
    protected function setup()
12
    {
13
        $this->client = $this->prophesize(Client::class);
0 ignored issues
show
Bug introduced by
The property client does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
14
        $this->reader = new ScrollReader($this->client, [
0 ignored issues
show
Bug introduced by
The property reader does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
15
            'foo' => 'bar',
16
        ]);
17
    }
18
19
    public function testGetItems()
20
    {
21
        $this->client->search(['foo' => 'bar', 'scroll' => '1m'])
22
            ->willReturn([
23
                '_scroll_id' => '1',
24
                'hits' => [
25
                    'hits' => [
26
                        'foo' => 'bar'
27
                    ]
28
                ]
29
            ]);
30
31
        $this->client->search(['foo' => 'bar', 'scroll' => '1m', 'scroll_id' => '1'])
32
            ->willReturn([
33
                '_scroll_id' => '2',
34
                'hits' => []
35
            ]);
36
37
        $response = $this->reader->getItems();
38
        $items = [];
39
        
40
        foreach ($response as $item) {
41
            $items[] = $item;
42
        }
43
44
        $this->assertEquals(['foo' => 'bar'], $items);
45
    }
46
}