Passed
Pull Request — master (#17)
by Pavel
10:33
created

AbstractDbAwareTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 7

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 7
dl 0
loc 45
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 5 1
B configureDb() 0 25 1
A getEntityManager() 0 4 1
1
<?php
2
3
namespace ScayTrase\Api\Cruds\Tests;
4
5
use Doctrine\ORM\EntityManagerInterface;
6
use Doctrine\ORM\Tools\SchemaTool;
7
use Doctrine\ORM\Tools\SchemaValidator;
8
9
abstract class AbstractDbAwareTest extends AbstractCrudsWebTest
10
{
11
    public function setUp()
12
    {
13
        parent::setUp();
14
        self::configureDb();
15
    }
16
17
    /**
18
     * @throws \Doctrine\ORM\Tools\ToolsException
19
     */
20
    protected static function configureDb()
21
    {
22
        /** @var EntityManagerInterface $em */
23
        $em = self::getEntityManager();
24
25
        $metadata = $em->getMetadataFactory()->getAllMetadata();
26
        $tool     = new SchemaTool($em);
27
        $tool->dropDatabase();
28
        $tool->createSchema($metadata);
29
        $validator = new SchemaValidator($em);
30
        $errors    = $validator->validateMapping();
31
        static::assertCount(
32
            0,
33
            $errors,
34
            implode(
35
                "\n\n",
36
                array_map(
37
                    function ($l) {
38
                        return implode("\n\n", $l);
39
                    },
40
                    $errors
41
                )
42
            )
43
        );
44
    }
45
46
    /**
47
     * @return EntityManagerInterface|object
48
     */
49
    protected static function getEntityManager()
50
    {
51
        return self::$kernel->getContainer()->get('doctrine.orm.entity_manager');
52
    }
53
}
54