Completed
Pull Request — 2.6 (#7677)
by Arne
08:09
created

GH5763Entity::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 2
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Doctrine\Tests\ORM\Functional\Ticket;
4
5
use Doctrine\ORM\Id\AssignedGenerator;
6
use Doctrine\ORM\Mapping\ClassMetadata;
7
use Doctrine\Tests\OrmFunctionalTestCase;
8
9
class GH5763Test extends OrmFunctionalTestCase
10
{
11
    protected function setUp(): void
12
    {
13
        parent::setUp();
14
15
        $this->_schemaTool->createSchema([
16
            $this->_em->getClassMetadata(GH5763Entity::class),
17
        ]);
18
    }
19
20
    public function testInsertSqlCacheIsBustedOnColumnSetChange()
21
    {
22
        $metaData = $this->_em->getClassMetadata(GH5763Entity::class);
23
24
        list($originalIdGenerator, $originalIdGeneratorType) = [$metaData->idGenerator, $metaData->generatorType];
25
        $metaData->setIdGeneratorType(ClassMetadata::GENERATOR_TYPE_NONE);
26
        $metaData->setIdGenerator(new AssignedGenerator());
27
28
        $firstObject = new GH5763Entity('foo', 10);
29
30
        $this->_em->persist($firstObject);
31
        $this->_em->flush($firstObject);
32
33
        static::assertSame(10, $firstObject->id);
34
35
        list($metaData->idGenerator, $metaData->generatorType) = [$originalIdGenerator, $originalIdGeneratorType];
36
37
        $secondObject = new GH5763Entity('bar');
38
39
        $this->_em->persist($secondObject);
40
        $this->_em->flush($secondObject);
41
42
        $this->assertNotNull($secondObject->id);
43
    }
44
}
45
46
/**
47
 * @Entity()
48
 * @Table()
49
 */
50
class GH5763Entity
51
{
52
    /**
53
     * @Id
54
     * @Column(type="integer")
55
     * @GeneratedValue(strategy="IDENTITY")
56
     */
57
    public $id;
58
59
    /**
60
     * @Column(type="string")
61
     */
62
    public $something;
63
64
    public function __construct($something, $id = null)
65
    {
66
        $this->id        = $id;
67
        $this->something = $something;
68
    }
69
}
70