1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @author SignpostMarv |
4
|
|
|
*/ |
5
|
|
|
declare(strict_types=1); |
6
|
|
|
|
7
|
|
|
namespace SignpostMarv\DaftObject\DaftObjectRepository\Tests\AbstractDaftObjectEasyDBRepository; |
8
|
|
|
|
9
|
|
|
use ParagonIE\EasyDB\Factory; |
10
|
|
|
use SignpostMarv\DaftObject\DaftObjectRepository; |
11
|
|
|
use SignpostMarv\DaftObject\DaftObjectRepository\Tests\DaftObjectMemoryRepository\DaftObjectMemoryRepositoryTest; |
12
|
|
|
use SignpostMarv\DaftObject\EasyDB\TestObjectRepository; |
13
|
|
|
use SignpostMarv\DaftObject\SuitableForRepositoryType; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* @template T as SuitableForRepositoryType |
17
|
|
|
* @template R as TestObjectRepository |
18
|
|
|
* |
19
|
|
|
* @template-extends DaftObjectMemoryRepositoryTest<T, R> |
20
|
|
|
*/ |
21
|
|
|
class AbstractDaftObjectEasyDBRepositoryTest extends DaftObjectMemoryRepositoryTest |
22
|
|
|
{ |
23
|
4 |
|
public function test_AbstractDaftObjectEasyDBRepository() : void |
24
|
|
|
{ |
25
|
4 |
|
$expected_data = static::InitialData_test_DaftObjectMemoryRepository(); |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @psalm-var T |
29
|
|
|
*/ |
30
|
4 |
|
$a = static::ObtainSuitableForRepositoryIntTypeFromArgs(array_merge( |
31
|
4 |
|
['id' => 1], |
32
|
4 |
|
$expected_data |
33
|
|
|
)); |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @psalm-var R |
37
|
|
|
*/ |
38
|
4 |
|
$repo = $this->ObtainDaftObjectRepositoryAndAssertSameByObject($a); |
39
|
|
|
|
40
|
4 |
|
$repo->RememberDaftObjectData($a); |
41
|
4 |
|
$repo->RememberDaftObjectData($a, false); |
42
|
|
|
|
43
|
4 |
|
$this->RecallThenAssertBothModes( |
44
|
4 |
|
$repo, |
45
|
4 |
|
$a, |
46
|
4 |
|
$expected_data |
47
|
|
|
); |
48
|
|
|
|
49
|
4 |
|
$repo->ForgetDaftObject($a); |
50
|
|
|
|
51
|
4 |
|
$this->RecallThenAssertBothModes( |
52
|
4 |
|
$repo, |
53
|
4 |
|
$a, |
54
|
4 |
|
$expected_data |
55
|
|
|
); |
56
|
4 |
|
} |
57
|
|
|
|
58
|
8 |
|
protected static function ObtainDaftObjectRepositoryType() : string |
59
|
|
|
{ |
60
|
8 |
|
return TestObjectRepository::class; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* @psalm-param T $object |
65
|
|
|
* |
66
|
|
|
* @psalm-return R |
67
|
|
|
*/ |
68
|
8 |
|
protected function ObtainDaftObjectRepositoryAndAssertSameByObject( |
69
|
|
|
SuitableForRepositoryType $object |
70
|
|
|
) : DaftObjectRepository { |
71
|
|
|
/** |
72
|
|
|
* @psalm-var class-string<R> |
73
|
|
|
*/ |
74
|
8 |
|
$repo_type = static::ObtainDaftObjectRepositoryType(); |
75
|
|
|
|
76
|
8 |
|
$db = Factory::create('sqlite::memory:'); |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* @psalm-var class-string<T> |
80
|
|
|
*/ |
81
|
8 |
|
$object_type = static::ObtainDaftObjectType(); |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* @psalm-var R |
85
|
|
|
*/ |
86
|
8 |
|
$repo = $repo_type::DaftObjectRepositoryByType($object_type, $db); |
87
|
|
|
|
88
|
8 |
|
$db = Factory::create('sqlite::memory:'); |
89
|
|
|
|
90
|
8 |
|
$repo_from_object = $repo_type::DaftObjectRepositoryByDaftObject($object, $db); |
91
|
|
|
|
92
|
8 |
|
static::assertSame(get_class($repo), get_class($repo_from_object)); |
|
|
|
|
93
|
|
|
|
94
|
8 |
|
return $repo; |
95
|
|
|
} |
96
|
|
|
} |
97
|
|
|
|