Completed
Push — master ( c6e8cc...5bd743 )
by Jacob
02:18
created

DisplayTest::testConstruct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 20
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 20
rs 9.4286
cc 1
eloc 15
nc 1
nop 0
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
    public function testConstruct()
12
    {
13
        $display = new Display();
14
        $reflectedDisplay = new ReflectionClass(get_class($display));
15
        $reflectedProperty = $reflectedDisplay->getProperty('defaults');
16
        $reflectedProperty->setAccessible(true);
17
        $defaults = $reflectedProperty->getValue($display);
18
19
        $display = new Display();
20
        $this->assertAttributeEquals($defaults, 'options', $display);
21
22
        $options = array(
23
            'script_path' => 'testing/testing.js',
24
            'fake_key' => 'foo bar'
25
        );
26
        $expectedOptions = array_intersect_key($options, $defaults);
27
        $expectedOptions = array_replace($defaults, $expectedOptions);
28
        $display = new Display($options);
29
        $this->assertAttributeEquals($expectedOptions, 'options', $display);
30
    }
31
32 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...
33
    {
34
        $timeTest = array(
35
            '.032432' => '32.432 ms',
36
            '24.3781' => '24.378 s',
37
            '145.123' => '2.419 m'
38
        );
39
        $display = new Display();
40
        $reflectedMethod = $this->getAccessibleMethod($display, 'getReadableTime');
41
42
        foreach ($timeTest as $rawTime => $expectedTime) {
43
            $readableTime = $reflectedMethod->invokeArgs($display, array($rawTime));
44
            $this->assertEquals($expectedTime, $readableTime);
45
        }
46
    }
47
48 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...
49
    {
50
        $memoryTest = array(
51
            '314'     => '314 b',
52
            '7403'    => '7.23 k',
53
            '2589983' => '2.47 M'
54
        );
55
        $display = new Display();
56
        $reflectedMethod = $this->getAccessibleMethod($display, 'getReadableMemory');
57
58
        foreach ($memoryTest as $rawMemory => $expectedMemory) {
59
            $readableMemory = $reflectedMethod->invokeArgs($display, array($rawMemory));
60
            $this->assertEquals($expectedMemory, $readableMemory);
61
        }
62
    }
63
64
    protected function getAccessibleMethod(Display $display, $methodName)
65
    {
66
        $reflectedConsole = new ReflectionClass(get_class($display));
67
        $reflectedMethod = $reflectedConsole->getMethod($methodName);
68
        $reflectedMethod->setAccessible(true);
69
        return $reflectedMethod;
70
    }
71
}
72