1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace ApplicationTest\Repository; |
6
|
|
|
|
7
|
|
|
use Application\Model\Statistic; |
8
|
|
|
use Application\Model\User; |
9
|
|
|
use Application\Repository\StatisticRepository; |
10
|
|
|
use InvalidArgumentException; |
11
|
|
|
|
12
|
|
|
class StatisticRepositoryTest extends AbstractRepositoryTest |
13
|
|
|
{ |
14
|
|
|
private StatisticRepository $repository; |
15
|
|
|
|
16
|
|
|
protected function setUp(): void |
17
|
|
|
{ |
18
|
|
|
parent::setUp(); |
19
|
|
|
$this->repository = _em()->getRepository(Statistic::class); |
20
|
|
|
} |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @dataProvider providerGetExtraStatistics |
24
|
|
|
*/ |
25
|
|
|
public function testGetExtraStatistics(string $site, string $poeriod, ?int $userId): void |
26
|
|
|
{ |
27
|
|
|
$user = $userId ? $this->getEntityManager()->getRepository(User::class)->getOneById($userId) : null; |
28
|
|
|
$actual = $this->repository->getExtraStatistics($site, $poeriod, $user); |
29
|
|
|
|
30
|
|
|
$keys = ['cardCreation', 'cardUpdate', 'userCreation', 'userUpdate']; |
31
|
|
|
self::assertSame($keys, array_keys($actual)); |
32
|
|
|
foreach ($keys as $key) { |
33
|
|
|
$one = $actual[$key]; |
34
|
|
|
self::assertSame(['tables', 'chart'], array_keys($one)); |
35
|
|
|
|
36
|
|
|
foreach ($one['tables'] as $table) { |
37
|
|
|
self::assertSame(['name', 'rows'], array_keys($table)); |
38
|
|
|
|
39
|
|
|
foreach ($table['rows'] as $row) { |
40
|
|
|
self::assertSame(['name', 'value'], array_keys($row)); |
41
|
|
|
} |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
self::assertSame(['name', 'categories', 'series'], array_keys($one['chart'])); |
45
|
|
|
|
46
|
|
|
foreach ($one['chart']['series'] as $serie) { |
47
|
|
|
self::assertSame(['name', 'data'], array_keys($serie)); |
48
|
|
|
} |
49
|
|
|
} |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
public function providerGetExtraStatistics(): iterable |
53
|
|
|
{ |
54
|
|
|
yield ['dilps', 'month', null]; |
55
|
|
|
yield ['dilps', 'all', null]; |
56
|
|
|
yield ['dilps', '2019', null]; |
57
|
|
|
yield ['tiresias', 'month', 1000]; |
58
|
|
|
yield ['tiresias', 'all', 1000]; |
59
|
|
|
yield ['tiresias', '2019', 1000]; |
60
|
|
|
yield ['tir\'asd"esias', '2019', 1000]; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* @dataProvider providerGetExtraStatisticsException |
65
|
|
|
*/ |
66
|
|
|
public function testGetExtraStatisticsException(string $site, string $period, ?int $userId): void |
67
|
|
|
{ |
68
|
|
|
$this->expectException(InvalidArgumentException::class); |
69
|
|
|
|
70
|
|
|
$user = $userId ? $this->getEntityManager()->getRepository(User::class)->getOneById($userId) : null; |
71
|
|
|
$this->repository->getExtraStatistics($site, $period, $user); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
public function providerGetExtraStatisticsException(): iterable |
75
|
|
|
{ |
76
|
|
|
yield ['tiresias', '20asd\'1"9', 1000]; |
77
|
|
|
yield ['tiresias', 'bbb', 1000]; |
78
|
|
|
} |
79
|
|
|
} |
80
|
|
|
|