Test Failed
Pull Request — master (#1307)
by Ilya
61:40
created

DDC2988Test   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
c 1
b 0
f 0
lcom 1
cbo 6
dl 0
loc 36
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 22 2
A testManyToManyFindBy() 0 7 1
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));
0 ignored issues
show
Unused Code introduced by
$result 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...
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