Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cest generator: suite namespaces #4525

Merged
merged 4 commits into from Sep 28, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 8 additions & 2 deletions src/Codeception/Lib/Generator/Cest.php
Expand Up @@ -48,9 +48,15 @@ public function produce()
throw new ConfigurationException("Cept can't be created for suite without an actor. Add `actor: SomeTester` to suite config");
}

$namespace = rtrim($this->settings['namespace'], '\\');
if (array_key_exists('suite_namespace', $this->settings)) {
$namespace = rtrim($this->settings['suite_namespace'], '\\');
} else {
$namespace = rtrim($this->settings['namespace'], '\\');
}

$ns = $this->getNamespaceHeader($namespace.'\\'.$this->name);
if ($ns) {

if ($namespace) {
$ns .= "use ".$this->settings['namespace'].'\\'.$actor.";";
}

Expand Down
13 changes: 13 additions & 0 deletions tests/unit/Codeception/Command/GenerateCestTest.php
Expand Up @@ -78,4 +78,17 @@ public function testCreateWithNamespace()
$this->assertContains('class HallUnderTheHillCest', $this->content);
$this->assertContains('Test was created in tests/shire/MiddleEarth/HallUnderTheHillCest.php', $this->output);
}

public function testGenerateWithSuiteNamespace()
{
$this->config['suite_namespace'] = 'MiddleEarth\\Bosses\\';
$this->config['namespace'] = 'MiddleEarth';
$this->config['actor'] = 'HobbitGuy';
$this->execute(array('suite' => 'shire', 'class' => 'HallUnderTheHillCest'));
$this->assertEquals($this->filename, 'tests/shire/HallUnderTheHillCest.php');
$this->assertContains('namespace MiddleEarth\\Bosses;', $this->content);
$this->assertContains('use MiddleEarth\\HobbitGuy', $this->content);
$this->assertContains('public function tryToTest(HobbitGuy $I)', $this->content);
$this->assertIsValidPhp($this->content);
}
}