Completed
Push — master ( 8717d0...8ea879 )
by Philip
25:16
created

LoadFixturesCommand::execute()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 29

Duplication

Lines 0
Ratio 0 %

Importance

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