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

GH5998Test::setUp()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 4
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 7
rs 10
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(GH5998Main::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(GH5998Child::class),
0 ignored issues
show
Coding Style introduced by
Array key not indented correctly; expected 16 spaces but found 12
Loading history...
21
            ]
22
        );
23
    }
24
25
    /**
26
     * Verifies that MappedSuperclasses work within a JTI hierarchy.
27
     */
28
    public function testIssue()
29
    {
30
        // Test insert
31
        $child = new GH5998Child('Sam', 0, 1);
32
        $this->em->persist($child);
33
        $this->em->flush();
34
        $this->em->clear();
35
36
        // Test find
37
        $child = $this->em->getRepository(GH5998Child::class)->find(1);
38
        self::assertNotNull($child);
39
40
        // Test lock and update
41
        $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...
42
            $em->lock($child, LockMode::NONE);
43
            $child->firstName = 'Bob';
44
            $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...
45
        });
46
        $this->em->clear();
47
        $child = $this->em->getRepository(GH5998Child::class)->find(1);
48
        self::assertEquals($child->firstName, 'Bob');
49
        self::assertEquals($child->status, 0);
50
51
        // Test delete
52
        $this->em->remove($child);
53
        $this->em->flush();
54
        $child = $this->em->getRepository(GH5998Child::class)->find(1);
55
        self::assertNull($child);
56
    }
57
}
58
59
/**
60
 * @ORM\MappedSuperclass
61
 */
62
class GH5998Common
63
{
64
    /**
65
     * @ORM\Id
66
     * @ORM\Column(type="integer")
67
     * @ORM\GeneratedValue
68
     */
69
    public $id;
70
    /**
0 ignored issues
show
introduced by
Found multi-line comment for property \Doctrine\Tests\ORM\Functional\Ticket\GH5998Common::$status with single line content, use one-line comment instead.
Loading history...
71
     * @ORM\Column(type="integer");
72
     */
73
    public $status;
74
}
75
76
/**
77
 * @ORM\Entity
78
 * @ORM\InheritanceType("JOINED")
79
 * @ORM\DiscriminatorMap({"child" = "Doctrine\Tests\ORM\Functional\Ticket\GH5998Child"})
80
 */
81
abstract class GH5998Main extends GH5998Common
82
{
83
    /**
0 ignored issues
show
introduced by
Found multi-line comment for property \Doctrine\Tests\ORM\Functional\Ticket\GH5998Main::$firstName with single line content, use one-line comment instead.
Loading history...
84
     * @ORM\Column(type="string", length=255);
85
     */
86
    public $firstName;
87
}
88
89
/**
90
 * @ORM\Entity
91
 */
92
class GH5998Child extends GH5998Main
93
{
94
    /**
0 ignored issues
show
introduced by
Found multi-line comment for property \Doctrine\Tests\ORM\Functional\Ticket\GH5998Child::$type with single line content, use one-line comment instead.
Loading history...
95
     * @ORM\Column(type="integer")
96
     */
97
    public $type;
98
    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...
99
    {
100
        $this->firstName = $firstName;
101
        $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...
102
        $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...
103
    }
104
}
105