Completed
Pull Request — 2.7 (#7974)
by Benjamin
08:15
created

GH7505Test::setUp()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

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