Test Setup Failed
Push — master ( 298fd3...56daff )
by Matthew
17:14
created

GetterSetterTrait   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 0
dl 0
loc 27
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B runGetterSetterTests() 0 24 5
1
<?php
2
3
namespace Dtc\QueueBundle\Tests;
4
5
trait GetterSetterTrait
6
{
7
    public function runGetterSetterTests($testClass)
8
    {
9
        $reflection = new \ReflectionClass($testClass);
10
        $properties = $reflection->getProperties();
11
        foreach ($properties as $property) {
12
            $name = $property->getName();
13
            $getMethod = 'get'.ucfirst($name);
14
            $setMethod = 'set'.ucfirst($name);
15
            self::assertTrue($reflection->hasMethod($getMethod), $getMethod);
16
            self::assertTrue($reflection->hasMethod($setMethod), $setMethod);
17
18
            $obj = new $testClass();
19
20
            $parameters = $reflection->getMethod($setMethod)->getParameters();
21
            if ($parameters && 1 == count($parameters)) {
22
                $parameter = $parameters[0];
23
                if (!$parameter->getClass()) {
24
                    $someValue = 'somevalue';
25
                    $obj->$setMethod($someValue);
26
                    self::assertSame($someValue, $obj->$getMethod(), "$setMethod, $getMethod");
27
                }
28
            }
29
        }
30
    }
31
}
32