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

CrudsTestCaseTrait::getKernelClasses()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

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