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