Completed
Push — master ( a19d10...c6e8cc )
by Jacob
02:16
created

DisplayTest::getAccessibleMethod()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 7
rs 9.4286
cc 1
eloc 5
nc 1
nop 2
1
<?php
2
3
namespace Particletree\Pqp;
4
5
use PHPUnit_Framework_TestCase;
6
use ReflectionClass;
7
8
class DisplayTest extends PHPUnit_Framework_TestCase
9
{
10
11 View Code Duplication
    public function testGetReadableTime()
1 ignored issue
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...
12
    {
13
        $timeTest = array(
14
            '.032432' => '32.432 ms',
15
            '24.3781' => '24.378 s',
16
            '145.123' => '2.419 m'
17
        );
18
        $display = new Display();
19
        $reflectedMethod = $this->getAccessibleMethod($display, 'getReadableTime');
20
21
        foreach ($timeTest as $rawTime => $expectedReadableTime) {
22
            $readableTime = $reflectedMethod->invokeArgs($display, array($rawTime));
23
            $this->assertEquals($expectedReadableTime, $readableTime);
24
        }
25
    }
26
27 View Code Duplication
    public function testGetReadableMemory()
1 ignored issue
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...
28
    {
29
        $memoryTest = array(
30
            '314'     => '314 b',
31
            '7403'    => '7.23 k',
32
            '2589983' => '2.47 M'
33
        );
34
        $display = new Display();
35
        $reflectedMethod = $this->getAccessibleMethod($display, 'getReadableMemory');
36
37
        foreach ($memoryTest as $rawMemory => $expectedReadableMemory) {
38
            $readableMemory = $reflectedMethod->invokeArgs($display, array($rawMemory));
39
            $this->assertEquals($expectedReadableMemory, $readableMemory);
40
        }
41
    }
42
43
    protected function getAccessibleMethod(Display $display, $methodName)
44
    {
45
        $reflectedConsole = new ReflectionClass(get_class($display));
46
        $reflectedMethod = $reflectedConsole->getMethod($methodName);
47
        $reflectedMethod->setAccessible(true);
48
        return $reflectedMethod;
49
    }
50
}
51