AbstractDaftObjectEasyDBRepositoryTest   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 74
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
eloc 26
dl 0
loc 74
ccs 29
cts 29
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A test_AbstractDaftObjectEasyDBRepository() 0 32 1
A ObtainDaftObjectRepositoryType() 0 3 1
A ObtainDaftObjectRepositoryAndAssertSameByObject() 0 27 1
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));
0 ignored issues
show
Bug Best Practice introduced by
The method PHPUnit\Framework\Assert::assertSame() is not static, but was called statically. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

92
        static::/** @scrutinizer ignore-call */ 
93
                assertSame(get_class($repo), get_class($repo_from_object));
Loading history...
Bug introduced by
get_class($repo) of type string is incompatible with the type PHPUnit\Framework\T expected by parameter $expected of PHPUnit\Framework\Assert::assertSame(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

92
        static::assertSame(/** @scrutinizer ignore-type */ get_class($repo), get_class($repo_from_object));
Loading history...
93
94 8
        return $repo;
95
    }
96
}
97