File: CompositeKeyRelationsTest.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 (61 lines) | stat: -rw-r--r-- 1,868 bytes parent folder | download | duplicates (3)
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
<?php

declare(strict_types=1);

namespace Doctrine\Tests\ORM\Functional;

use Doctrine\Tests\Models\CompositeKeyRelations\CustomerClass;
use Doctrine\Tests\Models\CompositeKeyRelations\InvoiceClass;
use Doctrine\Tests\OrmFunctionalTestCase;

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

        parent::setUp();
    }

    public function testFindEntityWithNotNullRelation(): void
    {
        $this->_em->getConnection()->insert('CustomerClass', [
            'companyCode' => 'AA',
            'code' => 'CUST1',
            'name' => 'Customer 1',
        ]);

        $this->_em->getConnection()->insert('InvoiceClass', [
            'companyCode' => 'AA',
            'invoiceNumber' => 'INV1',
            'customerCode' => 'CUST1',
        ]);

        $entity = $this->findEntity('AA', 'INV1');
        self::assertSame('AA', $entity->companyCode);
        self::assertSame('INV1', $entity->invoiceNumber);
        self::assertInstanceOf(CustomerClass::class, $entity->customer);
        self::assertSame('Customer 1', $entity->customer->name);
    }

    public function testFindEntityWithNullRelation(): void
    {
        $this->_em->getConnection()->insert('InvoiceClass', [
            'companyCode' => 'BB',
            'invoiceNumber' => 'INV1',
        ]);

        $entity = $this->findEntity('BB', 'INV1');
        self::assertSame('BB', $entity->companyCode);
        self::assertSame('INV1', $entity->invoiceNumber);
        self::assertNull($entity->customer);
    }

    private function findEntity(string $companyCode, string $invoiceNumber): InvoiceClass
    {
        return $this->_em->find(
            InvoiceClass::class,
            ['companyCode' => $companyCode, 'invoiceNumber' => $invoiceNumber],
        );
    }
}