Test Failed
Pull Request — master (#6759)
by Jan
63:55
created

BusOwner   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 0
dl 0
loc 27
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A setBus() 0 4 1
1
<?php
2
3
namespace Doctrine\Tests\ORM\Functional;
4
5
use Doctrine\ORM\Tools\SchemaTool;
6
use Doctrine\Tests\OrmFunctionalTestCase;
7
8
class OneToOneInverseSideLoadAfterDqlQueryTest extends OrmFunctionalTestCase
9
{
10
11 View Code Duplication
    protected function setUp()
12
    {
13
        parent::setUp();
14
        $schemaTool = new SchemaTool($this->_em);
15
        try {
16
            $schemaTool->createSchema(
17
                [
18
                    $this->_em->getClassMetadata(Bus::class),
19
                    $this->_em->getClassMetadata(BusOwner::class),
20
                ]
21
            );
22
        } catch(\Exception $e) {}
0 ignored issues
show
Coding Style Comprehensibility introduced by
Consider adding a comment why this CATCH block is empty.
Loading history...
23
    }
24
25
    public function testInverseSideOneToOneLoadedAfterDqlQuery(): void
26
    {
27
        $owner = new BusOwner('Alexander');
28
        $bus = new Bus($owner);
29
30
        $this->_em->persist($bus);
31
        $this->_em->flush();
32
        $this->_em->clear();
33
34
        $bus = $this->_em->createQueryBuilder()
0 ignored issues
show
Unused Code introduced by
$bus is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
35
            ->select('to')
36
            ->from(BusOwner::class, 'to')
37
            ->andWhere('to.id = :id')
38
            ->setParameter('id', $owner->id)
39
            ->getQuery()
40
            ->getResult();
41
42
        $this->assertSQLEquals(
43
            "SELECT b0_.id AS id_0, b0_.name AS name_1 FROM BusOwner b0_ WHERE b0_.id = ?",
44
            $this->_sqlLoggerStack->queries[$this->_sqlLoggerStack->currentQuery - 1]['sql']
45
        );
46
47
        $this->assertSQLEquals(
48
            "SELECT t0.id AS id_1, t0.owner AS owner_2 FROM Bus t0 WHERE t0.owner = ?",
49
            $this->_sqlLoggerStack->queries[$this->_sqlLoggerStack->currentQuery]['sql']
50
        );
51
    }
52
53
}
54
55
56
/**
57
 * @Entity
58
 */
59
class Bus
60
{
61
    /**
62
     * @id @column(type="integer") @generatedValue
63
     * @var int
64
     */
65
    public $id;
66
    /**
67
     * Owning side
68
     * @OneToOne(targetEntity="BusOwner", inversedBy="bus", cascade={"persist"})
69
     * @JoinColumn(nullable=false, name="owner")
70
     */
71
    public $owner;
72
73
    public function __construct(BusOwner $owner)
74
    {
75
        $this->owner = $owner;
76
    }
77
78
}
79
80
/**
81
 * @Entity
82
 */
83
class BusOwner
84
{
85
    /**
86
     * @Id
87
     * @Column(type="integer")
88
     * @GeneratedValue
89
     */
90
    public $id;
91
92
    /** @column(type="string") */
93
    public $name;
94
    /**
95
     * Inverse side
96
     * @OneToOne(targetEntity="Bus", mappedBy="owner")
97
     */
98
    public $bus;
99
100
    public function __construct($name)
101
    {
102
        $this->name = $name;
103
    }
104
105
    public function setBus(Bus $t)
106
    {
107
        $this->bus = $t;
108
    }
109
}
110