TestHelper::seedFixtures()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 14
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

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