|
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; |
|
|
|
|
|
|
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
|
|
|
|