Failed Conditions
Pull Request — master (#69)
by Timon
02:28
created

HasFieldsTest::testHasField()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 9
dl 0
loc 14
rs 9.9666
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
declare(strict_types=1);
3
4
namespace TBolier\RethinkQL\IntegrationTest\Manipulation;
5
6
use TBolier\RethinkQL\IntegrationTest\Query\AbstractTableTest;
7
use TBolier\RethinkQL\Response\Cursor;
8
9
class HasFieldsTest extends AbstractTableTest
10
{
11
    /**
12
     * @throws \Exception
13
     */
14
    public function testTableHasField()
15
    {
16
        $this->insertDocument(1);
17
        $this->insertDocument(2);
18
        $this->insertDocumentWithNumber(3, 1);
19
20
        /** @var Cursor $cursor */
21
        $cursor = $this->r()
22
            ->table('tabletest')
23
            ->hasFields('number')
24
            ->run();
25
26
        $this->assertInstanceOf(\Iterator::class, $cursor);
27
        $this->assertEquals(1, $cursor->count());
28
    }
29
30
    /**
31
     * @throws \Exception
32
     */
33
    public function testHasField()
34
    {
35
        $this->insertDocument(1);
36
        $this->insertDocument(2);
37
        $this->insertDocumentWithNumber(3, 1);
38
39
        /** @var Cursor $cursor */
40
        $cursor = $this->r()
41
            ->table('tabletest')
42
            ->filter($this->r()->row()->hasFields('number'))
43
            ->run();
44
45
        $this->assertInstanceOf(\Iterator::class, $cursor);
46
        $this->assertEquals(1, $cursor->count());
47
    }
48
49
    /**
50
     * @throws \Exception
51
     */
52
    public function testHasFields()
53
    {
54
        $this->insertDocument(1);
55
        $this->insertDocument(2);
56
        $this->insertDocumentWithNumber(3, 1);
57
58
        /** @var Cursor $cursor */
59
        $cursor = $this->r()
60
            ->table('tabletest')
61
            ->filter($this->r()->row()->hasFields('id', 'number'))
62
            ->run();
63
64
        $this->assertInstanceOf(\Iterator::class, $cursor);
65
        $this->assertEquals(1, $cursor->count());
66
    }
67
68
    /**
69
     * @throws \Exception
70
     */
71
    public function testHasFieldsNot()
72
    {
73
        $this->insertDocument(1);
74
        $this->insertDocument(2);
75
        $this->insertDocumentWithNumber(3, 1);
76
77
        /** @var Cursor $cursor */
78
        $cursor = $this->r()
79
            ->table('tabletest')
80
            ->filter($this->r()->row()->hasFields('id', 'number')->not())
81
            ->run();
82
83
        $this->assertInstanceOf(\Iterator::class, $cursor);
84
        $this->assertEquals(2, $cursor->count());
85
    }
86
}
87