File: CompositePrimaryKeyWithAssociationsTest.php

package info (click to toggle)
doctrine 3.5.1%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 11,552 kB
  • sloc: php: 108,302; xml: 1,340; makefile: 35; sh: 14
file content (64 lines) | stat: -rw-r--r-- 1,845 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<?php

declare(strict_types=1);

namespace Doctrine\Tests\ORM\Functional;

use Doctrine\Tests\Models\GeoNames\Admin1;
use Doctrine\Tests\Models\GeoNames\Admin1AlternateName;
use Doctrine\Tests\Models\GeoNames\Country;
use Doctrine\Tests\OrmFunctionalTestCase;

class CompositePrimaryKeyWithAssociationsTest extends OrmFunctionalTestCase
{
    protected function setUp(): void
    {
        $this->useModelSet('geonames');

        parent::setUp();

        $it = new Country('IT', 'Italy');

        $this->_em->persist($it);
        $this->_em->flush();

        $admin1 = new Admin1(1, 'Rome', $it);

        $this->_em->persist($admin1);
        $this->_em->flush();

        $name1 = new Admin1AlternateName(1, 'Roma', $admin1);
        $name2 = new Admin1AlternateName(2, 'Rome', $admin1);

        $admin1->names[] = $name1;
        $admin1->names[] = $name2;

        $this->_em->persist($admin1);
        $this->_em->persist($name1);
        $this->_em->persist($name2);

        $this->_em->flush();

        $this->_em->clear();
    }

    public function testFindByAbleToGetCompositeEntitiesWithMixedTypeIdentifiers(): void
    {
        $admin1Repo      = $this->_em->getRepository(Admin1::class);
        $admin1NamesRepo = $this->_em->getRepository(Admin1AlternateName::class);

        $admin1Rome = $admin1Repo->findOneBy(['country' => 'IT', 'id' => 1]);

        $names = $admin1NamesRepo->findBy(['admin1' => $admin1Rome]);
        self::assertCount(2, $names);

        $name1 = $admin1NamesRepo->findOneBy(['admin1' => $admin1Rome, 'id' => 1]);
        $name2 = $admin1NamesRepo->findOneBy(['admin1' => $admin1Rome, 'id' => 2]);

        self::assertEquals(1, $name1->id);
        self::assertEquals('Roma', $name1->name);

        self::assertEquals(2, $name2->id);
        self::assertEquals('Rome', $name2->name);
    }
}