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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<?php
namespace Codeception\Lib\Generator;
use Codeception\Exception\ConfigurationException;
use Codeception\Util\Shared\Namespaces;
use Codeception\Util\Template;
class Cest
{
use Shared\Classname;
use Namespaces;
protected $template = <<<EOF
<?php
{{namespace}}
class {{name}}Cest
{
public function _before({{actor}} \$I)
{
}
public function _after({{actor}} \$I)
{
}
// tests
public function tryToTest({{actor}} \$I)
{
}
}
EOF;
protected $settings;
protected $name;
public function __construct($className, $settings)
{
$this->name = $this->removeSuffix($className, 'Cest');
$this->settings = $settings;
}
public function produce()
{
$actor = $this->settings['actor'];
if (!$actor) {
throw new ConfigurationException("Cept can't be created for suite without an actor. Add `actor: SomeTester` to suite config");
}
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 ($namespace) {
$ns .= "use ".$this->settings['namespace'].'\\'.$actor.";";
}
return (new Template($this->template))
->place('name', $this->getShortClassName($this->name))
->place('namespace', $ns)
->place('actor', $actor)
->produce();
}
}