Failed Conditions
Pull Request — 2.6 (#7882)
by
unknown
06:31
created

textExtraUpdateWithDatabaseGeneratedId()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 16
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 10
c 1
b 0
f 0
dl 0
loc 16
rs 9.9332
cc 1
nc 1
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Doctrine\Tests\ORM\Functional;
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
class SelfReferencingTest extends OrmFunctionalTestCase
11
{
12
    protected function setUp() : void
13
    {
14
        parent::setUp();
15
        try {
16
            $classMetadatas = [
17
                $this->em->getClassMetadata(Issue7877ApplicationGenerated::class),
0 ignored issues
show
Bug Best Practice introduced by
The property em does not exist on Doctrine\Tests\ORM\Functional\SelfReferencingTest. Did you maybe forget to declare it?
Loading history...
18
                $this->em->getClassMetadata(Issue7877DatabaseGenerated::class),
19
            ];
20
            // We first drop the schema to avoid collision between tests
21
            $this->schemaTool->dropSchema($classMetadatas);
0 ignored issues
show
Bug introduced by
The property schemaTool does not exist on Doctrine\Tests\ORM\Functional\SelfReferencingTest. Did you mean _schemaTool?
Loading history...
22
            $this->schemaTool->createSchema($classMetadatas);
23
        } catch (Exception $e) {
0 ignored issues
show
Bug introduced by
The type Doctrine\Tests\ORM\Functional\Exception was not found. Did you mean Exception? If so, make sure to prefix the type with \.
Loading history...
Coding Style Comprehensibility introduced by
Consider adding a comment why this CATCH block is empty.
Loading history...
24
        }
25
    }
26
27
    public function providerDifferentEntity()
28
    {
29
        yield [Issue7877ApplicationGenerated::class];
30
        yield [Issue7877DatabaseGenerated::class];
31
    }
32
33
    /**
34
     * @dataProvider providerDifferentEntity
35
     */
36
    public function testExtraUpdateWithDifferentEntities(string $class)
37
    {
38
        $count = \count($this->sqlLoggerStack->queries);
0 ignored issues
show
Bug introduced by
The property sqlLoggerStack does not exist on Doctrine\Tests\ORM\Functional\SelfReferencingTest. Did you mean _sqlLoggerStack?
Loading history...
39
40
        $parent = new $class($parentId = 1);
41
        $this->em->persist($parent);
0 ignored issues
show
Bug Best Practice introduced by
The property em does not exist on Doctrine\Tests\ORM\Functional\SelfReferencingTest. Did you maybe forget to declare it?
Loading history...
42
43
        $child         = new $class($childId = 2);
44
        $child->parent = $parent;
45
        $this->em->persist($child);
46
47
        $this->em->flush();
48
        $this->assertCount($count + 4, $this->sqlLoggerStack->queries);
49
50
        $this->em->clear();
51
52
        $child = $this->em->find($class, $childId);
53
        $this->assertSame($parentId, $child->parent->id);
54
    }
55
56
    public function testNoExtraUpdateWithApplicationGeneratedId()
57
    {
58
        $count = \count($this->sqlLoggerStack->queries);
0 ignored issues
show
Bug introduced by
The property sqlLoggerStack does not exist on Doctrine\Tests\ORM\Functional\SelfReferencingTest. Did you mean _sqlLoggerStack?
Loading history...
59
60
        $entity         = new Issue7877ApplicationGenerated($entityId = 1);
61
        $entity->parent = $entity;
62
        $this->em->persist($entity);
0 ignored issues
show
Bug Best Practice introduced by
The property em does not exist on Doctrine\Tests\ORM\Functional\SelfReferencingTest. Did you maybe forget to declare it?
Loading history...
63
64
        $this->em->flush();
65
        $this->assertCount($count + 3, $this->sqlLoggerStack->queries);
66
67
        $this->em->clear();
68
69
        $child = $this->em->find(Issue7877ApplicationGenerated::class, $entityId);
70
        $this->assertSame($entityId, $child->parent->id);
71
    }
72
73
    public function textExtraUpdateWithDatabaseGeneratedId()
74
    {
75
        $count = \count($this->sqlLoggerStack->queries);
0 ignored issues
show
Bug introduced by
The property sqlLoggerStack does not exist on Doctrine\Tests\ORM\Functional\SelfReferencingTest. Did you mean _sqlLoggerStack?
Loading history...
76
77
        $entity         = new Issue7877DatabaseGenerated();
78
        $entity->parent = $entity;
79
        $this->em->persist($entity);
0 ignored issues
show
Bug Best Practice introduced by
The property em does not exist on Doctrine\Tests\ORM\Functional\SelfReferencingTest. Did you maybe forget to declare it?
Loading history...
80
81
        $this->em->flush();
82
        $this->assertCount($count + 4, $this->sqlLoggerStack->queries);
83
        $entityId = $entity->id;
84
85
        $this->em->clear();
86
87
        $child = $this->em->find(Issue7877DatabaseGenerated::class, $entityId);
88
        $this->assertSame($entityId, $child->paren->id);
89
    }
90
}
91
92
/**
93
 * @ORM\Entity
94
 */
95
class Issue7877ApplicationGenerated
96
{
97
    public function __construct(int $id)
98
    {
99
        $this->id = $id;
100
    }
101
102
    /**
103
     * @ORM\Id
104
     * @ORM\Column(type="integer")
105
     * @ORM\GeneratedValue(strategy="NONE")
106
     */
107
    public $id;
108
109
    /**
110
     * @ORM\ManyToOne(targetEntity="Doctrine\Tests\ORM\Functional\Issue7877ApplicationGenerated")
111
     */
112
    public $parent;
113
}
114
115
/**
116
 * @ORM\Entity
117
 */
118
class Issue7877DatabaseGenerated
119
{
120
    /**
121
     * @ORM\Id
122
     * @ORM\Column(type="integer")
123
     * @ORM\GeneratedValue(strategy="AUTO")
124
     */
125
    public $id;
126
127
    /**
128
     * @ORM\ManyToOne(targetEntity="Doctrine\Tests\ORM\Functional\Issue7877DatabaseGenerated")
129
     */
130
    public $parent;
131
}
132