RepositoryServiceTest::testFindOneByEntity()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 19
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 2
Metric Value
eloc 13
c 2
b 0
f 2
dl 0
loc 19
rs 9.8333
cc 1
nc 1
nop 0
1
<?php
2
3
/*
4
 * This file is part of the core-bundle package.
5
 *
6
 * (c) 2022 WEBEWEB
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace WBW\Bundle\CoreBundle\Tests\Service;
13
14
use Throwable;
15
use WBW\Bundle\CoreBundle\Service\RepositoryService;
16
use WBW\Bundle\CoreBundle\Service\RepositoryServiceInterface;
17
use WBW\Bundle\CoreBundle\Tests\AbstractWebTestCase;
18
use WBW\Bundle\CoreBundle\Tests\Fixtures\Model\TestGroup;
19
use WBW\Bundle\CoreBundle\Tests\Fixtures\Model\TestUser;
20
21
/**
22
 * Repository service test.
23
 *
24
 * @author webeweb <https://github.com/webeweb>
25
 * @package WBW\Bundle\CoreBundle\Tests\Service
26
 */
27
class RepositoryServiceTest extends AbstractWebTestCase {
28
29
    /**
30
     * Repository service.
31
     *
32
     * @var RepositoryServiceInterface
33
     */
34
    private $service;
35
36
    /**
37
     * {@inheritDoc}
38
     */
39
    protected function setUp(): void {
40
        parent::setUp();
41
42
        // Set a Repository service.
43
        $this->service = static::$kernel->getContainer()->get(RepositoryService::SERVICE_NAME . ".alias");
44
    }
45
46
    /**
47
     * {@inheritDoc}
48
     */
49
    public static function setUpBeforeClass(): void {
50
        parent::setUpBeforeClass();
51
52
        parent::setUpSchemaTool();
53
    }
54
55
    /**
56
     * Test findAll()
57
     *
58
     * @return void
59
     * @throws Throwable Throws an exception if an error occurs.
60
     */
61
    public function testFindAll(): void {
62
63
        $obj = $this->service;
64
65
        $res = $obj->findAll();
66
        $this->assertCount(2, $res);
67
    }
68
69
    /**
70
     * Test findOneByEntity()
71
     *
72
     * @return void
73
     * @throws Throwable Throws an exception if an error occurs.
74
     */
75
    public function testFindOneByEntity(): void {
76
77
        $obj = $this->service;
78
79
        $res = $obj->findOneByEntity(TestGroup::class);
80
81
        $this->assertEquals("wbw_core_group", $res->getTable());
82
        $this->assertEquals(TestGroup::class, $res->getEntity());
83
        $this->assertEquals(0, $res->getCount());
84
85
        $this->assertCount(1, $res->getDetails());
86
87
        $this->assertEquals("name", $res->getDetails()[0]->getColumn());
88
        $this->assertEquals("name", $res->getDetails()[0]->getField());
89
        $this->assertEquals(-1, $res->getDetails()[0]->getAvailable());
90
        $this->assertEquals(0, $res->getDetails()[0]->getAverage());
91
        $this->assertEquals(0, $res->getDetails()[0]->getMinimum());
92
        $this->assertEquals(0, $res->getDetails()[0]->getMaximum());
93
        $this->assertEquals("string", $res->getDetails()[0]->getType());
94
    }
95
96
    /**
97
     * Test findOneByTable()
98
     *
99
     * @return void
100
     * @throws Throwable Throws an exception if an error occurs.
101
     */
102
    public function testFindOneByTable(): void {
103
104
        $obj = $this->service;
105
106
        $res = $obj->findOneByTable("wbw_core_user");
107
108
        $this->assertEquals("wbw_core_user", $res->getTable());
109
        $this->assertEquals(TestUser::class, $res->getEntity());
110
        $this->assertEquals(0, $res->getCount());
111
112
        $this->assertCount(3, $res->getDetails());
113
114
        $this->assertEquals("password", $res->getDetails()[0]->getColumn());
115
        $this->assertEquals("password", $res->getDetails()[0]->getField());
116
        $this->assertEquals(-1, $res->getDetails()[0]->getAvailable());
117
        $this->assertEquals(0, $res->getDetails()[0]->getAverage());
118
        $this->assertEquals(0, $res->getDetails()[0]->getMinimum());
119
        $this->assertEquals(0, $res->getDetails()[0]->getMaximum());
120
        $this->assertEquals("string", $res->getDetails()[0]->getType());
121
122
        $this->assertEquals("salt", $res->getDetails()[1]->getColumn());
123
        $this->assertEquals("salt", $res->getDetails()[1]->getField());
124
        $this->assertEquals(-1, $res->getDetails()[1]->getAvailable());
125
        $this->assertEquals(0, $res->getDetails()[1]->getAverage());
126
        $this->assertEquals(0, $res->getDetails()[1]->getMinimum());
127
        $this->assertEquals(0, $res->getDetails()[1]->getMaximum());
128
        $this->assertEquals("string", $res->getDetails()[1]->getType());
129
130
        $this->assertEquals("username", $res->getDetails()[2]->getColumn());
131
        $this->assertEquals("username", $res->getDetails()[2]->getField());
132
        $this->assertEquals(-1, $res->getDetails()[2]->getAvailable());
133
        $this->assertEquals(0, $res->getDetails()[2]->getAverage());
134
        $this->assertEquals(0, $res->getDetails()[2]->getMinimum());
135
        $this->assertEquals(0, $res->getDetails()[2]->getMaximum());
136
        $this->assertEquals("string", $res->getDetails()[2]->getType());
137
    }
138
139
    /**
140
     * Test __construct()
141
     *
142
     * @return void
143
     */
144
    public function test__construct(): void {
145
146
        $this->assertEquals("wbw.core.service.repository", RepositoryService::SERVICE_NAME);
147
148
        $obj = new RepositoryService();
149
150
        $this->assertInstanceOf(RepositoryServiceInterface::class, $obj);
151
152
        $this->assertNull($obj->getStatementService());
153
    }
154
}
155