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
70
71
72
73
74
75
76
<?php
namespace Codeception\Lib\Generator;
use Codeception\Configuration;
use Codeception\Util\Shared\Namespaces;
use Codeception\Util\Template;
class Test
{
use Namespaces;
use Shared\Classname;
protected $template = <<<EOF
<?php
{{namespace}}
class {{name}}Test extends \Codeception\Test\Unit
{
{{tester}}
protected function _before()
{
}
protected function _after()
{
}
// tests
public function testSomeFeature()
{
}
}
EOF;
protected $testerTemplate = <<<EOF
/**
* @var \{{actorClass}}
*/
protected \${{actor}};
EOF;
protected $settings;
protected $name;
public function __construct($settings, $name)
{
$this->settings = $settings;
$this->name = $this->removeSuffix($name, 'Test');
}
public function produce()
{
$actor = $this->settings['actor'];
if ($this->settings['namespace']) {
$actor = $this->settings['namespace'] . '\\' . $actor;
}
$ns = $this->getNamespaceHeader($this->settings['namespace'] . '\\' . $this->name);
$tester = '';
if ($this->settings['actor']) {
$tester = (new Template($this->testerTemplate))
->place('actorClass', $actor)
->place('actor', lcfirst(Configuration::config()['actor_suffix']))
->produce();
}
return (new Template($this->template))
->place('namespace', $ns)
->place('name', $this->getShortClassName($this->name))
->place('tester', $tester)
->produce();
}
}