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); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* {@inheritdoc} |
48
|
|
|
*/ |
49
|
|
|
public static function setUpBeforeClass(): void { |
50
|
|
|
parent::setUpBeforeClass(); |
51
|
|
|
|
52
|
|
|
parent::setUpSchemaTool(); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* Tests 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
|
|
|
$this->assertEquals("wbw_core_group", $res[0]->getTable()); |
69
|
|
|
$this->assertEquals(TestGroup::class, $res[0]->getEntity()); |
70
|
|
|
$this->assertEquals(0, $res[0]->getCount()); |
71
|
|
|
|
72
|
|
|
$this->assertCount(1, $res[0]->getDetails()); |
73
|
|
|
|
74
|
|
|
$this->assertEquals("name", $res[0]->getDetails()[0]->getColumn()); |
75
|
|
|
$this->assertEquals("name", $res[0]->getDetails()[0]->getField()); |
76
|
|
|
$this->assertEquals(-1, $res[0]->getDetails()[0]->getAvailable()); |
77
|
|
|
$this->assertEquals(0, $res[0]->getDetails()[0]->getAverage()); |
78
|
|
|
$this->assertEquals(0, $res[0]->getDetails()[0]->getMinimum()); |
79
|
|
|
$this->assertEquals(0, $res[0]->getDetails()[0]->getMaximum()); |
80
|
|
|
|
81
|
|
|
$this->assertEquals("wbw_core_user", $res[1]->getTable()); |
82
|
|
|
$this->assertEquals(TestUser::class, $res[1]->getEntity()); |
83
|
|
|
$this->assertEquals(0, $res[1]->getCount()); |
84
|
|
|
|
85
|
|
|
$this->assertCount(3, $res[1]->getDetails()); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* Tests findOneByEntity() |
90
|
|
|
* |
91
|
|
|
* @return void |
92
|
|
|
* @throws Throwable Throws an exception if an error occurs. |
93
|
|
|
*/ |
94
|
|
|
public function testFindOneByEntity(): void { |
95
|
|
|
|
96
|
|
|
$obj = $this->service; |
97
|
|
|
|
98
|
|
|
$res = $obj->findOneByEntity(TestGroup::class); |
99
|
|
|
|
100
|
|
|
$this->assertEquals("wbw_core_group", $res->getTable()); |
101
|
|
|
$this->assertEquals(TestGroup::class, $res->getEntity()); |
102
|
|
|
$this->assertEquals(0, $res->getCount()); |
103
|
|
|
|
104
|
|
|
$this->assertCount(1, $res->getDetails()); |
105
|
|
|
|
106
|
|
|
$this->assertEquals("name", $res->getDetails()[0]->getColumn()); |
107
|
|
|
$this->assertEquals("name", $res->getDetails()[0]->getField()); |
108
|
|
|
$this->assertEquals(-1, $res->getDetails()[0]->getAvailable()); |
109
|
|
|
$this->assertEquals(0, $res->getDetails()[0]->getAverage()); |
110
|
|
|
$this->assertEquals(0, $res->getDetails()[0]->getMinimum()); |
111
|
|
|
$this->assertEquals(0, $res->getDetails()[0]->getMaximum()); |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
/** |
115
|
|
|
* Tests findOneByTable() |
116
|
|
|
* |
117
|
|
|
* @return void |
118
|
|
|
* @throws Throwable Throws an exception if an error occurs. |
119
|
|
|
*/ |
120
|
|
|
public function testFindOneByTable(): void { |
121
|
|
|
|
122
|
|
|
$obj = $this->service; |
123
|
|
|
|
124
|
|
|
$res = $obj->findOneByTable("wbw_core_user"); |
125
|
|
|
|
126
|
|
|
$this->assertEquals("wbw_core_user", $res->getTable()); |
127
|
|
|
$this->assertEquals(TestUser::class, $res->getEntity()); |
128
|
|
|
$this->assertEquals(0, $res->getCount()); |
129
|
|
|
|
130
|
|
|
$this->assertCount(3, $res->getDetails()); |
131
|
|
|
|
132
|
|
|
$this->assertEquals("password", $res->getDetails()[0]->getColumn()); |
133
|
|
|
$this->assertEquals("password", $res->getDetails()[0]->getField()); |
134
|
|
|
$this->assertEquals(-1, $res->getDetails()[0]->getAvailable()); |
135
|
|
|
$this->assertEquals(0, $res->getDetails()[0]->getAverage()); |
136
|
|
|
$this->assertEquals(0, $res->getDetails()[0]->getMinimum()); |
137
|
|
|
$this->assertEquals(0, $res->getDetails()[0]->getMaximum()); |
138
|
|
|
|
139
|
|
|
$this->assertEquals("salt", $res->getDetails()[1]->getColumn()); |
140
|
|
|
$this->assertEquals("salt", $res->getDetails()[1]->getField()); |
141
|
|
|
$this->assertEquals(-1, $res->getDetails()[1]->getAvailable()); |
142
|
|
|
$this->assertEquals(0, $res->getDetails()[1]->getAverage()); |
143
|
|
|
$this->assertEquals(0, $res->getDetails()[1]->getMinimum()); |
144
|
|
|
$this->assertEquals(0, $res->getDetails()[1]->getMaximum()); |
145
|
|
|
|
146
|
|
|
$this->assertEquals("username", $res->getDetails()[2]->getColumn()); |
147
|
|
|
$this->assertEquals("username", $res->getDetails()[2]->getField()); |
148
|
|
|
$this->assertEquals(-1, $res->getDetails()[2]->getAvailable()); |
149
|
|
|
$this->assertEquals(0, $res->getDetails()[2]->getAverage()); |
150
|
|
|
$this->assertEquals(0, $res->getDetails()[2]->getMinimum()); |
151
|
|
|
$this->assertEquals(0, $res->getDetails()[2]->getMaximum()); |
152
|
|
|
} |
153
|
|
|
|
154
|
|
|
/** |
155
|
|
|
* Tests __construct() |
156
|
|
|
* |
157
|
|
|
* @return void |
158
|
|
|
*/ |
159
|
|
|
public function test__construct(): void { |
160
|
|
|
|
161
|
|
|
$this->assertEquals("wbw.core.service.repository", RepositoryService::SERVICE_NAME); |
162
|
|
|
|
163
|
|
|
$obj = new RepositoryService(); |
164
|
|
|
|
165
|
|
|
$this->assertInstanceOf(RepositoryServiceInterface::class, $obj); |
166
|
|
|
|
167
|
|
|
$this->assertNull($obj->getStatementService()); |
168
|
|
|
} |
169
|
|
|
} |
170
|
|
|
|