Completed
Push — master ( 811e69...252365 )
by Alexander
02:01
created

DocumentTest::testHas()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 7
rs 9.4285
cc 1
eloc 4
nc 1
nop 2
1
<?php
2
3
namespace EmberDb;
4
5
use PHPUnit\Framework\TestCase;
6
7
class DocumentTest extends TestCase
8
{
9
    public function providerHas()
10
    {
11
        $defaultPreconditions = [
12
            'document' => [
13
                'foo' => [
14
                    'bar' => 'baz'
15
                ]
16
            ]
17
        ];
18
        $defaultExpectations = [];
19
20
        $testCases = [
21
            '1-element subpath of existing 2-element-path' => [
22
                'preconditions' => [
23
                    'path' => 'foo'
24
                ],
25
                'expectations' => [
26
                    'has' => true
27
                ]
28
            ],
29
            'Existing, two-element path' => [
30
                'preconditions' => [
31
                    'path' => 'foo.bar'
32
                ],
33
                'expectations' => [
34
                    'has' => true
35
                ]
36
            ],
37
            'Non-existing, two-element path' => [
38
                'preconditions' => [
39
                    'path' => 'foo.baz'
40
                ],
41
                'expectations' => [
42
                    'has' => false
43
                ]
44
            ],
45
            'Non-existing 3-element-path in a document only containing 2-element-paths' => [
46
                'preconditions' => [
47
                    'path' => 'foo.bar.baz'
48
                ],
49
                'expectations' => [
50
                    'has' => false
51
                ]
52
            ],
53
            'Non-existing 3-element-path in a document only containing 2-element-paths with an empty array' => [
54
                'preconditions' => [
55
                    'document' => [
56
                        'foo' => [
57
                            'bar' => []
58
                        ]
59
                    ],
60
                    'path' => 'foo.bar.baz'
61
                ],
62
                'expectations' => [
63
                    'has' => false
64
                ]
65
            ],
66
        ];
67
68
        // Merge test data with default data
69
        foreach ($testCases as &$testCase) {
70
            $testCase['preconditions'] = array_merge($defaultPreconditions, $testCase['preconditions']);
71
            $testCase['expectations'] = array_merge($defaultExpectations, $testCase['expectations']);
72
        }
73
74
        return $testCases;
75
    }
76
77
78
    /**
79
     * @dataProvider providerHas
80
     */
81
    public function testHas($preconditions, $expectations)
82
    {
83
        $document = new Document($preconditions['document']);
84
        $has = $document->has($preconditions['path']);
85
86
        $this->assertEquals($expectations['has'], $has);
87
    }
88
}
89