|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace BasicTests; |
|
4
|
|
|
|
|
5
|
|
|
|
|
6
|
|
|
use CommonTestClass; |
|
7
|
|
|
use kalanis\kw_forms\Cache\Formats\Json; |
|
8
|
|
|
use kalanis\kw_forms\Cache\Storage; |
|
9
|
|
|
use kalanis\kw_forms\Cache\TStorage; |
|
10
|
|
|
use kalanis\kw_storage\Storage\Target\Memory; |
|
11
|
|
|
use kalanis\kw_storage\StorageException; |
|
12
|
|
|
|
|
13
|
|
|
|
|
14
|
|
|
class CacheTest extends CommonTestClass |
|
15
|
|
|
{ |
|
16
|
|
|
/** |
|
17
|
|
|
* @throws StorageException |
|
18
|
|
|
*/ |
|
19
|
|
|
public function testStorageTrait(): void |
|
20
|
|
|
{ |
|
21
|
|
|
$storagePart = new StorageTrait(); |
|
22
|
|
|
$storagePart->deleteStored(); |
|
23
|
|
|
$this->assertFalse($storagePart->isStored()); |
|
24
|
|
|
$storagePart->setStorage(new Memory()); |
|
25
|
|
|
$storagePart->deleteStored(); |
|
26
|
|
|
$this->assertFalse($storagePart->isStored()); |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* @throws StorageException |
|
31
|
|
|
*/ |
|
32
|
|
|
public function testStorage(): void |
|
33
|
|
|
{ |
|
34
|
|
|
$storage = new Storage(new Memory(), new Json()); |
|
35
|
|
|
$storage->setAlias('test'); |
|
36
|
|
|
$this->assertTrue($storage->store($this->contentStructure())); |
|
37
|
|
|
$this->assertTrue($storage->isStored()); |
|
38
|
|
|
$data = $storage->load(); |
|
39
|
|
|
$this->assertNotEmpty($data); |
|
40
|
|
|
$this->assertTrue($storage->delete()); |
|
41
|
|
|
$this->assertFalse($storage->isStored()); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* @throws StorageException |
|
46
|
|
|
*/ |
|
47
|
|
|
public function testStorageNothing(): void |
|
48
|
|
|
{ |
|
49
|
|
|
$storage = new Storage(); |
|
50
|
|
|
$storage->setAlias('test'); |
|
51
|
|
|
$this->assertFalse($storage->store($this->contentStructure())); |
|
52
|
|
|
$this->assertFalse($storage->isStored()); |
|
53
|
|
|
$data = $storage->load(); |
|
54
|
|
|
$this->assertEmpty($data); |
|
55
|
|
|
$this->assertFalse($storage->delete()); |
|
56
|
|
|
$this->assertFalse($storage->isStored()); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* @throws StorageException |
|
61
|
|
|
*/ |
|
62
|
|
|
public function testStorageFailedData(): void |
|
63
|
|
|
{ |
|
64
|
|
|
$mock = new Memory(); |
|
65
|
|
|
$storage = new Storage($mock); |
|
66
|
|
|
$storage->setAlias('test'); |
|
67
|
|
|
$this->assertTrue($storage->store($this->contentStructure())); |
|
68
|
|
|
$this->assertTrue($storage->isStored()); |
|
69
|
|
|
$mock->save('FormStorage_test_', '----'); // boo! |
|
70
|
|
|
$data = $storage->load(); |
|
71
|
|
|
$this->assertEmpty($data); |
|
72
|
|
|
$this->assertTrue($storage->delete()); |
|
73
|
|
|
$this->assertFalse($storage->isStored()); |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
protected function contentStructure(): array |
|
77
|
|
|
{ |
|
78
|
|
|
return ['6g8a7' => 'dfh4dg364sd6g', 'hzsdfgh' => 35.4534, 'sfkg' => false, 'hdhg' => 'sdfh5433']; |
|
79
|
|
|
} |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
|
|
83
|
|
|
class StorageTrait |
|
84
|
|
|
{ |
|
85
|
|
|
use TStorage; |
|
86
|
|
|
|
|
87
|
|
|
public function getAlias(): ?string |
|
88
|
|
|
{ |
|
89
|
|
|
return 'OurAlias'; |
|
90
|
|
|
} |
|
91
|
|
|
} |
|
92
|
|
|
|