Skip to content

Commit fe02965

Browse files
author
davert
committed
namespacing Guy classes
1 parent b783194 commit fe02965

6 files changed

Lines changed: 26 additions & 13 deletions

File tree

‎src/Codeception/Codecept.php‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ class Codecept
4848
'colors' => false,
4949
'log' => true,
5050
'coverage' => false,
51-
'defer-flush' => false
51+
'defer-flush' => false,
52+
'group' => null
5253
);
5354

5455
public function __construct($options = array()) {

‎src/Codeception/Command/Build.php‎

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ class Build extends Base
1919
// You can change it manually, but it will be overwritten on next build
2020
// @codingStandardsIgnoreFile
2121
22-
use Codeception\Maybe;
22+
%s
23+
use \Codeception\Maybe;
2324
%s
2425
2526
%s %s extends %s
@@ -166,13 +167,15 @@ protected function execute(InputInterface $input, OutputInterface $output)
166167
$aliases[] = implode("\n",$inherited);
167168
$aliases[] = '*/';
168169

170+
$namespace = $this->getNamespaceString($suiteconf['namespace']);
169171

170172
$contents = sprintf($this->template,
171-
implode("\n", $aliases),
172-
'class',
173-
$settings['class_name'],
174-
'\Codeception\AbstractGuy',
175-
implode("\n\n ", $code));
173+
$namespace,
174+
implode("\n", $aliases),
175+
'class',
176+
$settings['class_name'],
177+
'\Codeception\AbstractGuy',
178+
implode("\n\n ", $code));
176179

177180
file_put_contents($file = $settings['path'].$settings['class_name'].'.php', $contents);
178181
$output->writeln("$file generated successfully. $methodCounter methods added");

‎src/Codeception/Command/GenerateCept.php‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
class GenerateCept extends Base
1313
{
14-
protected $template = "<?php\n\$I = new %s(\$scenario);\n\$I->wantTo('perform actions and see result');\n";
14+
protected $template = "<?php%s\n\$I = new %s(\$scenario);\n\$I->wantTo('perform actions and see result');\n";
1515

1616
protected function configure()
1717
{
@@ -35,8 +35,10 @@ public function execute(InputInterface $input, OutputInterface $output)
3535
$config = \Codeception\Configuration::config($input->getOption('config'));
3636
$suiteconf = \Codeception\Configuration::suiteSettings($suite, $config);
3737

38+
$namespace = $this->getNamespaceString($suiteconf['namespace']);
39+
3840
$guy = $suiteconf['class_name'];
39-
$file = sprintf($this->template, $guy);
41+
$file = sprintf($this->template, $namespace, $guy);
4042
$filename = $this->completeSuffix($filename, 'Cept');
4143
$this->buildPath($suiteconf['path'], $filename);
4244

‎src/Codeception/Configuration.php‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,14 +101,16 @@ public static function suiteSettings($suite, $config)
101101
if (!in_array($suite, self::$suites)) throw new \Exception("Suite $suite was not loaded");
102102

103103
$defaults = array(
104+
'namespace' => null,
104105
'class_name' => 'NoGuy',
105106
'modules' => isset($config['modules']) ? $config['modules'] : array(),
106107
'bootstrap' => '_bootstrap.php',
107108
'suite_class' => '\PHPUnit_Framework_TestSuite',
108109
'colors' => true,
109110
'memory_limit' => '1024M',
110111
'path' => '',
111-
'error_level' => 'E_ALL & ~E_STRICT & ~E_DEPRECATED'
112+
'error_level' => 'E_ALL & ~E_STRICT & ~E_DEPRECATED',
113+
'includes' => array()
112114
);
113115

114116
$globalConf = $config['settings'];

‎src/Codeception/SuiteManager.php‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,18 @@ class SuiteManager {
2929

3030
protected $settings = array();
3131

32-
public function __construct(EventDispatcher $dispatcher, $name, $settings) {
32+
public function __construct(EventDispatcher $dispatcher, $name, $settings)
33+
{
3334
$this->settings = $settings;
3435
$this->dispatcher = $dispatcher;
3536
$this->suite = $this->createSuite($name);
3637
$this->path = $settings['path'];
37-
if ($settings['bootstrap']) $this->settings['bootstrap'] = $this->path . $settings['bootstrap'];
3838

39+
if ($settings['bootstrap']) $this->settings['bootstrap'] = $this->path . $settings['bootstrap'];
3940
if (!file_exists($settings['path'] . $settings['class_name'].'.php')) {
4041
throw new Exception\Configuration($settings['class_name'] . " class doesn't exists in suite folder.\nRun the 'build' command to generate it");
4142
}
43+
4244
require_once $settings['path'] . $settings['class_name'].'.php';
4345

4446
$this->initializeModules($settings);
@@ -148,7 +150,8 @@ public function loadTest($path) {
148150

149151
public function loadTests()
150152
{
151-
$finder = Finder::create()->files()->sortByName()->in($this->path);
153+
$dirs = array_merge($this->path, $this->settings['includes']);
154+
$finder = Finder::create()->files()->sortByName()->in($dirs);
152155
$ceptFinder = clone($finder);
153156
$testFiles = $ceptFinder->name('*Cept.php');
154157
foreach ($testFiles as $test) {

‎tests/cli/GenerateCeptCept.php‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
<?php
2+
namespace frontend;
3+
24
$I = new CliGuy($scenario);
35
$I->wantTo('generate sample Cept');
46
$I->amInPath('tests/data/sandbox');

0 commit comments

Comments
 (0)