Completed
Pull Request — master (#5823)
by Mikhail
13:41
created

DDC2692Test   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5
Metric Value
wmc 3
lcom 1
cbo 5
dl 0
loc 33
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A testIsListenerCalledOnlyOnceOnPreFlush() 0 13 1
A setUp() 0 13 2
1
<?php
2
3
namespace Doctrine\Tests\ORM\Functional\Ticket;
4
5
use Doctrine\Common\EventSubscriber;
6
use Doctrine\ORM\Event\PreFlushEventArgs;
7
8
/**
9
 * @group DDC-2692
10
 */
11
class DDC2692Test extends \Doctrine\Tests\OrmFunctionalTestCase
12
{
13
    /**
14
     * {@inheritDoc}
15
     */
16
    protected function setUp()
17
    {
18
        parent::setUp();
19
20
        try {
21
            $this->_schemaTool->createSchema(array(
22
                $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC2692Foo'),
23
            ));
24
        } catch(\Exception $e) {
25
            return;
26
        }
27
        $this->_em->clear();
28
    }
29
30
    public function testIsListenerCalledOnlyOnceOnPreFlush()
31
    {
32
        $listener = $this->getMock('Doctrine\Tests\ORM\Functional\Ticket\DDC2692Listener', array('preFlush'));
33
        $listener->expects($this->once())->method('preFlush');
34
35
        $this->_em->getEventManager()->addEventSubscriber($listener);
36
37
        $this->_em->persist(new DDC2692Foo);
38
        $this->_em->persist(new DDC2692Foo);
39
40
        $this->_em->flush();
41
        $this->_em->clear();
42
    }
43
}
44
/**
45
 * @Entity @Table(name="ddc_2692_foo")
46
 */
47
class DDC2692Foo
48
{
49
    /** @Id @Column(type="integer") @GeneratedValue */
50
    public $id;
51
}
52
53
class DDC2692Listener implements EventSubscriber {
54
55
    public function getSubscribedEvents() {
56
        return array(\Doctrine\ORM\Events::preFlush);
57
    }
58
59
    public function preFlush(PreFlushEventArgs $args) {
0 ignored issues
show
Unused Code introduced by
The parameter $args is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
60
    }
61
}
62