1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Doctrine\Tests\ORM\Functional\Ticket; |
6
|
|
|
|
7
|
|
|
use Doctrine\Tests\OrmFunctionalTestCase; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* @group GH7505 |
11
|
|
|
*/ |
12
|
|
|
final class GH7505Test extends OrmFunctionalTestCase |
13
|
|
|
{ |
14
|
|
|
/** |
15
|
|
|
* {@inheritDoc} |
16
|
|
|
*/ |
17
|
|
|
protected function setUp() : void |
18
|
|
|
{ |
19
|
|
|
parent::setUp(); |
20
|
|
|
|
21
|
|
|
$this->setUpEntitySchema([ |
22
|
|
|
GH7505AbstractResponse::class, |
23
|
|
|
GH7505ArrayResponse::class, |
24
|
|
|
GH7505TextResponse::class, |
25
|
|
|
]); |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
public function testSimpleArrayTypeHydratedCorrectly() : void |
29
|
|
|
{ |
30
|
|
|
$arrayResponse = new GH7505ArrayResponse(); |
31
|
|
|
$this->_em->persist($arrayResponse); |
32
|
|
|
|
33
|
|
|
$textResponse = new GH7505TextResponse(); |
34
|
|
|
$this->_em->persist($textResponse); |
35
|
|
|
|
36
|
|
|
$this->_em->flush(); |
37
|
|
|
$this->_em->clear(); |
38
|
|
|
|
39
|
|
|
$repository = $this->_em->getRepository(GH7505AbstractResponse::class); |
40
|
|
|
|
41
|
|
|
/** @var GH7505ArrayResponse $arrayResponse */ |
42
|
|
|
$arrayResponse = $repository->find($arrayResponse->id); |
43
|
|
|
self::assertSame([], $arrayResponse->value); |
44
|
|
|
|
45
|
|
|
/** @var GH7505TextResponse $textResponse */ |
46
|
|
|
$textResponse = $repository->find($textResponse->id); |
47
|
|
|
self::assertNull($textResponse->value); |
48
|
|
|
} |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @Entity() |
53
|
|
|
* @Table(name="gh7505_responses") |
54
|
|
|
* @InheritanceType("SINGLE_TABLE") |
55
|
|
|
* @DiscriminatorColumn(name="discr", type="string") |
56
|
|
|
* @DiscriminatorMap({ |
57
|
|
|
* "array" = GH7505ArrayResponse::class, |
58
|
|
|
* "text" = GH7505TextResponse::class, |
59
|
|
|
* }) |
60
|
|
|
*/ |
61
|
|
|
abstract class GH7505AbstractResponse |
62
|
|
|
{ |
63
|
|
|
/** |
64
|
|
|
* @Id @GeneratedValue |
65
|
|
|
* @Column(type="integer") |
66
|
|
|
*/ |
67
|
|
|
public $id; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* @Entity() |
72
|
|
|
*/ |
73
|
|
|
class GH7505ArrayResponse extends GH7505AbstractResponse |
74
|
|
|
{ |
75
|
|
|
/** |
76
|
|
|
* @Column(name="value_array", type="simple_array") |
77
|
|
|
* @var array |
78
|
|
|
*/ |
79
|
|
|
public $value = []; |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* @Entity() |
84
|
|
|
*/ |
85
|
|
|
class GH7505TextResponse extends GH7505AbstractResponse |
86
|
|
|
{ |
87
|
|
|
/** |
88
|
|
|
* @Column(name="value_string", type="string") |
89
|
|
|
* @var string|null |
90
|
|
|
*/ |
91
|
|
|
public $value; |
92
|
|
|
} |
93
|
|
|
|