Completed
Push — 1.9 ( d8eb28...5c3e2e )
by
unknown
61:52 queued 29s
created

getEntityManager()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace OroCRM\Bundle\ActivityContactBundle\Tests\Integration\Command;
4
5
use Doctrine\ORM\EntityManager;
6
7
use Monolog\Registry;
8
9
use Symfony\Bundle\FrameworkBundle\Console\Application;
10
use Symfony\Component\Console\Input\ArrayInput;
11
12
use Oro\Bundle\TestFrameworkBundle\Test\WebTestCase;
13
14
use OroCRM\Bundle\ActivityContactBundle\Command\ActivityContactRecalculateCommand;
15
use OroCRM\Bundle\ContactBundle\Tests\Functional\DataFixtures\LoadContactEntitiesData;
16
use OroCRM\Bundle\DotmailerBundle\Entity\Contact;
17
18
/**
19
 * @outputBuffering enabled
20
 * @dbIsolation
21
 */
22
class ActivityContactRecalculateCommandTest extends WebTestCase
23
{
24
    public function setUp()
25
    {
26
        $this->initClient();
27
        $this->loadFixtures([
28
            'OroCRM\Bundle\ContactBundle\Tests\Functional\DataFixtures\LoadContactEntitiesData',
29
        ]);
30
    }
31
32
    public function testRecalculationOfContactedContactHavingNoActivities()
33
    {
34
        $firstContact = $this->findContact(LoadContactEntitiesData::FIRST_ENTITY_NAME);
35
36
        $firstContact->setAcContactCount(1);
37
        $this->getEntityManager()->flush();
38
        $this->runActivityContactRecalculateCommand();
39
        $firstContact = $this->findContact(LoadContactEntitiesData::FIRST_ENTITY_NAME);
40
41
        $this->assertEquals(0, $firstContact->getAcContactCount());
42
    }
43
44
    protected function runActivityContactRecalculateCommand()
45
    {
46
        $app = new Application($this->getContainer()->get('kernel'));
47
        $app->setAutoExit(false);
48
        $app->run(new ArrayInput([
49
            'command' => ActivityContactRecalculateCommand::COMMAND_NAME,
50
        ]));
51
    }
52
53
    /**
54
     * @param string $firstName
55
     *
56
     * @return Contact
57
     */
58
    protected function findContact($firstName)
59
    {
60
        return $this->getRegistry()->getRepository('OroCRMContactBundle:Contact')->findOneByFirstName($firstName);
0 ignored issues
show
Bug introduced by
The method getRepository() does not seem to exist on object<Monolog\Registry>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
61
    }
62
63
    /**
64
     * @return EntityManager
65
     */
66
    protected function getEntityManager()
67
    {
68
        return $this->getRegistry()->getManager();
0 ignored issues
show
Bug introduced by
The method getManager() does not seem to exist on object<Monolog\Registry>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
69
    }
70
71
    /**
72
     * @return Registry
73
     */
74
    protected function getRegistry()
75
    {
76
        return $this->getContainer()->get('doctrine');
77
    }
78
}
79