Completed
Push — master ( a030fc...db8ab4 )
by Jacob
05:13
created

PhpQuickProfilerTest::testSetDisplay()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 8
rs 9.4286
cc 1
eloc 5
nc 1
nop 0
1
<?php
2
3
namespace Particletree\Pqp;
4
5
use PHPUnit_Framework_Testcase;
6
7
// namespace hack on microtime functionality
8
function microtime($get_as_float = false) {
9
    if ($get_as_float) {
10
      return 1450355136.5706;
11
    }
12
    return '1450355136 5706';
13
}
14
15
// namespace hack on included files functionality
16
function get_included_files() {
17
    return array(
18
      'index.php',
19
      'src/Class.php'
20
    );
21
}
22
23
// namespace hack on filesize
24
function filesize($filename) {
0 ignored issues
show
Unused Code introduced by
The parameter $filename is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
25
    return 100;
26
}
27
28
class PhpQuickProfilerTest extends PHPUnit_Framework_TestCase
29
{
30
31
    public function testConstruct()
32
    {
33
        $startTime = microtime(true);
34
35
        $profiler = new PhpQuickProfiler();
36
        $this->assertAttributeEquals($startTime, 'startTime', $profiler);
37
38
        $profiler = new PhpQuickProfiler($startTime);
39
        $this->assertAttributeEquals($startTime, 'startTime', $profiler);
40
    }
41
42
    public function testSetConsole()
43
    {
44
        $console = new Console();
45
        $profiler = new PhpQuickProfiler();
46
        $profiler->setConsole($console);
47
48
        $this->assertAttributeSame($console, 'console', $profiler);
49
    }
50
51
    public function testSetDisplay()
52
    {
53
        $display = new Display();
54
        $profiler = new PhpQuickProfiler();
55
        $profiler->setDisplay($display);
56
57
        $this->assertAttributeSame($display, 'display', $profiler);
58
    }
59
60
    public function testGatherFileData()
61
    {
62
        $files = get_included_files();
63
        $fileSize = filesize('');
64
        $profiler = new PhpQuickProfiler();
65
        $gatheredFileData = $profiler->gatherFileData();
66
67
        foreach ($gatheredFileData as $fileData) {
68
            $this->assertArrayHasKey('name', $fileData);
69
            $this->assertContains($fileData['name'], $files);
70
            $this->assertArrayHasKey('size', $fileData);
71
            $this->assertEquals($fileData['size'], $fileSize);
72
        }
73
    }
74
75
    public function testSetProfiledQueries()
76
    {
77
        $profiledQueries = array(
78
            'sql' => 'SELECT * FROM example',
79
            'time' => 25
80
        );
81
        $profiler = new PhpQuickProfiler();
82
        $profiler->setProfiledQueries($profiledQueries);
83
84
        $this->assertAttributeEquals($profiledQueries, 'profiledQueries', $profiler);
85
    }
86
}
87