1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace MageTest\PhpSpec\MagentoExtension\CodeGenerator\Generator; |
4
|
|
|
|
5
|
|
|
use PhpSpec\CodeGenerator\Generator\PromptingGenerator; |
6
|
|
|
use PhpSpec\CodeGenerator\Generator\Generator as GeneratorInterface; |
7
|
|
|
use PhpSpec\Locator\Resource as ResourceInterface; |
8
|
|
|
|
9
|
|
|
class ControllerSpecificationGenerator extends PromptingGenerator implements GeneratorInterface |
10
|
|
|
{ |
11
|
|
|
/** |
12
|
|
|
* @param ResourceInterface $resource |
13
|
|
|
* @param string $generation |
14
|
|
|
* @param array $data |
15
|
|
|
* @return bool |
16
|
|
|
*/ |
17
|
|
|
public function supports(ResourceInterface $resource, $generation, array $data) |
18
|
|
|
{ |
19
|
|
|
return 'controller_specification' === $generation; |
20
|
|
|
} |
21
|
|
|
|
22
|
|
|
public function getPriority() |
23
|
|
|
{ |
24
|
|
|
return 0; |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @param ResourceInterface $resource |
29
|
|
|
* |
30
|
|
|
* @return string |
31
|
|
|
*/ |
32
|
|
|
protected function getFilePath(ResourceInterface $resource) |
33
|
|
|
{ |
34
|
|
|
return $resource->getSpecFilename(); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @param ResourceInterface $resource |
39
|
|
|
* @param string $filepath |
40
|
|
|
* |
41
|
|
|
* @return string |
42
|
|
|
*/ |
43
|
|
|
protected function renderTemplate(ResourceInterface $resource, $filepath) |
44
|
|
|
{ |
45
|
|
|
$values = array( |
46
|
|
|
'%filepath%' => $filepath, |
47
|
|
|
'%name%' => $resource->getSpecName(), |
48
|
|
|
'%namespace%' => $resource->getSpecNamespace(), |
49
|
|
|
'%subject%' => $resource->getSrcClassname() |
50
|
|
|
); |
51
|
|
|
|
52
|
|
|
if (!$content = $this->getTemplateRenderer()->render('controller_specification', $values)) { |
53
|
|
|
$content = $this->getTemplateRenderer()->renderString( |
54
|
|
|
file_get_contents(__DIR__ . '/templates/controller_spec.template'), $values |
55
|
|
|
); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
return $content; |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* @param ResourceInterface $resource |
63
|
|
|
* @param string $filepath |
64
|
|
|
* |
65
|
|
|
* @return string |
66
|
|
|
*/ |
67
|
|
|
protected function getGeneratedMessage(ResourceInterface $resource, $filepath) |
68
|
|
|
{ |
69
|
|
|
sprintf( |
70
|
|
|
"<info>ControllerSpecification for <value>%s</value> created in <value>'%s'</value>.</info>\n", |
71
|
|
|
$resource->getSrcClassname(), |
72
|
|
|
$filepath |
73
|
|
|
); |
74
|
|
|
} |
75
|
|
|
} |
76
|
|
|
|