Completed
Branch master (3b8125)
by
unknown
01:20
created

ClassManagerTest::setUp()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
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
0 ignored issues
show
Unused Code introduced by
The call to PropertyManager::__construct() has too many arguments starting with $this->classManager.

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 @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
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()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
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()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
91
    {
92
        $testClass = $this->classManager->getTestClass();
93
        $testClassMethods = $testClass->getMethods();
94
        $testClassMethods->add(new TestMethodManager($this->classManager)); // broken test class method
0 ignored issues
show
Unused Code introduced by
The call to TestMethodManager::__construct() has too many arguments starting with $this->classManager.

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 @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
95
        $testClass->setMethods($testClassMethods);
96
        $errors = $this->getValidator()->validate($this->classManager);
97
        $this->assertEquals(1, $errors->count());
98
    }
99
}
100