Completed
Pull Request — master (#7825)
by
unknown
09:24
created

GH5998Test::setUp()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 1
eloc 5
nc 1
nop 0
dl 0
loc 8
rs 10
c 2
b 0
f 0
1
<?php
2
declare(strict_types=1);
0 ignored issues
show
introduced by
Expected 2 newlines between PHP open tag and declare statement, found 1.
Loading history...
3
4
namespace Doctrine\Tests\ORM\Functional\Ticket;
0 ignored issues
show
introduced by
Expected 1 lines after namespace statement, found 0.
Loading history...
5
use Doctrine\ORM\Annotation as ORM;
0 ignored issues
show
introduced by
Expected 1 lines before first use statement, found 0.
Loading history...
6
use Doctrine\DBAL\LockMode;
0 ignored issues
show
Coding Style introduced by
Use statements should be sorted alphabetically. The first wrong one is Doctrine\DBAL\LockMode.
Loading history...
7
use Doctrine\Tests\OrmFunctionalTestCase;
8
9
/**
10
 * @group GH-5998
11
 */
12
class GH5998Test extends OrmFunctionalTestCase
13
{
14
    protected function setUp(): void
0 ignored issues
show
introduced by
There must be exactly 1 whitespace between closing parenthesis and return type colon.
Loading history...
15
    {
16
        parent::setUp();
17
        $this->schemaTool->createSchema(
18
            [
19
            $this->em->getClassMetadata(GH5998JTI::class),
0 ignored issues
show
Coding Style introduced by
Array key not indented correctly; expected 16 spaces but found 12
Loading history...
20
            $this->em->getClassMetadata(GH5998JTIChild::class),
0 ignored issues
show
Coding Style introduced by
Array key not indented correctly; expected 16 spaces but found 12
Loading history...
21
            $this->em->getClassMetadata(GH5998STI::class),
0 ignored issues
show
Coding Style introduced by
Array key not indented correctly; expected 16 spaces but found 12
Loading history...
22
            ]
23
        );
24
    }
25
26
    /**
27
     * Verifies that MappedSuperclasses work within an inheritance hierarchy.
28
     */
29
    public function testIssue()
30
    {
31
        // Test JTI
32
        $this->testClass(GH5998JTIChild::class);
33
        // Test STI
34
        $this->testClass(GH5998STIChild::class);
35
    }
36
37
    private function testClass($className) {
38
        // Test insert
39
        $child = new $className('Sam', 0, 1);
40
        $this->em->persist($child);
41
        $this->em->flush();
42
        $this->em->clear();
43
44
        // Test find
45
        $child = $this->em->getRepository($className)->find(1);
46
        self::assertNotNull($child);
47
48
        // Test lock and update
49
        $this->em->transactional(function($em) use ($child) {
0 ignored issues
show
Coding Style introduced by
Expected 1 space after FUNCTION keyword; 0 found
Loading history...
introduced by
Closure not using "$this" should be declared static.
Loading history...
50
            $em->lock($child, LockMode::NONE);
51
            $child->firstName = 'Bob';
52
            $child->status = 0;
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 4 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
53
        });
54
        $this->em->clear();
55
        $child = $this->em->getRepository($className)->find(1);
56
        self::assertEquals($child->firstName, 'Bob');
57
        self::assertEquals($child->status, 0);
58
59
        // Test delete
60
        $this->em->remove($child);
61
        $this->em->flush();
62
        $child = $this->em->getRepository($className)->find(1);
63
        self::assertNull($child);
64
    }
65
}
66
67
/**
68
 * @ORM\MappedSuperclass
69
 */
70
class GH5998Common
71
{
72
    /**
73
     * @ORM\Id
74
     * @ORM\Column(type="integer")
75
     * @ORM\GeneratedValue
76
     */
77
    public $id;
78
}
79
80
/**
81
 * @ORM\Entity
82
 * @ORM\InheritanceType("JOINED")
83
 * @ORM\DiscriminatorMap({"child" = "Doctrine\Tests\ORM\Functional\Ticket\GH5998JTIChild"})
84
 */
85
abstract class GH5998JTI extends GH5998Common
86
{
87
    /**
0 ignored issues
show
introduced by
Found multi-line comment for property \Doctrine\Tests\ORM\Functional\Ticket\GH5998JTI::$firstName with single line content, use one-line comment instead.
Loading history...
88
     * @ORM\Column(type="string", length=255);
89
     */
90
    public $firstName;
91
}
92
93
/**
94
 * @ORM\MappedSuperclass
95
 */
96
class GH5998JTICommon extends GH5998JTI
97
{
98
    /**
0 ignored issues
show
introduced by
Found multi-line comment for property \Doctrine\Tests\ORM\Functional\Ticket\GH5998JTICommon::$status with single line content, use one-line comment instead.
Loading history...
99
     * @ORM\Column(type="integer");
100
     */
101
    public $status;
102
}
103
104
/**
105
 * @ORM\Entity
106
 */
107
class GH5998JTIChild extends GH5998JTICommon
108
{
109
    /**
0 ignored issues
show
introduced by
Found multi-line comment for property \Doctrine\Tests\ORM\Functional\Ticket\GH5998JTIChild::$type with single line content, use one-line comment instead.
Loading history...
110
     * @ORM\Column(type="integer")
111
     */
112
    public $type;
113
    function __construct(string $firstName, int $type, int $status)
0 ignored issues
show
Comprehensibility Best Practice introduced by
It is recommend to declare an explicit visibility for __construct.

Generally, we recommend to declare visibility for all methods in your source code. This has the advantage of clearly communication to other developers, and also yourself, how this method should be consumed.

If you are not sure which visibility to choose, it is a good idea to start with the most restrictive visibility, and then raise visibility as needed, i.e. start with private, and only raise it to protected if a sub-class needs to have access, or public if an external class needs access.

Loading history...
Coding Style introduced by
Expected 1 blank line before function; 0 found
Loading history...
114
    {
115
        $this->firstName = $firstName;
116
        $this->type = $type;
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 6 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
117
        $this->status = $status;
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 4 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
118
    }
119
}
120
121
/**
122
 * @ORM\Entity
123
 * @ORM\InheritanceType("SINGLE_TABLE")
124
 * @ORM\DiscriminatorMap({"child" = "Doctrine\Tests\ORM\Functional\Ticket\GH5998STIChild"})
125
 */
126
abstract class GH5998STI extends GH5998Common
127
{
128
    /**
0 ignored issues
show
introduced by
Found multi-line comment for property \Doctrine\Tests\ORM\Functional\Ticket\GH5998STI::$firstName with single line content, use one-line comment instead.
Loading history...
129
     * @ORM\Column(type="string", length=255);
130
     */
131
    public $firstName;
132
}
133
134
/**
135
 * @ORM\MappedSuperclass
136
 */
137
class GH5998STICommon extends GH5998STI
138
{
139
    /**
0 ignored issues
show
introduced by
Found multi-line comment for property \Doctrine\Tests\ORM\Functional\Ticket\GH5998STICommon::$status with single line content, use one-line comment instead.
Loading history...
140
     * @ORM\Column(type="integer");
141
     */
142
    public $status;
143
}
144
145
/**
146
 * @ORM\Entity
147
 */
148
class GH5998STIChild extends GH5998STICommon
149
{
150
    /**
0 ignored issues
show
introduced by
Found multi-line comment for property \Doctrine\Tests\ORM\Functional\Ticket\GH5998STIChild::$type with single line content, use one-line comment instead.
Loading history...
151
     * @ORM\Column(type="integer")
152
     */
153
    public $type;
154
    function __construct(string $firstName, int $type, int $status)
0 ignored issues
show
Comprehensibility Best Practice introduced by
It is recommend to declare an explicit visibility for __construct.

Generally, we recommend to declare visibility for all methods in your source code. This has the advantage of clearly communication to other developers, and also yourself, how this method should be consumed.

If you are not sure which visibility to choose, it is a good idea to start with the most restrictive visibility, and then raise visibility as needed, i.e. start with private, and only raise it to protected if a sub-class needs to have access, or public if an external class needs access.

Loading history...
Coding Style introduced by
Expected 1 blank line before function; 0 found
Loading history...
155
    {
156
        $this->firstName = $firstName;
157
        $this->type = $type;
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 6 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
158
        $this->status = $status;
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 4 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
159
    }
160
}
161