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

DDC2692Test::setUp()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 13
Code Lines 8

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 13
rs 9.4285
cc 2
eloc 8
nc 2
nop 0
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