|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace HelloWordPl\SimpleEntityGeneratorBundle\Tests\Lib\Items; |
|
4
|
|
|
|
|
5
|
|
|
use HelloWordPl\SimpleEntityGeneratorBundle\Lib\Items\ClassManager; |
|
6
|
|
|
use HelloWordPl\SimpleEntityGeneratorBundle\Lib\Items\MethodGetterInterfaceManager; |
|
7
|
|
|
use HelloWordPl\SimpleEntityGeneratorBundle\Lib\Items\MethodGetterManager; |
|
8
|
|
|
use HelloWordPl\SimpleEntityGeneratorBundle\Lib\Items\PropertyManager; |
|
9
|
|
|
use HelloWordPl\SimpleEntityGeneratorBundle\Lib\Items\TestMethodManager; |
|
10
|
|
|
use HelloWordPl\SimpleEntityGeneratorBundle\Tests\Lib\Items\BaseManager; |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* ClassManager Test |
|
14
|
|
|
* |
|
15
|
|
|
* @author Sławomir Kania <[email protected]> |
|
16
|
|
|
*/ |
|
17
|
|
|
class ClassManagerTest extends BaseManager |
|
18
|
|
|
{ |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* @var ClassManager |
|
22
|
|
|
*/ |
|
23
|
|
|
protected $classManager = null; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* SET UP |
|
27
|
|
|
*/ |
|
28
|
|
|
public function setUp() |
|
29
|
|
|
{ |
|
30
|
|
|
parent::setUp(); |
|
31
|
|
|
$this->classManager = $this->preapareClassManager(); |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
public function testManger() |
|
35
|
|
|
{ |
|
36
|
|
|
$this->assertInstanceOf('\HelloWordPl\SimpleEntityGeneratorBundle\Lib\Interfaces\RenderableInterface', $this->classManager); |
|
37
|
|
|
$this->assertInstanceOf('\HelloWordPl\SimpleEntityGeneratorBundle\Lib\Items\ClassManager', $this->classManager); |
|
38
|
|
|
$this->assertInstanceOf('\HelloWordPl\SimpleEntityGeneratorBundle\Lib\Interfaces\StructureWithMethodsInterface', $this->classManager); |
|
39
|
|
|
$this->assertInstanceOf('\HelloWordPl\SimpleEntityGeneratorBundle\Lib\Interfaces\DumpableInterface', $this->classManager); |
|
40
|
|
|
$this->assertEquals("User entity for tests", $this->classManager->getComment()); |
|
41
|
|
|
$this->assertEquals("\AppBundle\Entity\User", $this->classManager->getNamespace()); |
|
42
|
|
|
$this->assertEquals("\AppBundle\Entity", $this->classManager->getNamespaceWithoutName()); |
|
43
|
|
|
$this->assertEquals("AppBundle\Entity", $this->classManager->getNamespaceWithoutNameAndBackslashPrefix()); |
|
44
|
|
|
$this->assertEquals("User", $this->classManager->getName()); |
|
45
|
|
|
$this->assertEquals("/AppBundle/Entity", $this->classManager->getDirectory()); |
|
46
|
|
|
$this->assertTrue($this->classManager->hasInterface()); |
|
47
|
|
|
$this->assertTrue($this->classManager->hasTestClass()); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
public function testValidManagerWhenValid() |
|
51
|
|
|
{ |
|
52
|
|
|
$errors = $this->getValidator()->validate($this->classManager); |
|
53
|
|
|
$this->assertEquals(0, $errors->count()); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
public function testValidManagerWhenEmptyClassManager() |
|
57
|
|
|
{ |
|
58
|
|
|
$errors = $this->getValidator()->validate(new ClassManager()); |
|
59
|
|
|
$this->assertEquals(3, $errors->count()); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
public function testValidManagerWhenInvalidMethod() |
|
63
|
|
|
{ |
|
64
|
|
|
$methods = $this->classManager->getMethods(); |
|
65
|
|
|
$methods->add(new MethodGetterManager($this->classManager)); // broken method |
|
66
|
|
|
$this->classManager->setMethods($methods); |
|
67
|
|
|
$errors = $this->getValidator()->validate($this->classManager); |
|
68
|
|
|
$this->assertEquals(1, $errors->count()); |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
public function testValidManagerWhenInvalidProperty() |
|
72
|
|
|
{ |
|
73
|
|
|
$properties = $this->classManager->getProperties(); |
|
74
|
|
|
$properties->add(new PropertyManager($this->classManager)); // broken property |
|
|
|
|
|
|
75
|
|
|
$this->classManager->setProperties($properties); |
|
76
|
|
|
$errors = $this->getValidator()->validate($this->classManager); |
|
77
|
|
|
$this->assertEquals(4, $errors->count()); |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
View Code Duplication |
public function testValidManagerWhenInvalidInterfaceMethod() |
|
|
|
|
|
|
81
|
|
|
{ |
|
82
|
|
|
$interface = $this->classManager->getInterface(); |
|
83
|
|
|
$interfaceMethods = $interface->getMethods(); |
|
84
|
|
|
$interfaceMethods->add(new MethodGetterInterfaceManager($this->classManager)); // broken interface method |
|
85
|
|
|
$interface->setMethods($interfaceMethods); |
|
86
|
|
|
$errors = $this->getValidator()->validate($this->classManager); |
|
87
|
|
|
$this->assertEquals(1, $errors->count()); |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
View Code Duplication |
public function testValidManagerWhenInvalidTestClassMethod() |
|
|
|
|
|
|
91
|
|
|
{ |
|
92
|
|
|
$testClass = $this->classManager->getTestClass(); |
|
93
|
|
|
$testClassMethods = $testClass->getMethods(); |
|
94
|
|
|
$testClassMethods->add(new TestMethodManager($this->classManager)); // broken test class method |
|
|
|
|
|
|
95
|
|
|
$testClass->setMethods($testClassMethods); |
|
96
|
|
|
$errors = $this->getValidator()->validate($this->classManager); |
|
97
|
|
|
$this->assertEquals(1, $errors->count()); |
|
98
|
|
|
} |
|
99
|
|
|
} |
|
100
|
|
|
|
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.
In this case you can add the
@ignorePhpDoc annotation to the duplicate definition and it will be ignored.