|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace HelloWordPl\SimpleEntityGeneratorBundle\Tests\Lib\Items; |
|
4
|
|
|
|
|
5
|
|
|
use HelloWordPl\SimpleEntityGeneratorBundle\Lib\Items\ClassManager; |
|
6
|
|
|
use HelloWordPl\SimpleEntityGeneratorBundle\Lib\Items\InterfaceManager; |
|
7
|
|
|
use HelloWordPl\SimpleEntityGeneratorBundle\Lib\Items\MethodGetterInterfaceManager; |
|
8
|
|
|
use HelloWordPl\SimpleEntityGeneratorBundle\Tests\Lib\Items\BaseManager; |
|
9
|
|
|
|
|
10
|
|
|
/** |
|
11
|
|
|
* InterfaceManager Test |
|
12
|
|
|
* |
|
13
|
|
|
* @author Sławomir Kania <[email protected]> |
|
14
|
|
|
*/ |
|
15
|
|
View Code Duplication |
class InterfaceManagerTest extends BaseManager |
|
|
|
|
|
|
16
|
|
|
{ |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* @var InterfaceManager |
|
20
|
|
|
*/ |
|
21
|
|
|
protected $interfaceManager = null; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* SET UP |
|
25
|
|
|
*/ |
|
26
|
|
|
public function setUp() |
|
27
|
|
|
{ |
|
28
|
|
|
parent::setUp(); |
|
29
|
|
|
$this->interfaceManager = $this->preapareClassManager()->getInterface(); |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
public function testManger() |
|
33
|
|
|
{ |
|
34
|
|
|
$this->assertInstanceOf('\HelloWordPl\SimpleEntityGeneratorBundle\Lib\Interfaces\RenderableInterface', $this->interfaceManager); |
|
35
|
|
|
$this->assertInstanceOf('\HelloWordPl\SimpleEntityGeneratorBundle\Lib\Items\InterfaceManager', $this->interfaceManager); |
|
36
|
|
|
$this->assertInstanceOf('\HelloWordPl\SimpleEntityGeneratorBundle\Lib\Interfaces\StructureWithMethodsInterface', $this->interfaceManager); |
|
37
|
|
|
$this->assertInstanceOf('\HelloWordPl\SimpleEntityGeneratorBundle\Lib\Interfaces\DumpableInterface', $this->interfaceManager); |
|
38
|
|
|
$this->assertEquals("Interface for entity : \AppBundle\Entity\User", $this->interfaceManager->getComment()); |
|
39
|
|
|
$this->assertEquals("\AppBundle\Entity\UserInterface", $this->interfaceManager->getNamespace()); |
|
40
|
|
|
$this->assertEquals("UserInterface", $this->interfaceManager->getName()); |
|
41
|
|
|
$this->assertEquals("/AppBundle/Entity", $this->interfaceManager->getDirectory()); |
|
42
|
|
|
$this->assertEquals("\AppBundle\Entity", $this->interfaceManager->getNamespaceWithoutName()); |
|
43
|
|
|
$this->assertEquals("AppBundle\Entity", $this->interfaceManager->getNamespaceWithoutNameAndBackslashPrefix()); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
public function testValidManagerWhenValid() |
|
47
|
|
|
{ |
|
48
|
|
|
$errors = $this->getValidator()->validate($this->interfaceManager); |
|
49
|
|
|
$this->assertEquals(0, $errors->count()); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
public function testValidManagerWhenEmptyClassManager() |
|
53
|
|
|
{ |
|
54
|
|
|
$this->interfaceManager->setClassManager(new ClassManager()); |
|
55
|
|
|
$errors = $this->getValidator()->validate($this->interfaceManager); |
|
56
|
|
|
$this->assertEquals(4, $errors->count()); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
public function testValidManagerWhenInvalidMethod() |
|
60
|
|
|
{ |
|
61
|
|
|
$methods = $this->interfaceManager->getMethods(); |
|
62
|
|
|
$methods->add(new MethodGetterInterfaceManager($this->interfaceManager->getClassManager())); // broken method |
|
63
|
|
|
$this->interfaceManager->setMethods($methods); |
|
64
|
|
|
$errors = $this->getValidator()->validate($this->interfaceManager); |
|
65
|
|
|
$this->assertEquals(1, $errors->count()); |
|
66
|
|
|
} |
|
67
|
|
|
} |
|
68
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.