AliceODMContext::dropSchema()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 5
rs 9.4285
cc 1
eloc 3
nc 1
nop 0
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