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

GetterSetterTrait::runGetterSetterTests()   B

Complexity

Conditions 5
Paths 4

Size

Total Lines 24
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 24
rs 8.5125
c 0
b 0
f 0
cc 5
eloc 17
nc 4
nop 1
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