This repository has been archived by the owner on Feb 20, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from cakephp/customize-generate-group
Customize `generate:group`
- Loading branch information
Showing
3 changed files
with
78 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |