@@ -17,166 +17,166 @@  | 
                                                    ||
| 17 | 17 | class PhpQuickProfiler  | 
                                                        
| 18 | 18 |  { | 
                                                        
| 19 | 19 | |
| 20 | - /** @var integer */  | 
                                                        |
| 21 | - protected $startTime;  | 
                                                        |
| 22 | -  | 
                                                        |
| 23 | - /** @var Console */  | 
                                                        |
| 24 | - protected $console;  | 
                                                        |
| 25 | -  | 
                                                        |
| 26 | - /** @var Display */  | 
                                                        |
| 27 | - protected $display;  | 
                                                        |
| 28 | -  | 
                                                        |
| 29 | - /** @var array */  | 
                                                        |
| 30 | - protected $profiledQueries = array();  | 
                                                        |
| 31 | -  | 
                                                        |
| 32 | - /**  | 
                                                        |
| 33 | - * @param integer $startTime  | 
                                                        |
| 34 | - */  | 
                                                        |
| 35 | - public function __construct($startTime = null)  | 
                                                        |
| 36 | -    { | 
                                                        |
| 37 | -        if (is_null($startTime)) { | 
                                                        |
| 38 | - $startTime = microtime(true);  | 
                                                        |
| 39 | - }  | 
                                                        |
| 40 | - $this->startTime = $startTime;  | 
                                                        |
| 41 | - }  | 
                                                        |
| 42 | -  | 
                                                        |
| 43 | - /**  | 
                                                        |
| 44 | - * @param Console $console  | 
                                                        |
| 45 | - */  | 
                                                        |
| 46 | - public function setConsole(Console $console)  | 
                                                        |
| 47 | -    { | 
                                                        |
| 48 | - $this->console = $console;  | 
                                                        |
| 49 | - }  | 
                                                        |
| 50 | -  | 
                                                        |
| 51 | - /**  | 
                                                        |
| 52 | - * @param Display $display  | 
                                                        |
| 53 | - */  | 
                                                        |
| 54 | - public function setDisplay(Display $display)  | 
                                                        |
| 55 | -    { | 
                                                        |
| 56 | - $this->display = $display;  | 
                                                        |
| 57 | - }  | 
                                                        |
| 58 | -  | 
                                                        |
| 59 | - /**  | 
                                                        |
| 60 | - * Get data about files loaded for the application to current point  | 
                                                        |
| 61 | - *  | 
                                                        |
| 62 | - * @returns array  | 
                                                        |
| 63 | - */  | 
                                                        |
| 64 | - public function gatherFileData()  | 
                                                        |
| 65 | -    { | 
                                                        |
| 66 | - $files = get_included_files();  | 
                                                        |
| 67 | - $data = array();  | 
                                                        |
| 68 | -        foreach ($files as $file) { | 
                                                        |
| 69 | - array_push($data, array(  | 
                                                        |
| 70 | - 'name' => $file,  | 
                                                        |
| 71 | - 'size' => filesize($file)  | 
                                                        |
| 72 | - ));  | 
                                                        |
| 73 | - }  | 
                                                        |
| 74 | - return $data;  | 
                                                        |
| 75 | - }  | 
                                                        |
| 76 | -  | 
                                                        |
| 77 | - /**  | 
                                                        |
| 78 | - * Get data about memory usage of the application  | 
                                                        |
| 79 | - *  | 
                                                        |
| 80 | - * @returns array  | 
                                                        |
| 81 | - */  | 
                                                        |
| 82 | - public function gatherMemoryData()  | 
                                                        |
| 83 | -    { | 
                                                        |
| 84 | - $usedMemory = memory_get_peak_usage();  | 
                                                        |
| 85 | -        $allowedMemory = ini_get('memory_limit'); | 
                                                        |
| 86 | - return array(  | 
                                                        |
| 87 | - 'used' => $usedMemory,  | 
                                                        |
| 88 | - 'allowed' => $allowedMemory  | 
                                                        |
| 89 | - );  | 
                                                        |
| 90 | - }  | 
                                                        |
| 91 | -  | 
                                                        |
| 92 | - /**  | 
                                                        |
| 93 | - * @param array $profiled_queries  | 
                                                        |
| 94 | - */  | 
                                                        |
| 95 | - public function setProfiledQueries(array $profiledQueries)  | 
                                                        |
| 96 | -    { | 
                                                        |
| 97 | - $this->profiledQueries = $profiledQueries;  | 
                                                        |
| 98 | - }  | 
                                                        |
| 99 | -  | 
                                                        |
| 100 | - /**  | 
                                                        |
| 101 | - * Get data about sql usage of the application  | 
                                                        |
| 102 | - *  | 
                                                        |
| 103 | - * @param object $dbConnection  | 
                                                        |
| 104 | - * @returns array  | 
                                                        |
| 105 | - */  | 
                                                        |
| 106 | - public function gatherQueryData($dbConnection)  | 
                                                        |
| 107 | -    { | 
                                                        |
| 108 | -        if (empty($this->profiledQueries) && property_exists($dbConnection, 'queries')) { | 
                                                        |
| 109 | - $this->setProfiledQueries($dbConnection->queries);  | 
                                                        |
| 110 | - }  | 
                                                        |
| 111 | -  | 
                                                        |
| 112 | - $data = array();  | 
                                                        |
| 113 | -        foreach ($this->profiledQueries as $query) { | 
                                                        |
| 114 | -            if ($query['function'] !== 'perform') { | 
                                                        |
| 115 | - continue;  | 
                                                        |
| 116 | - }  | 
                                                        |
| 117 | -  | 
                                                        |
| 118 | - array_push($data, array(  | 
                                                        |
| 119 | - 'sql' => $query['statement'],  | 
                                                        |
| 120 | - 'explain' => $this->explainQuery($dbConnection, $query['statement'], $query['bind_values']),  | 
                                                        |
| 121 | - 'time' => $query['duration']  | 
                                                        |
| 122 | - ));  | 
                                                        |
| 123 | - }  | 
                                                        |
| 124 | - return $data;  | 
                                                        |
| 125 | - }  | 
                                                        |
| 126 | -  | 
                                                        |
| 127 | - /**  | 
                                                        |
| 128 | - * Attempts to explain a query  | 
                                                        |
| 129 | - *  | 
                                                        |
| 130 | - * @param object $dbConnection  | 
                                                        |
| 131 | - * @param string $query  | 
                                                        |
| 132 | - * @param array $parameters  | 
                                                        |
| 133 | - * @return array  | 
                                                        |
| 134 | - */  | 
                                                        |
| 135 | - protected function explainQuery($dbConnection, $query, $parameters)  | 
                                                        |
| 136 | -    { | 
                                                        |
| 137 | -        $query = "EXPLAIN {$query}"; | 
                                                        |
| 138 | -        try { | 
                                                        |
| 139 | - $statement = $dbConnection->prepare($query);  | 
                                                        |
| 140 | - $statement->execute($parameters);  | 
                                                        |
| 141 | - return $statement->fetch(\PDO::FETCH_ASSOC);  | 
                                                        |
| 142 | -        } catch (Exception $e) { | 
                                                        |
| 143 | - echo $e->getMessage();  | 
                                                        |
| 144 | - }  | 
                                                        |
| 145 | - return '';  | 
                                                        |
| 146 | - }  | 
                                                        |
| 147 | -  | 
                                                        |
| 148 | - /**  | 
                                                        |
| 149 | - * Get data about speed of the application  | 
                                                        |
| 150 | - *  | 
                                                        |
| 151 | - * @returns array  | 
                                                        |
| 152 | - */  | 
                                                        |
| 153 | - public function gatherSpeedData()  | 
                                                        |
| 154 | -    { | 
                                                        |
| 155 | - $elapsedTime = microtime(true) - $this->startTime;  | 
                                                        |
| 156 | -        $allowedTime = ini_get('max_execution_time'); | 
                                                        |
| 157 | - return array(  | 
                                                        |
| 158 | - 'elapsed' => $elapsedTime,  | 
                                                        |
| 159 | - 'allowed' => $allowedTime  | 
                                                        |
| 160 | - );  | 
                                                        |
| 161 | - }  | 
                                                        |
| 162 | -  | 
                                                        |
| 163 | - /**  | 
                                                        |
| 164 | - * Triggers end display of the profiling data  | 
                                                        |
| 165 | - *  | 
                                                        |
| 166 | - * @param object $dbConnection  | 
                                                        |
| 167 | - */  | 
                                                        |
| 168 | - public function display($dbConnection = null)  | 
                                                        |
| 169 | -    { | 
                                                        |
| 170 | -        if (!isset($this->display)) { | 
                                                        |
| 171 | -            throw new Exception('Display object has not been injected into Profiler'); | 
                                                        |
| 172 | - }  | 
                                                        |
| 173 | -  | 
                                                        |
| 174 | - $this->display->setConsole($this->console);  | 
                                                        |
| 175 | - $this->display->setFileData($this->gatherFileData());  | 
                                                        |
| 176 | - $this->display->setMemoryData($this->gatherMemoryData());  | 
                                                        |
| 177 | - $this->display->setQueryData($this->gatherQueryData($dbConnection));  | 
                                                        |
| 178 | - $this->display->setSpeedData($this->gatherSpeedData());  | 
                                                        |
| 179 | -  | 
                                                        |
| 180 | - $this->display->__invoke();  | 
                                                        |
| 181 | - }  | 
                                                        |
| 20 | + /** @var integer */  | 
                                                        |
| 21 | + protected $startTime;  | 
                                                        |
| 22 | +  | 
                                                        |
| 23 | + /** @var Console */  | 
                                                        |
| 24 | + protected $console;  | 
                                                        |
| 25 | +  | 
                                                        |
| 26 | + /** @var Display */  | 
                                                        |
| 27 | + protected $display;  | 
                                                        |
| 28 | +  | 
                                                        |
| 29 | + /** @var array */  | 
                                                        |
| 30 | + protected $profiledQueries = array();  | 
                                                        |
| 31 | +  | 
                                                        |
| 32 | + /**  | 
                                                        |
| 33 | + * @param integer $startTime  | 
                                                        |
| 34 | + */  | 
                                                        |
| 35 | + public function __construct($startTime = null)  | 
                                                        |
| 36 | +	{ | 
                                                        |
| 37 | +		if (is_null($startTime)) { | 
                                                        |
| 38 | + $startTime = microtime(true);  | 
                                                        |
| 39 | + }  | 
                                                        |
| 40 | + $this->startTime = $startTime;  | 
                                                        |
| 41 | + }  | 
                                                        |
| 42 | +  | 
                                                        |
| 43 | + /**  | 
                                                        |
| 44 | + * @param Console $console  | 
                                                        |
| 45 | + */  | 
                                                        |
| 46 | + public function setConsole(Console $console)  | 
                                                        |
| 47 | +	{ | 
                                                        |
| 48 | + $this->console = $console;  | 
                                                        |
| 49 | + }  | 
                                                        |
| 50 | +  | 
                                                        |
| 51 | + /**  | 
                                                        |
| 52 | + * @param Display $display  | 
                                                        |
| 53 | + */  | 
                                                        |
| 54 | + public function setDisplay(Display $display)  | 
                                                        |
| 55 | +	{ | 
                                                        |
| 56 | + $this->display = $display;  | 
                                                        |
| 57 | + }  | 
                                                        |
| 58 | +  | 
                                                        |
| 59 | + /**  | 
                                                        |
| 60 | + * Get data about files loaded for the application to current point  | 
                                                        |
| 61 | + *  | 
                                                        |
| 62 | + * @returns array  | 
                                                        |
| 63 | + */  | 
                                                        |
| 64 | + public function gatherFileData()  | 
                                                        |
| 65 | +	{ | 
                                                        |
| 66 | + $files = get_included_files();  | 
                                                        |
| 67 | + $data = array();  | 
                                                        |
| 68 | +		foreach ($files as $file) { | 
                                                        |
| 69 | + array_push($data, array(  | 
                                                        |
| 70 | + 'name' => $file,  | 
                                                        |
| 71 | + 'size' => filesize($file)  | 
                                                        |
| 72 | + ));  | 
                                                        |
| 73 | + }  | 
                                                        |
| 74 | + return $data;  | 
                                                        |
| 75 | + }  | 
                                                        |
| 76 | +  | 
                                                        |
| 77 | + /**  | 
                                                        |
| 78 | + * Get data about memory usage of the application  | 
                                                        |
| 79 | + *  | 
                                                        |
| 80 | + * @returns array  | 
                                                        |
| 81 | + */  | 
                                                        |
| 82 | + public function gatherMemoryData()  | 
                                                        |
| 83 | +	{ | 
                                                        |
| 84 | + $usedMemory = memory_get_peak_usage();  | 
                                                        |
| 85 | +		$allowedMemory = ini_get('memory_limit'); | 
                                                        |
| 86 | + return array(  | 
                                                        |
| 87 | + 'used' => $usedMemory,  | 
                                                        |
| 88 | + 'allowed' => $allowedMemory  | 
                                                        |
| 89 | + );  | 
                                                        |
| 90 | + }  | 
                                                        |
| 91 | +  | 
                                                        |
| 92 | + /**  | 
                                                        |
| 93 | + * @param array $profiled_queries  | 
                                                        |
| 94 | + */  | 
                                                        |
| 95 | + public function setProfiledQueries(array $profiledQueries)  | 
                                                        |
| 96 | +	{ | 
                                                        |
| 97 | + $this->profiledQueries = $profiledQueries;  | 
                                                        |
| 98 | + }  | 
                                                        |
| 99 | +  | 
                                                        |
| 100 | + /**  | 
                                                        |
| 101 | + * Get data about sql usage of the application  | 
                                                        |
| 102 | + *  | 
                                                        |
| 103 | + * @param object $dbConnection  | 
                                                        |
| 104 | + * @returns array  | 
                                                        |
| 105 | + */  | 
                                                        |
| 106 | + public function gatherQueryData($dbConnection)  | 
                                                        |
| 107 | +	{ | 
                                                        |
| 108 | +		if (empty($this->profiledQueries) && property_exists($dbConnection, 'queries')) { | 
                                                        |
| 109 | + $this->setProfiledQueries($dbConnection->queries);  | 
                                                        |
| 110 | + }  | 
                                                        |
| 111 | +  | 
                                                        |
| 112 | + $data = array();  | 
                                                        |
| 113 | +		foreach ($this->profiledQueries as $query) { | 
                                                        |
| 114 | +			if ($query['function'] !== 'perform') { | 
                                                        |
| 115 | + continue;  | 
                                                        |
| 116 | + }  | 
                                                        |
| 117 | +  | 
                                                        |
| 118 | + array_push($data, array(  | 
                                                        |
| 119 | + 'sql' => $query['statement'],  | 
                                                        |
| 120 | + 'explain' => $this->explainQuery($dbConnection, $query['statement'], $query['bind_values']),  | 
                                                        |
| 121 | + 'time' => $query['duration']  | 
                                                        |
| 122 | + ));  | 
                                                        |
| 123 | + }  | 
                                                        |
| 124 | + return $data;  | 
                                                        |
| 125 | + }  | 
                                                        |
| 126 | +  | 
                                                        |
| 127 | + /**  | 
                                                        |
| 128 | + * Attempts to explain a query  | 
                                                        |
| 129 | + *  | 
                                                        |
| 130 | + * @param object $dbConnection  | 
                                                        |
| 131 | + * @param string $query  | 
                                                        |
| 132 | + * @param array $parameters  | 
                                                        |
| 133 | + * @return array  | 
                                                        |
| 134 | + */  | 
                                                        |
| 135 | + protected function explainQuery($dbConnection, $query, $parameters)  | 
                                                        |
| 136 | +	{ | 
                                                        |
| 137 | +		$query = "EXPLAIN {$query}"; | 
                                                        |
| 138 | +		try { | 
                                                        |
| 139 | + $statement = $dbConnection->prepare($query);  | 
                                                        |
| 140 | + $statement->execute($parameters);  | 
                                                        |
| 141 | + return $statement->fetch(\PDO::FETCH_ASSOC);  | 
                                                        |
| 142 | +		} catch (Exception $e) { | 
                                                        |
| 143 | + echo $e->getMessage();  | 
                                                        |
| 144 | + }  | 
                                                        |
| 145 | + return '';  | 
                                                        |
| 146 | + }  | 
                                                        |
| 147 | +  | 
                                                        |
| 148 | + /**  | 
                                                        |
| 149 | + * Get data about speed of the application  | 
                                                        |
| 150 | + *  | 
                                                        |
| 151 | + * @returns array  | 
                                                        |
| 152 | + */  | 
                                                        |
| 153 | + public function gatherSpeedData()  | 
                                                        |
| 154 | +	{ | 
                                                        |
| 155 | + $elapsedTime = microtime(true) - $this->startTime;  | 
                                                        |
| 156 | +		$allowedTime = ini_get('max_execution_time'); | 
                                                        |
| 157 | + return array(  | 
                                                        |
| 158 | + 'elapsed' => $elapsedTime,  | 
                                                        |
| 159 | + 'allowed' => $allowedTime  | 
                                                        |
| 160 | + );  | 
                                                        |
| 161 | + }  | 
                                                        |
| 162 | +  | 
                                                        |
| 163 | + /**  | 
                                                        |
| 164 | + * Triggers end display of the profiling data  | 
                                                        |
| 165 | + *  | 
                                                        |
| 166 | + * @param object $dbConnection  | 
                                                        |
| 167 | + */  | 
                                                        |
| 168 | + public function display($dbConnection = null)  | 
                                                        |
| 169 | +	{ | 
                                                        |
| 170 | +		if (!isset($this->display)) { | 
                                                        |
| 171 | +			throw new Exception('Display object has not been injected into Profiler'); | 
                                                        |
| 172 | + }  | 
                                                        |
| 173 | +  | 
                                                        |
| 174 | + $this->display->setConsole($this->console);  | 
                                                        |
| 175 | + $this->display->setFileData($this->gatherFileData());  | 
                                                        |
| 176 | + $this->display->setMemoryData($this->gatherMemoryData());  | 
                                                        |
| 177 | + $this->display->setQueryData($this->gatherQueryData($dbConnection));  | 
                                                        |
| 178 | + $this->display->setSpeedData($this->gatherSpeedData());  | 
                                                        |
| 179 | +  | 
                                                        |
| 180 | + $this->display->__invoke();  | 
                                                        |
| 181 | + }  | 
                                                        |
| 182 | 182 | }  | 
                                                        
@@ -7,107 +7,107 @@  | 
                                                    ||
| 7 | 7 | // namespace hack on microtime functionality  | 
                                                        
| 8 | 8 | function microtime()  | 
                                                        
| 9 | 9 |  { | 
                                                        
| 10 | - return 1450355136.5706;  | 
                                                        |
| 10 | + return 1450355136.5706;  | 
                                                        |
| 11 | 11 | }  | 
                                                        
| 12 | 12 | |
| 13 | 13 | // namespace hack on included files functionality  | 
                                                        
| 14 | 14 | function get_included_files()  | 
                                                        
| 15 | 15 |  { | 
                                                        
| 16 | - return array(  | 
                                                        |
| 17 | - 'index.php',  | 
                                                        |
| 18 | - 'src/Class.php'  | 
                                                        |
| 19 | - );  | 
                                                        |
| 16 | + return array(  | 
                                                        |
| 17 | + 'index.php',  | 
                                                        |
| 18 | + 'src/Class.php'  | 
                                                        |
| 19 | + );  | 
                                                        |
| 20 | 20 | }  | 
                                                        
| 21 | 21 | |
| 22 | 22 | // namespace hack on filesize  | 
                                                        
| 23 | 23 | function filesize($filename)  | 
                                                        
| 24 | 24 |  { | 
                                                        
| 25 | - return strlen($filename) * 100;  | 
                                                        |
| 25 | + return strlen($filename) * 100;  | 
                                                        |
| 26 | 26 | }  | 
                                                        
| 27 | 27 | |
| 28 | 28 | // namespace hack on memory usage  | 
                                                        
| 29 | 29 | function memory_get_peak_usage()  | 
                                                        
| 30 | 30 |  { | 
                                                        
| 31 | - return 123456789;  | 
                                                        |
| 31 | + return 123456789;  | 
                                                        |
| 32 | 32 | }  | 
                                                        
| 33 | 33 | |
| 34 | 34 | // namespace hack on ini settings  | 
                                                        
| 35 | 35 | function ini_get($setting)  | 
                                                        
| 36 | 36 |  { | 
                                                        
| 37 | -    if ($setting == 'memory_limit') { | 
                                                        |
| 38 | - return '128M';  | 
                                                        |
| 39 | - }  | 
                                                        |
| 40 | - return \ini_get($setting);  | 
                                                        |
| 37 | +	if ($setting == 'memory_limit') { | 
                                                        |
| 38 | + return '128M';  | 
                                                        |
| 39 | + }  | 
                                                        |
| 40 | + return \ini_get($setting);  | 
                                                        |
| 41 | 41 | }  | 
                                                        
| 42 | 42 | |
| 43 | 43 | class PhpQuickProfilerTest extends PHPUnit_Framework_TestCase  | 
                                                        
| 44 | 44 |  { | 
                                                        
| 45 | 45 | |
| 46 | - public function testConstruct()  | 
                                                        |
| 47 | -    { | 
                                                        |
| 48 | - $startTime = microtime(true);  | 
                                                        |
| 49 | -  | 
                                                        |
| 50 | - $profiler = new PhpQuickProfiler();  | 
                                                        |
| 51 | - $this->assertAttributeEquals($startTime, 'startTime', $profiler);  | 
                                                        |
| 52 | -  | 
                                                        |
| 53 | - $profiler = new PhpQuickProfiler($startTime);  | 
                                                        |
| 54 | - $this->assertAttributeEquals($startTime, 'startTime', $profiler);  | 
                                                        |
| 55 | - }  | 
                                                        |
| 56 | -  | 
                                                        |
| 57 | - public function testSetConsole()  | 
                                                        |
| 58 | -    { | 
                                                        |
| 59 | - $console = new Console();  | 
                                                        |
| 60 | - $profiler = new PhpQuickProfiler();  | 
                                                        |
| 61 | - $profiler->setConsole($console);  | 
                                                        |
| 62 | -  | 
                                                        |
| 63 | - $this->assertAttributeSame($console, 'console', $profiler);  | 
                                                        |
| 64 | - }  | 
                                                        |
| 65 | -  | 
                                                        |
| 66 | - public function testSetDisplay()  | 
                                                        |
| 67 | -    { | 
                                                        |
| 68 | - $display = new Display();  | 
                                                        |
| 69 | - $profiler = new PhpQuickProfiler();  | 
                                                        |
| 70 | - $profiler->setDisplay($display);  | 
                                                        |
| 71 | -  | 
                                                        |
| 72 | - $this->assertAttributeSame($display, 'display', $profiler);  | 
                                                        |
| 73 | - }  | 
                                                        |
| 74 | -  | 
                                                        |
| 75 | - public function testGatherFileData()  | 
                                                        |
| 76 | -    { | 
                                                        |
| 77 | - $files = get_included_files();  | 
                                                        |
| 78 | - $profiler = new PhpQuickProfiler();  | 
                                                        |
| 79 | - $gatheredFileData = $profiler->gatherFileData();  | 
                                                        |
| 80 | -  | 
                                                        |
| 81 | -        foreach ($gatheredFileData as $fileData) { | 
                                                        |
| 82 | -            $this->assertArrayHasKey('name', $fileData); | 
                                                        |
| 83 | - $this->assertContains($fileData['name'], $files);  | 
                                                        |
| 84 | -            $this->assertArrayHasKey('size', $fileData); | 
                                                        |
| 85 | - $this->assertEquals($fileData['size'], filesize($fileData['name']));  | 
                                                        |
| 86 | - }  | 
                                                        |
| 87 | - }  | 
                                                        |
| 88 | -  | 
                                                        |
| 89 | - public function testGatherMemoryData()  | 
                                                        |
| 90 | -    { | 
                                                        |
| 91 | - $memory_usage = memory_get_peak_usage();  | 
                                                        |
| 92 | -        $allowed_limit = ini_get('memory_limit'); | 
                                                        |
| 93 | - $profiler = new PhpQuickProfiler();  | 
                                                        |
| 94 | - $gatheredMemoryData = $profiler->gatherMemoryData();  | 
                                                        |
| 95 | -  | 
                                                        |
| 96 | -        $this->assertArrayHasKey('used', $gatheredMemoryData); | 
                                                        |
| 97 | - $this->assertEquals($memory_usage, $gatheredMemoryData['used']);  | 
                                                        |
| 98 | -        $this->assertArrayHasKey('allowed', $gatheredMemoryData); | 
                                                        |
| 99 | - $this->assertEquals($allowed_limit, $gatheredMemoryData['allowed']);  | 
                                                        |
| 100 | - }  | 
                                                        |
| 101 | -  | 
                                                        |
| 102 | - public function testSetProfiledQueries()  | 
                                                        |
| 103 | -    { | 
                                                        |
| 104 | - $profiledQueries = array(  | 
                                                        |
| 105 | - 'sql' => 'SELECT * FROM example',  | 
                                                        |
| 106 | - 'time' => 25  | 
                                                        |
| 107 | - );  | 
                                                        |
| 108 | - $profiler = new PhpQuickProfiler();  | 
                                                        |
| 109 | - $profiler->setProfiledQueries($profiledQueries);  | 
                                                        |
| 110 | -  | 
                                                        |
| 111 | - $this->assertAttributeEquals($profiledQueries, 'profiledQueries', $profiler);  | 
                                                        |
| 112 | - }  | 
                                                        |
| 46 | + public function testConstruct()  | 
                                                        |
| 47 | +	{ | 
                                                        |
| 48 | + $startTime = microtime(true);  | 
                                                        |
| 49 | +  | 
                                                        |
| 50 | + $profiler = new PhpQuickProfiler();  | 
                                                        |
| 51 | + $this->assertAttributeEquals($startTime, 'startTime', $profiler);  | 
                                                        |
| 52 | +  | 
                                                        |
| 53 | + $profiler = new PhpQuickProfiler($startTime);  | 
                                                        |
| 54 | + $this->assertAttributeEquals($startTime, 'startTime', $profiler);  | 
                                                        |
| 55 | + }  | 
                                                        |
| 56 | +  | 
                                                        |
| 57 | + public function testSetConsole()  | 
                                                        |
| 58 | +	{ | 
                                                        |
| 59 | + $console = new Console();  | 
                                                        |
| 60 | + $profiler = new PhpQuickProfiler();  | 
                                                        |
| 61 | + $profiler->setConsole($console);  | 
                                                        |
| 62 | +  | 
                                                        |
| 63 | + $this->assertAttributeSame($console, 'console', $profiler);  | 
                                                        |
| 64 | + }  | 
                                                        |
| 65 | +  | 
                                                        |
| 66 | + public function testSetDisplay()  | 
                                                        |
| 67 | +	{ | 
                                                        |
| 68 | + $display = new Display();  | 
                                                        |
| 69 | + $profiler = new PhpQuickProfiler();  | 
                                                        |
| 70 | + $profiler->setDisplay($display);  | 
                                                        |
| 71 | +  | 
                                                        |
| 72 | + $this->assertAttributeSame($display, 'display', $profiler);  | 
                                                        |
| 73 | + }  | 
                                                        |
| 74 | +  | 
                                                        |
| 75 | + public function testGatherFileData()  | 
                                                        |
| 76 | +	{ | 
                                                        |
| 77 | + $files = get_included_files();  | 
                                                        |
| 78 | + $profiler = new PhpQuickProfiler();  | 
                                                        |
| 79 | + $gatheredFileData = $profiler->gatherFileData();  | 
                                                        |
| 80 | +  | 
                                                        |
| 81 | +		foreach ($gatheredFileData as $fileData) { | 
                                                        |
| 82 | +			$this->assertArrayHasKey('name', $fileData); | 
                                                        |
| 83 | + $this->assertContains($fileData['name'], $files);  | 
                                                        |
| 84 | +			$this->assertArrayHasKey('size', $fileData); | 
                                                        |
| 85 | + $this->assertEquals($fileData['size'], filesize($fileData['name']));  | 
                                                        |
| 86 | + }  | 
                                                        |
| 87 | + }  | 
                                                        |
| 88 | +  | 
                                                        |
| 89 | + public function testGatherMemoryData()  | 
                                                        |
| 90 | +	{ | 
                                                        |
| 91 | + $memory_usage = memory_get_peak_usage();  | 
                                                        |
| 92 | +		$allowed_limit = ini_get('memory_limit'); | 
                                                        |
| 93 | + $profiler = new PhpQuickProfiler();  | 
                                                        |
| 94 | + $gatheredMemoryData = $profiler->gatherMemoryData();  | 
                                                        |
| 95 | +  | 
                                                        |
| 96 | +		$this->assertArrayHasKey('used', $gatheredMemoryData); | 
                                                        |
| 97 | + $this->assertEquals($memory_usage, $gatheredMemoryData['used']);  | 
                                                        |
| 98 | +		$this->assertArrayHasKey('allowed', $gatheredMemoryData); | 
                                                        |
| 99 | + $this->assertEquals($allowed_limit, $gatheredMemoryData['allowed']);  | 
                                                        |
| 100 | + }  | 
                                                        |
| 101 | +  | 
                                                        |
| 102 | + public function testSetProfiledQueries()  | 
                                                        |
| 103 | +	{ | 
                                                        |
| 104 | + $profiledQueries = array(  | 
                                                        |
| 105 | + 'sql' => 'SELECT * FROM example',  | 
                                                        |
| 106 | + 'time' => 25  | 
                                                        |
| 107 | + );  | 
                                                        |
| 108 | + $profiler = new PhpQuickProfiler();  | 
                                                        |
| 109 | + $profiler->setProfiledQueries($profiledQueries);  | 
                                                        |
| 110 | +  | 
                                                        |
| 111 | + $this->assertAttributeEquals($profiledQueries, 'profiledQueries', $profiler);  | 
                                                        |
| 112 | + }  | 
                                                        |
| 113 | 113 | }  |