Completed
Push — master ( 73634f...8a94ba )
by Philip
02:09
created

LoadFixturesCommand::configure()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
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 6
rs 9.4285
cc 1
eloc 4
nc 1
nop 0
1
<?php
2
3
4
namespace Dontdrinkandroot\Gitki\WebBundle\Command;
5
6
use GitWrapper\GitWrapper;
7
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
8
use Symfony\Component\Console\Input\ArrayInput;
9
use Symfony\Component\Console\Input\InputInterface;
10
use Symfony\Component\Console\Output\OutputInterface;
11
use Symfony\Component\Console\Question\ConfirmationQuestion;
12
use Symfony\Component\Filesystem\Filesystem;
13
14
class LoadFixturesCommand extends ContainerAwareCommand
15
{
16
17
    /**
18
     * {@inheritdoc}
19
     */
20
    protected function configure()
21
    {
22
        $this
23
            ->setName('gitki:fixtures:load')
24
            ->setDescription('Load fixtures as they are used in the tests');
25
    }
26
27
    /**
28
     * {@inheritdoc}
29
     */
30
    protected function execute(InputInterface $input, OutputInterface $output)
31
    {
32
        $doctrineFixturesCommand = $this->getApplication()->find('doctrine:fixtures:load');
33
        $doctrineFixturesCommand->run(new ArrayInput([]), $output);
34
35
        $questionHelper = $this->getHelper('question');
36
        $question = new ConfirmationQuestion('Overwrite repository?', false);
37
        if (!$questionHelper->ask($input, $output, $question)) {
38
            return;
39
        }
40
41
        $repositoryPath = $this->getContainer()->getParameter('repository_path');
42
        $testRepoPath = realPath(__DIR__ . '/../../../var/data/test/repo/');
43
44
        $fileSystem = new Filesystem();
45
        $fileSystem->remove($repositoryPath);
46
47
        $fileSystem->remove($repositoryPath);
48
49
        $fileSystem->mkdir($repositoryPath);
50
        $fileSystem->mirror($testRepoPath, $repositoryPath);
51
52
        $git = new GitWrapper();
53
        $workingCopy = $git->init($repositoryPath);
54
        $workingCopy->add('', ['A' => '']);
55
        $workingCopy->commit('Initial commit');
56
    }
57
}
58