Skip to content
This repository has been archived by the owner on Feb 20, 2023. It is now read-only.

Commit

Permalink
Merge pull request #2 from cakephp/customize-generate-group
Browse files Browse the repository at this point in the history
Customize `generate:group`
  • Loading branch information
markstory committed Feb 13, 2015
2 parents 47d8d7b + 3aaf191 commit e20fc7b
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 0 deletions.
40 changes: 40 additions & 0 deletions src/Command/GenerateGroup.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php
namespace Cake\Codeception\Command;

use Cake\Codeception\Lib\Generator\Group as GroupGenerator;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

class GenerateGroup extends \Codeception\Command\GenerateGroup
{
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'] . '/Group/', $class);
$filename = $this->completeSuffix($class, 'Group');
$filename = $path . $filename;

$this->introduceAutoloader(
$config['paths']['tests'] . DIRECTORY_SEPARATOR . $config['settings']['bootstrap'],
'Group',
'Group'
);

$gen = new GroupGenerator($config, $group);
$res = $this->save($filename, $gen->produce());

if (!$res) {
$output->writeln("<error>Group $filename already exists</error>");
return;
}

$msg = [
"<info>Group extension was created in $filename</info>",
'To use this group extension, include it to "extensions" option of global Codeception config.'
];
$output->writeln(implode("\n", $msg));
}
}
1 change: 1 addition & 0 deletions src/Console/Installer.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public static function postAutoloadDump(Event $event)
$needles = [
'Build',
'Bootstrap',
'GenerateGroup'
];

foreach ($needles as $needle) {
Expand Down
37 changes: 37 additions & 0 deletions src/Lib/Generator/Group.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php
namespace Cake\Codeception\Lib\Generator;

use Codeception\Util\Template;

class Group extends \Codeception\Lib\Generator\Group
{
protected $template = <<<EOF
<?php
namespace App\Test\Group;
use Codeception\Event\TestEvent;
use Codeception\Platform\Group;
/**
* Group class is Codeception Extension which is allowed to handle to all internal events.
* This class itself can be used to listen events for test execution of one particular group.
* It may be especially useful to create fixtures data, prepare server, etc.
*
* INSTALLATION:
*
* To use this group extension, include it to "extensions" option of global Codeception config.
*/
class {{class}}Group extends Group
{
public static \$group = '{{name}}';
public function _before(TestEvent \$e)
{
}
public function _after(TestEvent \$e)
{
}
}
EOF;
}

0 comments on commit e20fc7b

Please sign in to comment.