File: InsertableUpdatableTest.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 (65 lines) | stat: -rw-r--r-- 1,900 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
65
<?php

declare(strict_types=1);

namespace Doctrine\Tests\ORM\Functional;

use Doctrine\Tests\Models\Upsertable\Insertable;
use Doctrine\Tests\Models\Upsertable\Updatable;
use Doctrine\Tests\OrmFunctionalTestCase;

class InsertableUpdatableTest extends OrmFunctionalTestCase
{
    protected function setUp(): void
    {
        parent::setUp();

        $this->createSchemaForModels(Updatable::class, Insertable::class);
    }

    public function testNotInsertableIsFetchedFromDatabase(): void
    {
        $insertable                    = new Insertable();
        $insertable->insertableContent = 'abcdefg';

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

        // gets inserted from default value and fetches value from database
        self::assertEquals('1234', $insertable->nonInsertableContent);

        $insertable->nonInsertableContent = '5678';

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

        $insertable = $this->_em->find(Insertable::class, $insertable->id);

        // during UPDATE statement it is not ignored
        self::assertEquals('5678', $insertable->nonInsertableContent);
    }

    public function testNotUpdatableIsFetched(): void
    {
        $updatable                      = new Updatable();
        $updatable->updatableContent    = 'foo';
        $updatable->nonUpdatableContent = 'foo';

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

        $updatable->updatableContent    = 'bar';
        $updatable->nonUpdatableContent = 'baz';

        $this->_em->flush();

        self::assertEquals('foo', $updatable->nonUpdatableContent);

        $this->_em->clear();

        $cleanUpdatable = $this->_em->find(Updatable::class, $updatable->id);

        self::assertEquals('bar', $cleanUpdatable->updatableContent);
        self::assertEquals('foo', $cleanUpdatable->nonUpdatableContent);
    }
}