|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Oro\Bundle\TestGeneratorBundle\Generator; |
|
4
|
|
|
|
|
5
|
|
|
class FunctionalTestGenerator extends AbstractTestGenerator |
|
6
|
|
|
{ |
|
7
|
|
|
/** |
|
8
|
|
|
* @param string $className |
|
9
|
|
|
*/ |
|
10
|
|
|
public function generate($className) |
|
11
|
|
|
{ |
|
12
|
|
|
$this->usedClasses[] = 'Oro\Bundle\TestFrameworkBundle\Test\WebTestCase'; |
|
13
|
|
|
$fullTestNameSpace = $this->getNamespaceForTest($className, 'functional'); |
|
14
|
|
|
$parts = explode('\\', $fullTestNameSpace); |
|
15
|
|
|
$testClassName = array_pop($parts); |
|
16
|
|
|
$partsOfOriginClass = explode('\\', $className); |
|
17
|
|
|
$testedClassName = array_pop($partsOfOriginClass); |
|
18
|
|
|
$nameSpace = implode('\\', $parts); |
|
19
|
|
|
$testPath = $this->getTestPath($fullTestNameSpace); |
|
20
|
|
|
$class = new \ReflectionClass($className); |
|
21
|
|
|
$methodsData = $this->getMethodsData($class); |
|
22
|
|
|
$orderedUses = $this->getOrderedUses($this->usedClasses); |
|
23
|
|
|
$content = $this->twig->render( |
|
24
|
|
|
'@OroTestGenerator/Tests/functional_template.php.twig', |
|
25
|
|
|
[ |
|
26
|
|
|
'namespace' => $nameSpace, |
|
27
|
|
|
'vendors' => $orderedUses, |
|
28
|
|
|
'className' => $testClassName, |
|
29
|
|
|
'testedClassName' => $testedClassName, |
|
30
|
|
|
'testedClassNameVariable' => lcfirst($testedClassName), |
|
31
|
|
|
'methodsData' => $methodsData |
|
32
|
|
|
] |
|
33
|
|
|
); |
|
34
|
|
|
$this->createFile($testPath, $content); |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* @param \ReflectionClass $class |
|
40
|
|
|
* @return array |
|
41
|
|
|
*/ |
|
42
|
|
|
protected function getMethodsData(\ReflectionClass $class) |
|
43
|
|
|
{ |
|
44
|
|
|
$data = []; |
|
45
|
|
|
$methods = $this->getPublicMethods($class); |
|
46
|
|
|
foreach ($methods as $method) { |
|
47
|
|
|
$methodName = $method->getName(); |
|
48
|
|
|
if ($methodName !== '__construct') { |
|
49
|
|
|
$data[] = [ |
|
50
|
|
|
'name' => $methodName, |
|
51
|
|
|
'testName' => 'test' . ucfirst($methodName) |
|
52
|
|
|
]; |
|
53
|
|
|
} |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
return $data; |
|
57
|
|
|
} |
|
58
|
|
|
} |
|
59
|
|
|
|