ExportRepositoryTest::getCardCount()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 3
dl 0
loc 6
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace ApplicationTest\Repository;
6
7
use Application\Enum\Site;
8
use Application\Model\Export;
9
use Application\Model\User;
10
use Application\Repository\ExportRepository;
11
use Application\Repository\UserRepository;
12
13
class ExportRepositoryTest extends AbstractRepositoryTest
14
{
15
    private ExportRepository $repository;
16
17
    protected function setUp(): void
18
    {
19
        parent::setUp();
20
        $this->repository = $this->getEntityManager()->getRepository(Export::class);
21
    }
22
23
    public function testUpdateCards(): void
24
    {
25
        /** @var UserRepository $userRepository */
26
        $userRepository = _em()->getRepository(User::class);
27
        User::setCurrent($userRepository->getOneByLogin('administrator', Site::Dilps));
28
29
        /** @var Export $export1 */
30
        $export1 = $this->getEntityManager()->getReference(Export::class, 14000);
31
32
        /** @var Export $export2 */
33
        $export2 = $this->getEntityManager()->getReference(Export::class, 14001);
34
35
        self::assertSame($export1->getCardCount(), $this->getCardCount($export1), 'fixture should be coherent');
36
        self::assertSame($export2->getCardCount(), $this->getCardCount($export2), 'fixture should be coherent');
37
38
        self::assertSame(1, $this->repository->updateCards($export1, [], [6000]), 'should not change with same values');
39
40
        self::assertSame(2, $this->repository->updateCards($export2, [2001], []), 'should not change with same values');
41
42
        self::assertSame(3, $this->repository->updateCards($export1, [], [6000, 6001, 6003]), 'can add more cards to hand-picked cards');
43
44
        self::assertSame(4, $this->repository->updateCards($export2, [2001], [6007, 6008]), 'can add more cards to collection');
45
    }
46
47
    private function getCardCount(Export $export): int
48
    {
49
        $connection = $this->getEntityManager()->getConnection();
50
        $cardCount = $connection->fetchOne('SELECT COUNT(*) FROM export_card WHERE export_id = :export', ['export' => $export->getId()]);
51
52
        return (int) $cardCount;
53
    }
54
}
55