Completed
Push — master ( 9e29b7...c3d8ab )
by Yaroslav
19:31
created

DataBaseDumpManager::load()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
namespace Utils;
4
5
use Symfony\Component\Process\Process;
6
7
class DataBaseDumpManager
8
{
9
    /**
10
     * @var string
11
     */
12
    private $rootDir;
13
14
    /**
15
     * @param string $rootDir
16
     */
17
    public function __construct($rootDir)
18
    {
19
        $this->rootDir = $rootDir;
20
    }
21
22
    /**
23
     * @return string|null
24
     */
25
    public function dump()
26
    {
27
        $output = $this->runBin('test-database-dump', uniqid('', true));
28
29
        if (preg_match('/ to \'(?<file>.+)\'$/', $output, $matches)) {
30
            return $matches['file'];
31
        }
32
33
        throw new \RuntimeException("Can't create database dump");
34
    }
35
36
    /**
37
     * @param $dumpFile
38
     */
39
    public function load($dumpFile)
40
    {
41
        $this->runBin('test-database-import', $dumpFile);
42
    }
43
44
    /**
45
     * @param string $bin
46
     * @param string $args
47
     * @return string
48
     */
49
    private function runBin($bin, $args)
50
    {
51
        $process = new Process(sprintf('%s/bin/%s %s', $this->rootDir, $bin, $args));
52
        $process->run();
53
54
        return $process->getOutput();
55
    }
56
}
57