|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace ApplicationTest\Repository; |
|
6
|
|
|
|
|
7
|
|
|
use Application\DBAL\Types\AccountTypeType; |
|
8
|
|
|
use Application\Model\Account; |
|
9
|
|
|
use Application\Model\User; |
|
10
|
|
|
use Application\Repository\AccountRepository; |
|
11
|
|
|
use ApplicationTest\Traits\LimitedAccessSubQuery; |
|
12
|
|
|
use Doctrine\DBAL\Exception\UniqueConstraintViolationException; |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* @group Repository |
|
16
|
|
|
*/ |
|
17
|
|
|
class AccountRepositoryTest extends AbstractRepositoryTest |
|
18
|
|
|
{ |
|
19
|
|
|
use LimitedAccessSubQuery; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* @var AccountRepository |
|
23
|
|
|
*/ |
|
24
|
|
|
private $repository; |
|
25
|
|
|
|
|
26
|
|
|
public function setUp(): void |
|
27
|
|
|
{ |
|
28
|
|
|
parent::setUp(); |
|
29
|
|
|
$this->repository = _em()->getRepository(Account::class); |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
public function providerGetAccessibleSubQuery(): array |
|
33
|
|
|
{ |
|
34
|
|
|
$all = [ |
|
35
|
|
|
10000, 10001, 10002, 10003, 10004, 10005, 10006, 10007, 10008, 10009, 10010, 10011, 10013, 10014, 10015, |
|
36
|
|
|
10016, 10017, 10018, 10019, 10020, 10021, 10022, 10023, 10024, 10025, 10026, 10027, 10028, 10029, 10030, |
|
37
|
|
|
10031, 10032, 10033, 10034, 10035, 10036, 10037, 10038, 10039, 10040, 10041, 10042, 10043, 10044, 10045, |
|
38
|
|
|
10046, 10047, 10048, 10049, 10050, 10051, 10052, 10053, 10054, 10055, 10057, 10058, 10059, 10060, 10061, |
|
39
|
|
|
10062, 10063, 10064, 10065, 10066, 10067, 10068, 10069, 10070, 10071, 10072, 10073, 10074, 10075, 10076, |
|
40
|
|
|
10077, 10078, 10079, 10080, 10081, 10082, 10083, 10084, 10085, 10086, 10087, 10088, 10089, 10090, 10091, |
|
41
|
|
|
10092, 10093, 10094, 10095, 10096, 10097, 10098, 10099, 10100, 10101, 10102, 10103, |
|
42
|
|
|
]; |
|
43
|
|
|
|
|
44
|
|
|
return [ |
|
45
|
|
|
['anonymous', []], |
|
46
|
|
|
['bookingonly', []], |
|
47
|
|
|
['individual', [10097]], |
|
48
|
|
|
['member', [10096]], |
|
49
|
|
|
['responsible', $all], |
|
50
|
|
|
['administrator', $all], |
|
51
|
|
|
]; |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
public function testOneUserCanHaveOnlyOneAccount(): void |
|
55
|
|
|
{ |
|
56
|
|
|
$this->expectException(UniqueConstraintViolationException::class); |
|
57
|
|
|
$this->getEntityManager()->getConnection()->insert('account', ['owner_id' => 1000, 'iban' => uniqid()]); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
public function testGetOrCreate(): void |
|
61
|
|
|
{ |
|
62
|
|
|
$user = new User(); |
|
63
|
|
|
$user->setFirstName('Foo'); |
|
64
|
|
|
$user->setLastName('Bar'); |
|
65
|
|
|
|
|
66
|
|
|
$account = $this->repository->getOrCreate($user); |
|
67
|
|
|
|
|
68
|
|
|
self::assertSame($user, $account->getOwner()); |
|
69
|
|
|
self::assertSame('Foo Bar', $account->getName()); |
|
70
|
|
|
self::assertSame(AccountTypeType::LIABILITY, $account->getType()); |
|
71
|
|
|
self::assertSame('20300009', $account->getCode()); |
|
72
|
|
|
self::assertSame('Acomptes de clients', $account->getParent()->getName()); |
|
73
|
|
|
} |
|
74
|
|
|
} |
|
75
|
|
|
|