AliceODMContext   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 4
c 1
b 0
f 1
lcom 1
cbo 4
dl 0
loc 51
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A setKernel() 0 13 1
A createSchema() 0 5 1
A dropSchema() 0 5 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\ODM\MongoDB\SchemaManager;
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 AliceODMContext extends AbstractAliceContext
23
{
24
    /**
25
     * @var SchemaManager
26
     */
27
    private $schemaManager;
28
29
    /**
30
     * {@inheritdoc}
31
     */
32
    public function setKernel(KernelInterface $kernel)
33
    {
34
        $this->init(
35
            $kernel,
36
            $kernel->getContainer()->get('hautelook_alice.doctrine.mongodb.fixtures_finder'),
37
            $kernel->getContainer()->get('hautelook_alice.fixtures.loader'),
38
            $this->resolvePersister($kernel->getContainer()->get('doctrine_mongodb.odm.default_document_manager'))
39
        );
40
41
        $this->schemaManager = $kernel->getContainer()->get('doctrine_mongodb.odm.default_document_manager')->getSchemaManager();
42
43
        return $this;
44
    }
45
46
    /**
47
     * {@inheritdoc}
48
     */
49
    public function createSchema()
50
    {
51
        $this->schemaManager->createCollections();
52
        $this->schemaManager->ensureIndexes();
53
    }
54
55
    /**
56
     * {@inheritdoc}
57
     */
58
    public function dropSchema()
59
    {
60
        $this->schemaManager->deleteIndexes();
61
        $this->schemaManager->dropCollections();
62
    }
63
64
    /**
65
     * {@inheritdoc}
66
     */
67
    public function emptyDatabase()
68
    {
69
        $this->dropSchema();
70
        $this->createSchema();
71
    }
72
}
73