|
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 __construct() |
|
90
|
|
|
* |
|
91
|
|
|
* @return void |
|
92
|
|
|
*/ |
|
93
|
|
|
public function test__construct(): void { |
|
94
|
|
|
|
|
95
|
|
|
$this->assertEquals("wbw.core.service.repository", RepositoryService::SERVICE_NAME); |
|
96
|
|
|
|
|
97
|
|
|
$obj = new RepositoryService(); |
|
98
|
|
|
|
|
99
|
|
|
$this->assertInstanceOf(RepositoryServiceInterface::class, $obj); |
|
100
|
|
|
|
|
101
|
|
|
$this->assertNull($obj->getStatementService()); |
|
102
|
|
|
} |
|
103
|
|
|
} |
|
104
|
|
|
|