|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace TraitsTests; |
|
4
|
|
|
|
|
5
|
|
|
|
|
6
|
|
|
use kalanis\kw_input\Interfaces; |
|
7
|
|
|
use kalanis\kw_input\Entries; |
|
8
|
|
|
use kalanis\kw_input\Traits; |
|
9
|
|
|
use stdClass; |
|
10
|
|
|
|
|
11
|
|
|
|
|
12
|
|
|
class FillerTest extends ATraitsTest |
|
13
|
|
|
{ |
|
14
|
|
|
public function testFilledEntries(): void |
|
15
|
|
|
{ |
|
16
|
|
|
$lib = new XFill(); |
|
17
|
|
|
$this->checkData($lib->fromEntries(Interfaces\IEntry::SOURCE_EXTERNAL, $this->inputData())); |
|
18
|
|
|
} |
|
19
|
|
|
|
|
20
|
|
|
public function testFilledIterator(): void |
|
21
|
|
|
{ |
|
22
|
|
|
$lib = new XFill(); |
|
23
|
|
|
$this->checkData($lib->fromIterator(Interfaces\IEntry::SOURCE_EXTERNAL, new \ArrayIterator($this->inputData()))); |
|
24
|
|
|
} |
|
25
|
|
|
|
|
26
|
|
|
protected function inputData(): array |
|
27
|
|
|
{ |
|
28
|
|
|
return [ |
|
29
|
|
|
'foz' => 'wuz', |
|
30
|
|
|
'ugg' . chr(0) => 'huu' . chr(0), |
|
31
|
|
|
'asd' => $this->getSimpleObject(), |
|
32
|
|
|
'ghd' => (new Entries\Entry())->setEntry(Entries\Entry::SOURCE_RAW, 'ghd', 'ankyxgf'), |
|
33
|
|
|
]; |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
protected function getSimpleObject(): object |
|
37
|
|
|
{ |
|
38
|
|
|
$obj = new stdClass(); |
|
39
|
|
|
$obj->foo = 'bar'; |
|
40
|
|
|
return $obj; |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
protected function checkData(array $data): void |
|
44
|
|
|
{ |
|
45
|
|
|
$item = reset($data); |
|
46
|
|
|
$this->assertNotFalse($item); |
|
47
|
|
|
/** @var Entries\Entry $item */ |
|
48
|
|
|
$this->assertEquals(Interfaces\IEntry::SOURCE_EXTERNAL, $item->getSource()); |
|
49
|
|
|
$this->assertEquals('foz', $item->getKey()); |
|
50
|
|
|
$this->assertEquals('wuz', $item->getValue()); |
|
51
|
|
|
|
|
52
|
|
|
$item = next($data); |
|
53
|
|
|
$this->assertNotFalse($item); |
|
54
|
|
|
/** @var Entries\Entry $item */ |
|
55
|
|
|
$this->assertEquals(Interfaces\IEntry::SOURCE_EXTERNAL, $item->getSource()); |
|
56
|
|
|
$this->assertEquals('ugg', $item->getKey()); |
|
57
|
|
|
$this->assertEquals('huu' . chr(0), $item->getValue()); |
|
58
|
|
|
|
|
59
|
|
|
$item = next($data); |
|
60
|
|
|
$this->assertNotFalse($item); |
|
61
|
|
|
/** @var Entries\Entry $item */ |
|
62
|
|
|
$this->assertEquals(Interfaces\IEntry::SOURCE_EXTERNAL, $item->getSource()); |
|
63
|
|
|
$this->assertEquals('asd', $item->getKey()); |
|
64
|
|
|
$this->assertInstanceOf(stdClass::class, $item->getValue()); |
|
65
|
|
|
|
|
66
|
|
|
$item = next($data); |
|
67
|
|
|
$this->assertNotFalse($item); |
|
68
|
|
|
/** @var Entries\Entry $item */ |
|
69
|
|
|
$this->assertEquals(Interfaces\IEntry::SOURCE_EXTERNAL, $item->getSource()); |
|
70
|
|
|
$this->assertEquals('ghd', $item->getKey()); |
|
71
|
|
|
$this->assertEquals('ankyxgf', $item->getValue()); |
|
72
|
|
|
|
|
73
|
|
|
$item = next($data); |
|
74
|
|
|
$this->assertFalse($item); |
|
75
|
|
|
} |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
|
|
79
|
|
|
class XFill |
|
80
|
|
|
{ |
|
81
|
|
|
use Traits\TFill; |
|
82
|
|
|
|
|
83
|
|
|
public function fromEntries(string $source, array $entries): array |
|
84
|
|
|
{ |
|
85
|
|
|
return $this->fillFromEntries($source, $entries); |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
public function fromIterator(string $source, iterable $iterator): array |
|
89
|
|
|
{ |
|
90
|
|
|
return $this->fillFromIterator($source, $iterator); |
|
91
|
|
|
} |
|
92
|
|
|
} |
|
93
|
|
|
|