1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace BasicTests; |
4
|
|
|
|
5
|
|
|
|
6
|
|
|
use CommonTestClass; |
7
|
|
|
use kalanis\kw_filter\FilterArrayEntry; |
8
|
|
|
use kalanis\kw_filter\Interfaces\IFilterEntry; |
9
|
|
|
|
10
|
|
|
|
11
|
|
|
class EntryArrayTest extends CommonTestClass |
12
|
|
|
{ |
13
|
|
|
public function testEntry(): void |
14
|
|
|
{ |
15
|
|
|
$entry = new FilterArrayEntry(); |
16
|
|
|
$this->assertEmpty($entry->getKey()); |
17
|
|
|
$this->assertEmpty($entry->getValue()); |
18
|
|
|
$this->assertEquals(IFilterEntry::RELATION_IN, $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 FilterArrayEntry(); |
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, array $expected): void |
46
|
|
|
{ |
47
|
|
|
$entry = new FilterArrayEntry(); |
48
|
|
|
$entry->setValue($values); |
49
|
|
|
$this->assertEquals($expected, $entry->getValue()); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
public function valueProvider(): array |
53
|
|
|
{ |
54
|
|
|
return [ |
55
|
|
|
['poi', ['poi']], |
56
|
|
|
[['dum', 'din', 'don'], ['dum', 'din', 'don']], |
57
|
|
|
[[1353, 'ysdg'], ['1353', 'ysdg']], |
58
|
|
|
[864, ['864']], |
59
|
|
|
[false, ['']], |
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 FilterArrayEntry(); |
72
|
|
|
$entry->setRelation($value); |
73
|
|
|
$this->assertEquals($expected, $entry->getRelation()); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
public function relationProvider(): array |
77
|
|
|
{ |
78
|
|
|
return [ |
79
|
|
|
[IFilterEntry::RELATION_NOT_IN, IFilterEntry::RELATION_NOT_IN], |
80
|
|
|
['bad', IFilterEntry::RELATION_IN], |
81
|
|
|
]; |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
protected function getAnonClass(): object |
85
|
|
|
{ |
86
|
|
|
return new class { |
87
|
|
|
public function __toString() |
88
|
|
|
{ |
89
|
|
|
return 'fbjgf'; |
90
|
|
|
} |
91
|
|
|
}; |
92
|
|
|
} |
93
|
|
|
} |
94
|
|
|
|