Failed Conditions
Pull Request — 2.6 (#7506)
by
unknown
09:52
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\ORM\Annotation as ORM;
0 ignored issues
show
Bug introduced by
The type Doctrine\ORM\Annotation was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

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