Completed
Pull Request — master (#457)
by Alejandro
06:50
created

TestHelper::seedFixtures()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 14
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
eloc 8
dl 0
loc 14
rs 10
c 0
b 0
f 0
ccs 0
cts 9
cp 0
cc 3
nc 3
nop 2
crap 12
1
<?php
2
declare(strict_types=1);
3
4
namespace Shlinkio\Shlink\TestUtils\Helper;
5
6
use Doctrine\Common\DataFixtures\Executor\ORMExecutor;
7
use Doctrine\Common\DataFixtures\Loader;
8
use Doctrine\Common\DataFixtures\Purger\ORMPurger;
9
use Doctrine\ORM\EntityManagerInterface;
10
use Symfony\Component\Process\Process;
11
12
class TestHelper
13
{
14
    public function createTestDb(): void
15
    {
16
        $process = new Process(['vendor/bin/doctrine', 'orm:schema-tool:drop', '--force', '--no-interaction', '-q']);
17
        $process->inheritEnvironmentVariables()
18
                ->mustRun();
19
20
        $process = new Process(['vendor/bin/doctrine', 'orm:schema-tool:create', '--no-interaction', '-q']);
21
        $process->inheritEnvironmentVariables()
22
                ->mustRun();
23
    }
24
25
    public function seedFixtures(EntityManagerInterface $em, array $config): void
26
    {
27
        $paths = $config['paths'] ?? [];
28
        if (empty($paths)) {
29
            return;
30
        }
31
32
        $loader = new Loader();
33
        foreach ($paths as $path) {
34
            $loader->loadFromDirectory($path);
35
        }
36
37
        $executor = new ORMExecutor($em, new ORMPurger());
38
        $executor->execute($loader->getFixtures());
39
    }
40
}
41