Failed Conditions
Push — master ( 977552...4856db )
by Adrien
12:24
created

providerGetAccessibleSubQuery()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 8
nc 1
nop 0
dl 0
loc 11
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace ApplicationTest\Repository;
6
7
use Application\Model\AccountingDocument;
8
use Application\Model\ExpenseClaim;
9
use Application\Model\User;
10
use Application\Repository\AccountingDocumentRepository;
11
use ApplicationTest\Traits\LimitedAccessSubQuery;
12
13
/**
14
 * @group Repository
15
 */
16
class AccountingDocumentRepositoryTest extends AbstractRepositoryTest
17
{
18
    use LimitedAccessSubQuery;
19
20
    /**
21
     * @var AccountingDocumentRepository
22
     */
23
    private $repository;
24
25
    public function setUp(): void
26
    {
27
        parent::setUp();
28
        $this->repository = _em()->getRepository(AccountingDocument::class);
29
    }
30
31
    public function providerGetAccessibleSubQuery(): array
32
    {
33
        $all = [9000];
34
35
        return [
36
            ['anonymous', []],
37
            ['bookingonly', []],
38
            ['individual', []],
39
            ['member', [9000]],
40
            ['responsible', $all],
41
            ['administrator', $all],
42
        ];
43
    }
44
45
    public function testFileOnDiskIsDeletedWhenRecordInDbIsDeleted(): void
46
    {
47
        $expenseClaim = new ExpenseClaim();
48
        $document = new AccountingDocument();
49
        $user = new User();
50
51
        $expenseClaim->setOwner($user);
52
        $expenseClaim->setAmount('100');
53
        $expenseClaim->setName('steaks');
54
        $document->setExpenseClaim($expenseClaim);
55
        $document->setFilename('test document.pdf');
56
        $this->getEntityManager()->persist($user);
57
        $this->getEntityManager()->persist($expenseClaim);
58
        $this->getEntityManager()->persist($document);
59
        $this->getEntityManager()->flush();
60
61
        $path = $document->getPath();
62
        touch($path);
63
        self::assertFileExists($path, 'test file must exist, because we just touch()ed it');
64
65
        $this->getEntityManager()->remove($document);
66
        $this->getEntityManager()->flush();
67
        self::assertFileNotExists($path, 'test file must have been deleted when record was deleted');
68
    }
69
}
70