TestHelper   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 13
c 2
b 0
f 0
dl 0
loc 25
rs 10
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A seedFixtures() 0 14 3
A createTestDb() 0 7 1
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