Failed Conditions
Push — master ( 5651e0...3036cd )
by
unknown
07:37
created

AccountingDocumentRepositoryTest   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 23
dl 0
loc 41
rs 10
c 0
b 0
f 0
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 4 1
A testFileOnDiskIsDeletedWhenRecordInDbIsDeleted() 0 23 1
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
12
/**
13
 * @group Repository
14
 */
15
class AccountingDocumentRepositoryTest extends AbstractRepositoryTest
16
{
17
    /**
18
     * @var AccountingDocumentRepository
19
     */
20
    private $repository;
21
22
    /**
23
     * @var ExpenseClaim
24
     */
25
    private $expenseClaim;
0 ignored issues
show
introduced by
The private property $expenseClaim is not used, and could be removed.
Loading history...
26
27
    public function setUp(): void
28
    {
29
        parent::setUp();
30
        $this->repository = _em()->getRepository(AccountingDocument::class);
31
    }
32
33
    public function testFileOnDiskIsDeletedWhenRecordInDbIsDeleted(): void
34
    {
35
        $expenseClaim = new ExpenseClaim();
36
        $document = new AccountingDocument();
37
        $user = new User();
38
39
        $expenseClaim->setOwner($user);
40
        $expenseClaim->setAmount('100');
41
        $expenseClaim->setName('steaks');
42
        $document->setExpenseClaim($expenseClaim);
43
        $document->setFilename('test document.pdf');
44
        $this->getEntityManager()->persist($user);
45
        $this->getEntityManager()->persist($expenseClaim);
46
        $this->getEntityManager()->persist($document);
47
        $this->getEntityManager()->flush();
48
49
        $path = $document->getPath();
50
        touch($path);
51
        self::assertFileExists($path, 'test file must exist, because we just touch()ed it');
52
53
        $this->getEntityManager()->remove($document);
54
        $this->getEntityManager()->flush();
55
        self::assertFileNotExists($path, 'test file must have been deleted when record was deleted');
56
    }
57
}
58