EntryTest::testKeys()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 3
nc 1
nop 2
dl 0
loc 5
rs 10
c 1
b 0
f 1
1
<?php
2
3
namespace BasicTests;
4
5
6
use CommonTestClass;
7
use kalanis\kw_filter\FilterEntry;
8
use kalanis\kw_filter\Interfaces\IFilterEntry;
9
10
11
class EntryTest extends CommonTestClass
12
{
13
    public function testEntry(): void
14
    {
15
        $entry = new FilterEntry();
16
        $this->assertEmpty($entry->getKey());
17
        $this->assertEmpty($entry->getValue());
18
        $this->assertEquals(IFilterEntry::RELATION_EQUAL, $entry->getRelation());
19
    }
20
21
    /**
22
     * @param string $keys
23
     * @param string $expected
24
     * @dataProvider keyProvider
25
     */
26
    public function testKeys(string $keys, string $expected): void
27
    {
28
        $entry = new FilterEntry();
29
        $entry->setKey($keys);
30
        $this->assertEquals($expected, $entry->getKey());
31
    }
32
33
    public function keyProvider(): array
34
    {
35
        return [
36
            ['any', 'any'],
37
        ];
38
    }
39
40
    /**
41
     * @param mixed $values
42
     * @param string $expected
43
     * @dataProvider valueProvider
44
     */
45
    public function testValues($values, string $expected): void
46
    {
47
        $entry = new FilterEntry();
48
        $entry->setValue($values);
49
        $this->assertEquals($expected, $entry->getValue());
50
    }
51
52
    public function valueProvider(): array
53
    {
54
        return [
55
            ['poi', 'poi'],
56
            [['dggh', 'sdfhg'], 'dggh'],
57
            [[1353, 'ysdg'], '1353'],
58
            [false, ''],
59
            [true, '1'],
60
            [$this->getAnonClass(), 'fbjgf'],
61
        ];
62
    }
63
64
    /**
65
     * @param string $value
66
     * @param string $expected
67
     * @dataProvider relationProvider
68
     */
69
    public function testRelations(string $value, string $expected): void
70
    {
71
        $entry = new FilterEntry();
72
        $entry->setRelation($value);
73
        $this->assertEquals($expected, $entry->getRelation());
74
    }
75
76
    public function relationProvider(): array
77
    {
78
        return [
79
            [IFilterEntry::RELATION_EQUAL, IFilterEntry::RELATION_EQUAL],
80
            [IFilterEntry::RELATION_MORE, IFilterEntry::RELATION_MORE],
81
            ['bad', IFilterEntry::RELATION_EQUAL],
82
        ];
83
    }
84
85
    protected function getAnonClass(): object
86
    {
87
        return new class {
88
            public function __toString()
89
            {
90
                return 'fbjgf';
91
            }
92
        };
93
    }
94
}
95