1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace KwTests; |
4
|
|
|
|
5
|
|
|
|
6
|
|
|
use kalanis\kw_connect\core\ConnectException; |
7
|
|
|
use kalanis\kw_connect\core\Interfaces; |
8
|
|
|
use kalanis\kw_connect\records; |
9
|
|
|
use kalanis\kw_connect\search; |
10
|
|
|
use kalanis\kw_mapper\Records\ARecord; |
11
|
|
|
|
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* Class BasicTest |
15
|
|
|
* @package KwTests |
16
|
|
|
* @requires extension PDO |
17
|
|
|
* @requires extension pdo_sqlite |
18
|
|
|
*/ |
19
|
|
|
class BasicTest extends AKwTests |
20
|
|
|
{ |
21
|
|
|
/** |
22
|
|
|
* @param ARecord $data |
23
|
|
|
* @param string|int $unknownKey |
24
|
|
|
* @param string|int $existsKey |
25
|
|
|
* @param mixed $expect |
26
|
|
|
* @param string $passFunc |
27
|
|
|
* @param bool $useFunc |
28
|
|
|
* @dataProvider rowProvider |
29
|
|
|
* @throws ConnectException |
30
|
|
|
*/ |
31
|
|
|
public function testRowRecord(ARecord $data, $unknownKey, $existsKey, $expect, $passFunc, $useFunc) |
32
|
|
|
{ |
33
|
|
|
$data = new records\Row($data); |
34
|
|
|
$this->assertInstanceOf(Interfaces\IRow::class, $data); |
35
|
|
|
|
36
|
|
|
$this->assertFalse($data->__isset($unknownKey)); |
37
|
|
|
$this->assertFalse(isset($data->$unknownKey)); |
38
|
|
|
|
39
|
|
|
$this->assertTrue($data->__isset($existsKey)); |
40
|
|
|
$this->assertTrue(isset($data->$existsKey)); |
41
|
|
|
|
42
|
|
|
$this->assertEquals($expect, $data->getValue($existsKey)); |
43
|
|
|
|
44
|
|
|
$this->assertFalse($data->__isset($passFunc)); |
45
|
|
|
$this->assertFalse(isset($data->$passFunc)); |
46
|
|
|
|
47
|
|
|
if ($useFunc) { |
48
|
|
|
$this->assertEquals($expect, $data->getValue($passFunc)); |
49
|
|
|
} |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @param ARecord $data |
54
|
|
|
* @param string|int $unknownKey |
55
|
|
|
* @param string|int $existsKey |
56
|
|
|
* @param mixed $expect |
57
|
|
|
* @param string $passFunc |
58
|
|
|
* @param bool $useFunc |
59
|
|
|
* @dataProvider rowProvider |
60
|
|
|
* @throws ConnectException |
61
|
|
|
*/ |
62
|
|
|
public function testRowSearch(ARecord $data, $unknownKey, $existsKey, $expect, $passFunc, $useFunc) |
63
|
|
|
{ |
64
|
|
|
$data = new search\Row($data); |
65
|
|
|
$this->assertInstanceOf(Interfaces\IRow::class, $data); |
66
|
|
|
|
67
|
|
|
$this->assertFalse($data->__isset($unknownKey)); |
68
|
|
|
$this->assertFalse(isset($data->$unknownKey)); |
69
|
|
|
|
70
|
|
|
$this->assertTrue($data->__isset($existsKey)); |
71
|
|
|
$this->assertTrue(isset($data->$existsKey)); |
72
|
|
|
|
73
|
|
|
$this->assertEquals($expect, $data->getValue($existsKey)); |
74
|
|
|
|
75
|
|
|
$this->assertFalse($data->__isset($passFunc)); |
76
|
|
|
$this->assertFalse(isset($data->$passFunc)); |
77
|
|
|
|
78
|
|
|
if ($useFunc) { |
79
|
|
|
$this->assertEquals($expect, $data->getValue($passFunc)); |
80
|
|
|
} |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
public function rowProvider(): array |
84
|
|
|
{ |
85
|
|
|
return [ |
86
|
|
|
[$this->loadedRec(1), 'fff', 'name', 'dave', 'getName', true], |
87
|
|
|
[$this->loadedRec(2), 40, 'target', 'one', 'getTarget', false], |
88
|
|
|
[$this->loadedRec(3), 'hehe', 'counter', 789, 'getCounter', false], |
89
|
|
|
]; |
90
|
|
|
} |
91
|
|
|
} |
92
|
|
|
|