|
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() |
|
12
|
|
|
{ |
|
13
|
|
|
parent::setUp(); |
|
14
|
|
|
|
|
15
|
|
|
$this->_schemaTool->createSchema([ |
|
16
|
|
|
$this->_em->getClassMetadata(GH5763Entity::class), |
|
17
|
|
|
]); |
|
18
|
|
|
} |
|
19
|
|
|
|
|
20
|
|
|
public function testIssue() |
|
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
|
|
|
|