|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace ApplicationTest\Repository; |
|
6
|
|
|
|
|
7
|
|
|
use Application\Enum\Site; |
|
8
|
|
|
use Application\Model\Card; |
|
9
|
|
|
use Application\Model\Export; |
|
10
|
|
|
use Application\Repository\CardRepository; |
|
11
|
|
|
|
|
12
|
|
|
class CardRepositoryTest extends AbstractRepositoryTest |
|
13
|
|
|
{ |
|
14
|
|
|
private CardRepository $repository; |
|
15
|
|
|
|
|
16
|
|
|
protected function setUp(): void |
|
17
|
|
|
{ |
|
18
|
|
|
parent::setUp(); |
|
19
|
|
|
$this->repository = _em()->getRepository(Card::class); |
|
20
|
|
|
} |
|
21
|
|
|
|
|
22
|
|
|
public function testCardOnDiskIsDeletedWhenRecordInDbIsDeleted(): void |
|
23
|
|
|
{ |
|
24
|
|
|
$card = new Card('test card'); |
|
25
|
|
|
|
|
26
|
|
|
$card->setSite(Site::Dilps); |
|
27
|
|
|
$card->setFilename('test card.jpg'); |
|
28
|
|
|
$this->getEntityManager()->persist($card); |
|
29
|
|
|
$this->getEntityManager()->flush(); |
|
30
|
|
|
|
|
31
|
|
|
touch($card->getPath()); |
|
32
|
|
|
self::assertFileExists($card->getPath(), 'test file must exist, because we just touch()ed it'); |
|
33
|
|
|
|
|
34
|
|
|
$this->getEntityManager()->remove($card); |
|
35
|
|
|
$this->getEntityManager()->flush(); |
|
36
|
|
|
self::assertFileDoesNotExist($card->getPath(), 'test file must have been deleted when record was deleted'); |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
public function testGetExportCards(): void |
|
40
|
|
|
{ |
|
41
|
|
|
$export1 = $this->getEntityManager()->getReference(Export::class, 14000); |
|
42
|
|
|
self::assertCount(1, $this->repository->getExportCards($export1, 0)); |
|
|
|
|
|
|
43
|
|
|
self::assertCount(0, $this->repository->getExportCards($export1, 6000)); |
|
44
|
|
|
|
|
45
|
|
|
$export2 = $this->getEntityManager()->getReference(Export::class, 14001); |
|
46
|
|
|
self::assertCount(2, $this->repository->getExportCards($export2, 0)); |
|
47
|
|
|
self::assertCount(1, $this->repository->getExportCards($export2, 6001)); |
|
48
|
|
|
self::assertCount(0, $this->repository->getExportCards($export2, 6002)); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
public function testCachedArtistNames(): void |
|
52
|
|
|
{ |
|
53
|
|
|
$this->assertArtistNames('Test artist 3000 |
|
54
|
|
|
Test artist 3001'); |
|
55
|
|
|
|
|
56
|
|
|
$connection = $this->getEntityManager()->getConnection(); |
|
57
|
|
|
$connection->executeStatement("UPDATE artist SET name = 'foo' WHERE id = 3000"); |
|
58
|
|
|
$this->assertArtistNames('foo |
|
59
|
|
|
Test artist 3001'); |
|
60
|
|
|
|
|
61
|
|
|
$connection->executeStatement('DELETE FROM card_artist WHERE artist_id = 3000'); |
|
62
|
|
|
$this->assertArtistNames('Test artist 3001'); |
|
63
|
|
|
|
|
64
|
|
|
$connection->executeStatement('INSERT INTO card_artist (card_id, artist_id) VALUES (6000, 3000)'); |
|
65
|
|
|
$this->assertArtistNames('foo |
|
66
|
|
|
Test artist 3001'); |
|
67
|
|
|
|
|
68
|
|
|
$connection->executeStatement('DELETE FROM artist WHERE id = 3001'); |
|
69
|
|
|
$this->assertArtistNames('foo'); |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
private function assertArtistNames(string $name): void |
|
73
|
|
|
{ |
|
74
|
|
|
self::assertSame($name, $this->getEntityManager()->getConnection()->fetchOne('SELECT cached_artist_names FROM card WHERE id = 6000')); |
|
75
|
|
|
} |
|
76
|
|
|
} |
|
77
|
|
|
|