ScrollReaderTest::setup()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 7
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 0
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
}