|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Doctrine\Tests\ORM\Functional\Ticket; |
|
4
|
|
|
|
|
5
|
|
|
use Doctrine\Common\Collections\ArrayCollection; |
|
6
|
|
|
|
|
7
|
|
|
/** |
|
8
|
|
|
* @group DDC-2988 |
|
9
|
|
|
*/ |
|
10
|
|
|
class DDC2988Test extends \Doctrine\Tests\OrmFunctionalTestCase |
|
11
|
|
|
{ |
|
12
|
|
|
protected $groups; |
|
13
|
|
|
|
|
14
|
|
|
protected function setUp() |
|
15
|
|
|
{ |
|
16
|
|
|
parent::setUp(); |
|
17
|
|
|
try { |
|
18
|
|
|
$this->_schemaTool->createSchema([ |
|
19
|
|
|
$this->_em->getClassMetadata(DDC2988User::class), |
|
20
|
|
|
$this->_em->getClassMetadata(DDC2988Group::class), |
|
21
|
|
|
]); |
|
22
|
|
|
} catch (\Exception $e) { |
|
23
|
|
|
return; |
|
24
|
|
|
} |
|
25
|
|
|
|
|
26
|
|
|
$group = new DDC2988Group(); |
|
27
|
|
|
$this->_em->persist($group); |
|
28
|
|
|
|
|
29
|
|
|
$user = new DDC2988User(); |
|
30
|
|
|
$user->groups[] = $group; |
|
31
|
|
|
$this->_em->persist($user); |
|
32
|
|
|
|
|
33
|
|
|
$this->_em->flush(); |
|
34
|
|
|
$this->_em->clear(); |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
|
|
38
|
|
|
public function testManyToManyFindBy() |
|
39
|
|
|
{ |
|
40
|
|
|
$userRepository = $this->_em->getRepository(DDC2988User::class); |
|
41
|
|
|
$groupRepository = $this->_em->getRepository(DDC2988Group::class); |
|
42
|
|
|
$groups = $groupRepository->findAll(); |
|
43
|
|
|
$result = $userRepository->findBy(array('groups' => $groups)); |
|
|
|
|
|
|
44
|
|
|
} |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
/** @Entity */ |
|
48
|
|
|
class DDC2988User |
|
49
|
|
|
{ |
|
50
|
|
|
/** @Id @Column(type="integer") @GeneratedValue */ |
|
51
|
|
|
public $id; |
|
52
|
|
|
|
|
53
|
|
|
/** @ManyToMany(targetEntity="DDC2988Group") |
|
54
|
|
|
* @JoinTable(name="users_to_groups", |
|
55
|
|
|
* joinColumns={@JoinColumn(name="user_id", referencedColumnName="id")}, |
|
56
|
|
|
* inverseJoinColumns={@JoinColumn(name="group_id", referencedColumnName="id")} |
|
57
|
|
|
* ) |
|
58
|
|
|
*/ |
|
59
|
|
|
public $groups; |
|
60
|
|
|
|
|
61
|
|
|
public function __contruct() |
|
62
|
|
|
{ |
|
63
|
|
|
$this->groups = new ArrayCollection(); |
|
64
|
|
|
} |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
/** @Entity */ |
|
68
|
|
|
class DDC2988Group |
|
69
|
|
|
{ |
|
70
|
|
|
/** @Id @Column(type="integer") @GeneratedValue */ |
|
71
|
|
|
public $id; |
|
72
|
|
|
} |
|
73
|
|
|
|
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVarassignment in line 1 and the$higherassignment in line 2 are dead. The first because$myVaris never used and the second because$higheris always overwritten for every possible time line.