|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace HelloWordPl\SimpleEntityGeneratorBundle\Tests\Lib\Items; |
|
4
|
|
|
|
|
5
|
|
|
use HelloWordPl\SimpleEntityGeneratorBundle\Lib\Items\ClassManager; |
|
6
|
|
|
use HelloWordPl\SimpleEntityGeneratorBundle\Lib\Items\TestClassManager; |
|
7
|
|
|
use HelloWordPl\SimpleEntityGeneratorBundle\Lib\Items\TestMethodManager; |
|
8
|
|
|
use HelloWordPl\SimpleEntityGeneratorBundle\Tests\Lib\Items\BaseManager; |
|
9
|
|
|
|
|
10
|
|
|
/** |
|
11
|
|
|
* TestClassManager Test |
|
12
|
|
|
* |
|
13
|
|
|
* @author Sławomir Kania <[email protected]> |
|
14
|
|
|
*/ |
|
15
|
|
View Code Duplication |
class TestClassManagerTest extends BaseManager |
|
|
|
|
|
|
16
|
|
|
{ |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* @var TestClassManager |
|
20
|
|
|
*/ |
|
21
|
|
|
protected $testClassManager = null; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* SET UP |
|
25
|
|
|
*/ |
|
26
|
|
|
public function setUp() |
|
27
|
|
|
{ |
|
28
|
|
|
parent::setUp(); |
|
29
|
|
|
$this->testClassManager = $this->preapareClassManager()->getTestClass(); |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
public function testManger() |
|
33
|
|
|
{ |
|
34
|
|
|
$this->assertInstanceOf('\HelloWordPl\SimpleEntityGeneratorBundle\Lib\Interfaces\RenderableInterface', $this->testClassManager); |
|
35
|
|
|
$this->assertInstanceOf('\HelloWordPl\SimpleEntityGeneratorBundle\Lib\Interfaces\DumpableInterface', $this->testClassManager); |
|
36
|
|
|
$this->assertInstanceOf('\HelloWordPl\SimpleEntityGeneratorBundle\Lib\Interfaces\StructureWithMethodsInterface', $this->testClassManager); |
|
37
|
|
|
$this->assertInstanceOf('\HelloWordPl\SimpleEntityGeneratorBundle\Lib\Items\TestClassManager', $this->testClassManager); |
|
38
|
|
|
$this->assertEquals('Test for \AppBundle\Entity\User', $this->testClassManager->getComment()); |
|
39
|
|
|
$this->assertEquals('/AppBundle/Tests/Entity', $this->testClassManager->getDirectory()); |
|
40
|
|
|
$this->assertEquals('UserTest', $this->testClassManager->getName()); |
|
41
|
|
|
$this->assertEquals('\AppBundle\Tests\Entity\UserTest', $this->testClassManager->getNamespace()); |
|
42
|
|
|
$this->assertEquals('\AppBundle\Tests\Entity', $this->testClassManager->getNamespaceWithoutName()); |
|
43
|
|
|
$this->assertEquals('AppBundle\Tests\Entity', $this->testClassManager->getNamespaceWithoutNameAndBackslashPrefix()); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
public function testValidManagerWhenValid() |
|
47
|
|
|
{ |
|
48
|
|
|
$errors = $this->getValidator()->validate($this->testClassManager); |
|
49
|
|
|
$this->assertEquals(0, $errors->count()); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
public function testValidManagerWhenInvalidTestMethod() |
|
53
|
|
|
{ |
|
54
|
|
|
$methods = $this->testClassManager->getMethods(); |
|
55
|
|
|
$methods->add(new TestMethodManager()); |
|
56
|
|
|
$this->testClassManager->setMethods($methods); |
|
57
|
|
|
$errors = $this->getValidator()->validate($this->testClassManager); |
|
58
|
|
|
$this->assertEquals(1, $errors->count()); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
public function testValidManagerWhenInvalidClassManager() |
|
62
|
|
|
{ |
|
63
|
|
|
$this->testClassManager->setClassManager(new ClassManager()); |
|
64
|
|
|
$errors = $this->getValidator()->validate($this->testClassManager); |
|
65
|
|
|
$this->assertEquals(3, $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.