AliceORMContext   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 6
dl 0
loc 53
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A setKernel() 0 17 1
A createSchema() 0 4 1
A dropSchema() 0 4 1
A emptyDatabase() 0 5 1
1
<?php
2
3
/*
4
 * This file is part of the Fidry\AliceBundleExtension package.
5
 *
6
 * (c) Théo FIDRY <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Fidry\AliceBundleExtension\Context\Doctrine;
13
14
use Doctrine\ORM\Tools\SchemaTool;
15
use Symfony\Component\HttpKernel\KernelInterface;
16
17
/**
18
 * Context to load fixtures files with Alice loader.
19
 *
20
 * @author Théo FIDRY <[email protected]>
21
 */
22
class AliceORMContext extends AbstractAliceContext
23
{
24
    /**
25
     * @var SchemaTool
26
     */
27
    private $schemaTool;
28
29
    /**
30
     * {@inheritdoc}
31
     */
32
    public function setKernel(KernelInterface $kernel)
33
    {
34
        $this->init(
35
            $kernel,
36
            $kernel->getContainer()->get('hautelook_alice.doctrine.orm.fixtures_finder'),
37
            $kernel->getContainer()->get('hautelook_alice.fixtures.loader'),
38
            $this->resolvePersister($kernel->getContainer()->get('doctrine.orm.entity_manager'))
39
        );
40
41
        /** @var \Doctrine\ORM\EntityManager $entityManager */
42
        $entityManager = $kernel->getContainer()->get('doctrine.orm.default_entity_manager');
43
44
        $this->schemaTool = new SchemaTool($entityManager);
45
        $this->classes = $entityManager->getMetadataFactory()->getAllMetadata();
46
47
        return $this;
48
    }
49
50
    /**
51
     * {@inheritdoc}
52
     */
53
    public function createSchema()
54
    {
55
        $this->schemaTool->createSchema($this->classes);
56
    }
57
58
    /**
59
     * {@inheritdoc}
60
     */
61
    public function dropSchema()
62
    {
63
        $this->schemaTool->dropSchema($this->classes);
64
    }
65
66
    /**
67
     * {@inheritdoc}
68
     */
69
    public function emptyDatabase()
70
    {
71
        $this->dropSchema();
72
        $this->createSchema();
73
    }
74
}
75