Repository navigation
Expand file tree
/
Copy pathGenerateGroup.php
More file actions
49 lines (40 loc) · 1.7 KB
/
Copy pathGenerateGroup.php
File metadata and controls
49 lines (40 loc) · 1.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<?php
namespace Codeception\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Output\OutputInterface;
use Codeception\Lib\Generator\Group as GroupGenerator;
/**
* Creates empty Group file - extension which handles all group events.
*
* `codecept g:group Admin`
*/
class GenerateGroup extends Base
{
protected function configure()
{
$this->setDefinition(array(
new InputArgument('group', InputArgument::REQUIRED, 'Group class name'),
new InputOption('config', 'c', InputOption::VALUE_OPTIONAL, 'Use custom path for config'),
));
}
public function execute(InputInterface $input, OutputInterface $output)
{
$config = $this->getGlobalConfig($input->getOption('config'));
$group = $input->getArgument('group');
$class = ucfirst($group);
$path = $this->buildPath($config['paths']['tests'].'/_groups/', $class);
$filename = $this->completeSuffix($class, 'Group');
$filename = $path.$filename;
$this->introduceAutoloader($config['paths']['tests'].DIRECTORY_SEPARATOR.$config['settings']['bootstrap'],'Group','_groups');
$gen = new GroupGenerator($config, $group);
$res = $this->save($filename, $gen->produce());
if (!$res) {
$output->writeln("<error>Group $filename already exists</error>");
return;
}
$output->writeln("<info>Group extension was created in $filename</info>");
$output->writeln('To use this group extension, include it to "extensions" option of global Codeception config.');
}
}