testFileOnDiskIsDeletedWhenRecordInDbIsDeleted()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 23
Code Lines 18

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 18
nc 1
nop 0
dl 0
loc 23
rs 9.6666
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
use Money\Money;
13
14
class AccountingDocumentRepositoryTest extends AbstractRepositoryTest
15
{
16
    use LimitedAccessSubQuery;
17
18
    private AccountingDocumentRepository $repository;
19
20
    protected function setUp(): void
21
    {
22
        parent::setUp();
23
        $this->repository = $this->getEntityManager()->getRepository(AccountingDocument::class);
24
    }
25
26
    public function providerGetAccessibleSubQuery(): iterable
27
    {
28
        $all = [9000, 9001];
29
        yield ['anonymous', []];
30
        yield ['bookingonly', []];
31
        yield ['individual', [9000]];
32
        yield ['member', [9000]];
33
        yield ['responsible', $all];
34
        yield ['administrator', $all];
35
    }
36
37
    public function testFileOnDiskIsDeletedWhenRecordInDbIsDeleted(): void
38
    {
39
        $expenseClaim = new ExpenseClaim();
40
        $document = new AccountingDocument();
41
        $user = new User();
42
43
        $expenseClaim->setOwner($user);
44
        $expenseClaim->setAmount(Money::CHF(10000));
45
        $expenseClaim->setName('steaks');
46
        $document->setExpenseClaim($expenseClaim);
47
        $document->setFilename('test document.pdf');
48
        $this->getEntityManager()->persist($user);
49
        $this->getEntityManager()->persist($expenseClaim);
50
        $this->getEntityManager()->persist($document);
51
        $this->getEntityManager()->flush();
52
53
        $path = $document->getPath();
54
        touch($path);
55
        self::assertFileExists($path, 'test file must exist, because we just touch()ed it');
56
57
        $this->getEntityManager()->remove($document);
58
        $this->getEntityManager()->flush();
59
        self::assertFileDoesNotExist($path, 'test file must have been deleted when record was deleted');
60
    }
61
}
62