Passed
Pull Request — master (#7459)
by
unknown
08:32
created

GH7458Test::setUp()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 0
dl 0
loc 8
rs 10
c 0
b 0
f 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;
8
use Doctrine\Tests\OrmFunctionalTestCase;
9
10
final class GH7458Test extends OrmFunctionalTestCase
11
{
12
    protected function setUp() : void
13
    {
14
        parent::setup();
15
16
        $this->setUpEntitySchema(
17
            [
18
                GH7458Order::class,
19
                GH7458Item::class,
20
            ]
21
        );
22
    }
23
24
    /**
25
     * @group 7458
26
     */
27
    public function testManagedRelations() : void
28
    {
29
        $order             = new GH7458Order();
30
        $item              = new GH7458Item();
31
        $order->items      = [$item];
32
        $item->order       = $order;
33
        $item->description = uniqid();
0 ignored issues
show
introduced by
Function uniqid() should not be referenced via a fallback global name, but via a use statement.
Loading history...
34
35
        $this->em->persist($order);
36
        $this->em->persist($item);
37
        $this->em->flush();
38
        $this->em->clear();
39
40
        // Target properties for item
41
        $order = null;
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 7 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...
42
        $description = uniqid();
0 ignored issues
show
introduced by
Function uniqid() should not be referenced via a fallback global name, but via a use statement.
Loading history...
43
44
        // Load instance into unit of work and modify properties
45
        $queriedItem1 = $this->em->getUnitOfWork()->getEntityPersister(GH7458Item::class)->load(['id' => $item->id]);
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 14 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...
46
        $queriedItem1->order = $order;
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 7 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...
47
        $queriedItem1->description = $description;
48
49
        // Load instance from unit of work cache
50
        $queriedItem2 = $this->em->getUnitOfWork()->getEntityPersister(GH7458Item::class)->load(['id' => $item->id]);
51
52
        // Should retrieve cached instance without re-hydrating properties
53
        self::assertSame($queriedItem1, $queriedItem2);
54
        self::assertSame($order, $queriedItem2->order);
55
        self::assertSame($description, $queriedItem2->description);
56
    }
57
}
58
59
/**
60
 * @ORM\Entity
61
 */
62
class GH7458Order
63
{
64
    /** @ORM\Id @ORM\Column(type="integer") @ORM\GeneratedValue */
65
    public $id;
66
    /** @ORM\OneToMany(targetEntity=GH7458Item::class, mappedBy="order", fetch="EAGER") */
67
    public $items;
68
}
69
70
/**
71
 * @ORM\Entity
72
 */
73
class GH7458Item
74
{
75
    /** @ORM\Id @ORM\Column(type="integer") @ORM\GeneratedValue */
76
    public $id;
77
    /** @ORM\Column(type="string") */
78
    public $description;
79
    /** @ORM\ManyToOne(targetEntity=GH7458Order::class, inversedBy="items", fetch="EAGER") */
80
    public $order;
81
}
82