Completed
Push — master ( 8ce185...772880 )
by Pavel
04:21
created

CrudsTestCaseTrait   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 4

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 3
c 2
b 0
f 0
lcom 2
cbo 4
dl 0
loc 50
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getKernelClasses() 0 7 1
B configureDb() 0 26 1
A setKernelClass() 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
use ScayTrase\Api\Cruds\Tests\Fixtures\JmsSerializer\JmsTestKernel;
9
use ScayTrase\Api\Cruds\Tests\Fixtures\SymfonySerializer\SymfonyTestKernel;
10
use Symfony\Component\HttpKernel\KernelInterface;
11
12
/**
13
 * @method static bootKernel
14
 */
15
trait CrudsTestCaseTrait
16
{
17
    /** @var  string */
18
    static protected $class;
19
    /** @var  KernelInterface */
20
    static protected $kernel;
21
22
    public function getKernelClasses()
23
    {
24
        return [
25
            'kernel with jms serializer'     => [JmsTestKernel::class],
26
            'kernel with symfony serializer' => [SymfonyTestKernel::class],
27
        ];
28
    }
29
30
    /**
31
     * @throws \Doctrine\ORM\Tools\ToolsException
32
     */
33
    protected static function configureDb()
34
    {
35
        static::bootKernel();
36
        /** @var EntityManagerInterface $em */
37
        $em = static::$kernel->getContainer()->get('doctrine.orm.entity_manager');
38
39
        $metadata = $em->getMetadataFactory()->getAllMetadata();
40
        $tool     = new SchemaTool($em);
41
        $tool->dropDatabase();
42
        $tool->createSchema($metadata);
43
        $validator = new SchemaValidator($em);
44
        $errors    = $validator->validateMapping();
45
        static::assertCount(
46
            0,
47
            $errors,
48
            implode(
49
                "\n\n",
50
                array_map(
51
                    function ($l) {
52
                        return implode("\n\n", $l);
53
                    },
54
                    $errors
55
                )
56
            )
57
        );
58
    }
59
60
    protected static function setKernelClass($kernel)
61
    {
62
        self::$class = $kernel;
63
    }
64
}
65