|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Oro\Bundle\TestGeneratorBundle\Generator; |
|
4
|
|
|
|
|
5
|
|
|
class UnitTestGenerator extends AbstractTestGenerator |
|
6
|
|
|
{ |
|
7
|
|
|
/** |
|
8
|
|
|
* @param string $className |
|
9
|
|
|
*/ |
|
10
|
|
View Code Duplication |
public function generate($className) |
|
11
|
|
|
{ |
|
12
|
|
|
$fullTestNameSpace = $this->getNamespaceForTest($className, 'unit'); |
|
13
|
|
|
$parts = explode('\\', $fullTestNameSpace); |
|
14
|
|
|
$testClassName = array_pop($parts); |
|
15
|
|
|
$partsOfOriginClass = explode('\\', $className); |
|
16
|
|
|
$testedClassName = array_pop($partsOfOriginClass); |
|
17
|
|
|
$nameSpace = implode('\\', $parts); |
|
18
|
|
|
$testPath = $this->getTestPath($fullTestNameSpace); |
|
19
|
|
|
$class = new \ReflectionClass($className); |
|
20
|
|
|
$constructor = $class->getConstructor(); |
|
21
|
|
|
$dependencies = $constructor ? $this->getDependencies($constructor) : []; |
|
22
|
|
|
$dependenciesData = $this->getDependenciesData($dependencies); |
|
23
|
|
|
$methodsData = $this->getMethodsData($class); |
|
24
|
|
|
$this->addClassToUses($className); |
|
25
|
|
|
$orderedUses = $this->getOrderedUses($this->usedClasses); |
|
26
|
|
|
$content = $this->twig->render( |
|
27
|
|
|
'@OroTestGenerator/Tests/unit_template.php.twig', |
|
28
|
|
|
[ |
|
29
|
|
|
'namespace' => $nameSpace, |
|
30
|
|
|
'vendors' => $orderedUses, |
|
31
|
|
|
'className' => $testClassName, |
|
32
|
|
|
'testedClassName' => $testedClassName, |
|
33
|
|
|
'testedClassNameVariable' => lcfirst($testedClassName), |
|
34
|
|
|
'dependenciesData' => $dependenciesData, |
|
35
|
|
|
'methodsData' => $methodsData |
|
36
|
|
|
] |
|
37
|
|
|
); |
|
38
|
|
|
$this->createFile($testPath, $content); |
|
39
|
|
|
} |
|
40
|
|
|
} |
|
41
|
|
|
|