Completed
Push — master ( e32eeb...714cda )
by
unknown
89:50 queued 46:29
created

CreateTestCommand::configure()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 16
Code Lines 12

Duplication

Lines 16
Ratio 100 %
Metric Value
dl 16
loc 16
rs 9.4285
cc 1
eloc 12
nc 1
nop 0
1
<?php
2
3
namespace Oro\Bundle\TestGeneratorBundle\Command;
4
5
use Symfony\Component\Console\Input\InputArgument;
6
use Symfony\Component\Console\Input\InputInterface;
7
use Symfony\Component\Console\Output\OutputInterface;
8
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
9
10
class CreateTestCommand extends ContainerAwareCommand
11
{
12
    const NAME = 'oro:generate:test';
13
14
    /**
15
     * {@inheritdoc}
16
     */
17 View Code Duplication
    protected function configure()
18
    {
19
        $this
20
            ->setName(self::NAME)
21
            ->setDescription('Create Test')
22
            ->addArgument(
23
                'class',
24
                InputArgument::REQUIRED,
25
                'Full qualified class name or path to php file'
26
            )
27
            ->addArgument(
28
                'type',
29
                InputArgument::REQUIRED,
30
                'Test type. Supported types are: unit, entity, functional'
31
            );
32
    }
33
34
    /**
35
     * {@inheritdoc}
36
     */
37
    protected function execute(InputInterface $input, OutputInterface $output)
38
    {
39
        $type = $input->getArgument('type');
40
        if (!in_array($type, ['unit', 'entity', 'functional'], true)) {
41
            throw new \InvalidArgumentException(
42
                sprintf('Type "%s" is not known. Supported types are: unit, entity, functional', $type)
43
            );
44
        }
45
46
        $generator = $this->getContainer()->get('oro_test_generator.generator.test.' . $type);
47
        $class = $input->getArgument('class');
48
        if (strpos($class, '\\') === false) {
49
            $class = str_replace('.php', '', $class);
50
            $class = str_replace('/', '\\', substr($class, strripos($class, '/src/') + 5));
51
        }
52
        $generator->generate($class);
53
        $output->writeln('<info>Test was generated successful</info>');
54
    }
55
}
56