|
@ -10,6 +10,8 @@ |
|
|
* Unit tests for CommandProfiler class |
|
|
* Unit tests for CommandProfiler class |
|
|
*/ |
|
|
*/ |
|
|
|
|
|
|
|
|
|
|
|
require_once dirname(__FILE__) . '/../../../Registry.php'; |
|
|
|
|
|
require_once dirname(__FILE__) . '/../../../Config.php'; |
|
|
require_once dirname(__FILE__) . '/../../../exception/GeneralException.php'; |
|
|
require_once dirname(__FILE__) . '/../../../exception/GeneralException.php'; |
|
|
require_once dirname(__FILE__) . '/../../../util/FirePHPCore-0.3.2/lib/FirePHPCore/fb.php'; |
|
|
require_once dirname(__FILE__) . '/../../../util/FirePHPCore-0.3.2/lib/FirePHPCore/fb.php'; |
|
|
require_once dirname(__FILE__) . '/../../../util/profiler/Profiler.php'; |
|
|
require_once dirname(__FILE__) . '/../../../util/profiler/Profiler.php'; |
|
@ -36,10 +38,8 @@ class ProfilerTest extends PHPUnit_Framework_TestCase |
|
|
*/ |
|
|
*/ |
|
|
public function testGetInstaceNoDebug() |
|
|
public function testGetInstaceNoDebug() |
|
|
{ |
|
|
{ |
|
|
if (!defined('DEBUG')) { |
|
|
Config::set('PROFILER', false); |
|
|
define('DEBUG', false); |
|
|
$this->setExpectedException('GeneralException', 'Need turn PROFILER before use.'); |
|
|
} |
|
|
|
|
|
$this->setExpectedException('GeneralException', 'Need to turn on DEBUG before use.'); |
|
|
|
|
|
Profiler::getInstance(); |
|
|
Profiler::getInstance(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -48,9 +48,7 @@ class ProfilerTest extends PHPUnit_Framework_TestCase |
|
|
*/ |
|
|
*/ |
|
|
public function testGetInstance() |
|
|
public function testGetInstance() |
|
|
{ |
|
|
{ |
|
|
if (!defined('DEBUG')) { |
|
|
Config::set('PROFILER', true); |
|
|
define('DEBUG', true); |
|
|
|
|
|
} |
|
|
|
|
|
$profiler = Profiler::getInstance(); |
|
|
$profiler = Profiler::getInstance(); |
|
|
$this->assertInstanceOf('Profiler', $profiler); |
|
|
$this->assertInstanceOf('Profiler', $profiler); |
|
|
$this->assertSame($profiler, Profiler::getInstance()); |
|
|
$this->assertSame($profiler, Profiler::getInstance()); |
|
@ -61,9 +59,7 @@ class ProfilerTest extends PHPUnit_Framework_TestCase |
|
|
*/ |
|
|
*/ |
|
|
public function testProfilerCommand() |
|
|
public function testProfilerCommand() |
|
|
{ |
|
|
{ |
|
|
if (!defined('DEBUG')) { |
|
|
Config::set('PROFILER', true); |
|
|
define('DEBUG', true); |
|
|
|
|
|
} |
|
|
|
|
|
$this->getMock('CommandProfiler', array('getType', 'getCommand', 'getElapsed'), array(), 'CommandProfilerMock', false); |
|
|
$this->getMock('CommandProfiler', array('getType', 'getCommand', 'getElapsed'), array(), 'CommandProfilerMock', false); |
|
|
$profiler = Profiler::getInstance(); |
|
|
$profiler = Profiler::getInstance(); |
|
|
$cmdProfiler = $profiler->profilerCommand('command', 'type'); |
|
|
$cmdProfiler = $profiler->profilerCommand('command', 'type'); |
|
@ -75,9 +71,8 @@ class ProfilerTest extends PHPUnit_Framework_TestCase |
|
|
*/ |
|
|
*/ |
|
|
public function testStartEndNoCommandProfiler() |
|
|
public function testStartEndNoCommandProfiler() |
|
|
{ |
|
|
{ |
|
|
if (!defined('DEBUG')) { |
|
|
Config::set('PROFILER', true); |
|
|
define('DEBUG', true); |
|
|
Config::set('PROFILER_DETAILS', true); |
|
|
} |
|
|
|
|
|
$profiler = Profiler::getInstance(); |
|
|
$profiler = Profiler::getInstance(); |
|
|
$profiler->start(); |
|
|
$profiler->start(); |
|
|
$result = $profiler->end('<body></body>'); |
|
|
$result = $profiler->end('<body></body>'); |
|
@ -95,15 +90,15 @@ class ProfilerTest extends PHPUnit_Framework_TestCase |
|
|
*/ |
|
|
*/ |
|
|
public function testStartEndWithCommandProfiler() |
|
|
public function testStartEndWithCommandProfiler() |
|
|
{ |
|
|
{ |
|
|
if (!defined('DEBUG')) { |
|
|
Config::set('PROFILER', true); |
|
|
define('DEBUG', true); |
|
|
Config::set('PROFILER_DETAILS', true); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
$this->getMock('CommandProfiler', array('getType', 'getCommand', 'getElapsed'), array(), 'CommandProfilerMock', false); |
|
|
$this->getMock('CommandProfiler', array('getType', 'getCommand', 'getElapsed'), array(), 'CommandProfilerMock', false); |
|
|
$profiler = Profiler::getInstance(); |
|
|
$profiler = Profiler::getInstance(); |
|
|
$cmdProfiler = $profiler->profilerCommand('command', 'type'); |
|
|
|
|
|
|
|
|
|
|
|
$profiler->start(); |
|
|
$profiler->start(); |
|
|
|
|
|
$cmdProfiler = $profiler->profilerCommand('command', 'type'); |
|
|
|
|
|
$this->assertNotNull($cmdProfiler); |
|
|
$result = $profiler->end('<body></body>'); |
|
|
$result = $profiler->end('<body></body>'); |
|
|
$this->assertNotEquals('<body></body>', $result); |
|
|
$this->assertNotEquals('<body></body>', $result); |
|
|
$this->assertStringEndsNotWith(']<br/></div></body>', $result); |
|
|
$this->assertStringEndsNotWith(']<br/></div></body>', $result); |
|
@ -113,15 +108,145 @@ class ProfilerTest extends PHPUnit_Framework_TestCase |
|
|
/** |
|
|
/** |
|
|
* @runInSeparateProcess |
|
|
* @runInSeparateProcess |
|
|
*/ |
|
|
*/ |
|
|
|
|
|
public function testStartEndWithCommandProfilerWithNonDetails() |
|
|
|
|
|
{ |
|
|
|
|
|
Config::set('PROFILER', true); |
|
|
|
|
|
Config::set('PROFILER_DETAILS', false); |
|
|
|
|
|
|
|
|
|
|
|
$this->getMock('CommandProfiler', array('getType', 'getCommand', 'getElapsed'), array(), 'CommandProfilerMock', false); |
|
|
|
|
|
$profiler = Profiler::getInstance(); |
|
|
|
|
|
$profiler->start(); |
|
|
|
|
|
$result = $profiler->end('<body></body>'); |
|
|
|
|
|
$this->assertNotEquals('<body></body>', $result); |
|
|
|
|
|
$this->assertContains('Queries not counted.', $result); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* @runInSeparateProcess |
|
|
|
|
|
*/ |
|
|
|
|
|
public function testStartEndWithCommandProfilerWithNonDetailsButExistingQueries() |
|
|
|
|
|
{ |
|
|
|
|
|
Config::set('PROFILER', true); |
|
|
|
|
|
Config::set('PROFILER_DETAILS', false); |
|
|
|
|
|
|
|
|
|
|
|
$this->getMock('CommandProfiler', array('getType', 'getCommand', 'getElapsed'), array(), 'CommandProfilerMock', false); |
|
|
|
|
|
$profiler = Profiler::getInstance(); |
|
|
|
|
|
$profiler->start(); |
|
|
|
|
|
$cmdProfiler = $profiler->profilerCommand('command', 'type'); |
|
|
|
|
|
$result = $profiler->end('<body></body>'); |
|
|
|
|
|
$this->assertNotEquals('<body></body>', $result); |
|
|
|
|
|
$this->assertStringEndsNotWith(']<br/></div></body>', $result); |
|
|
|
|
|
$this->assertContains('Queries: 1', $result); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* @runInSeparateProcess |
|
|
|
|
|
*/ |
|
|
|
|
|
public function testStartEndWithCommandProfilerWithDetailsButNonQueries() |
|
|
|
|
|
{ |
|
|
|
|
|
Config::set('PROFILER', true); |
|
|
|
|
|
Config::set('PROFILER_DETAILS', true); |
|
|
|
|
|
|
|
|
|
|
|
$this->getMock('CommandProfiler', array('getType', 'getCommand', 'getElapsed'), array(), 'CommandProfilerMock', false); |
|
|
|
|
|
$profiler = Profiler::getInstance(); |
|
|
|
|
|
$profiler->start(); |
|
|
|
|
|
$result = $profiler->end('<body></body>'); |
|
|
|
|
|
$this->assertNotEquals('<body></body>', $result); |
|
|
|
|
|
$this->assertStringEndsWith(']<br/></div></body>', $result); |
|
|
|
|
|
$this->assertContains('Queries: 0', $result); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* @runInSeparateProcess |
|
|
|
|
|
*/ |
|
|
public function testGetJSON() |
|
|
public function testGetJSON() |
|
|
{ |
|
|
{ |
|
|
if (!defined('DEBUG')) { |
|
|
Config::set('PROFILER', true); |
|
|
define('DEBUG', true); |
|
|
Config::set('PROFILER_DETAILS', true); |
|
|
|
|
|
|
|
|
|
|
|
$this->getMock('CommandProfiler', array('getType', 'getCommand', 'getElapsed'), array(), 'CommandProfilerMock', false); |
|
|
|
|
|
$profiler = Profiler::getInstance(); |
|
|
|
|
|
$cmdProfiler = $profiler->profilerCommand('command', 'type'); |
|
|
|
|
|
$fire_php_mock = $this->getMockBuilder('FirePHP') |
|
|
|
|
|
->disableOriginalConstructor() |
|
|
|
|
|
->setMethods(array('__construct', 'fb')) |
|
|
|
|
|
->getMock(); |
|
|
|
|
|
$fire_php_mock->expects($this->exactly(2)) |
|
|
|
|
|
->method('fb') |
|
|
|
|
|
->with($this->anything(), $this->logicalAnd($this->logicalXor($this->anything(), $this->stringContains('Queries not'))), $this->logicalXor($this->anything(), $this->stringContains('Queries: 0'))); // Expected "Queries: 1"
|
|
|
|
|
|
$reflection_property = new ReflectionProperty('FirePHP', 'instance'); |
|
|
|
|
|
$reflection_property->setAccessible(true); |
|
|
|
|
|
$reflection_property->setValue($fire_php_mock); |
|
|
|
|
|
$this->assertNull($profiler->getJson()); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* @runInSeparateProcess |
|
|
|
|
|
*/ |
|
|
|
|
|
public function testGetJSONWithNonDetails() |
|
|
|
|
|
{ |
|
|
|
|
|
Config::set('PROFILER', true); |
|
|
|
|
|
Config::set('PROFILER_DETAILS', false); |
|
|
|
|
|
|
|
|
|
|
|
$this->getMock('CommandProfiler', array('getType', 'getCommand', 'getElapsed'), array(), 'CommandProfilerMock', false); |
|
|
|
|
|
$profiler = Profiler::getInstance(); |
|
|
|
|
|
$fire_php_mock = $this->getMockBuilder('FirePHP') |
|
|
|
|
|
->disableOriginalConstructor() |
|
|
|
|
|
->setMethods(array('__construct', 'fb')) |
|
|
|
|
|
->getMock(); |
|
|
|
|
|
$fire_php_mock->expects($this->exactly(2)) |
|
|
|
|
|
->method('fb') |
|
|
|
|
|
->with($this->anything(), $this->logicalAnd($this->logicalXor($this->anything(), $this->stringContains('Queries: 1'))), $this->logicalXor($this->anything(), $this->stringContains('Queries: 0'))); // expected "Queries not counted"
|
|
|
|
|
|
$reflection_property = new ReflectionProperty('FirePHP', 'instance'); |
|
|
|
|
|
$reflection_property->setAccessible(true); |
|
|
|
|
|
$reflection_property->setValue($fire_php_mock); |
|
|
|
|
|
$this->assertNull($profiler->getJson()); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* @runInSeparateProcess |
|
|
|
|
|
*/ |
|
|
|
|
|
public function testGetJSONWithNonDetailsButExistingQueries() |
|
|
|
|
|
{ |
|
|
|
|
|
Config::set('PROFILER', true); |
|
|
|
|
|
Config::set('PROFILER_DETAILS', false); |
|
|
|
|
|
|
|
|
$this->getMock('CommandProfiler', array('getType', 'getCommand', 'getElapsed'), array(), 'CommandProfilerMock', false); |
|
|
$this->getMock('CommandProfiler', array('getType', 'getCommand', 'getElapsed'), array(), 'CommandProfilerMock', false); |
|
|
$profiler = Profiler::getInstance(); |
|
|
$profiler = Profiler::getInstance(); |
|
|
$cmdProfiler = $profiler->profilerCommand('command', 'type'); |
|
|
$cmdProfiler = $profiler->profilerCommand('command', 'type'); |
|
|
|
|
|
$fire_php_mock = $this->getMockBuilder('FirePHP') |
|
|
|
|
|
->disableOriginalConstructor() |
|
|
|
|
|
->setMethods(array('__construct', 'fb')) |
|
|
|
|
|
->getMock(); |
|
|
|
|
|
$fire_php_mock->expects($this->exactly(2)) |
|
|
|
|
|
->method('fb') |
|
|
|
|
|
->with($this->anything(), $this->logicalAnd($this->logicalXor($this->anything(), $this->stringContains('Queries not counted'))), $this->logicalXor($this->anything(), $this->stringContains('Queries: 0'))); // expected "Queries: 1"
|
|
|
|
|
|
$reflection_property = new ReflectionProperty('FirePHP', 'instance'); |
|
|
|
|
|
$reflection_property->setAccessible(true); |
|
|
|
|
|
$reflection_property->setValue($fire_php_mock); |
|
|
|
|
|
$this->assertNull($profiler->getJson()); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* @runInSeparateProcess |
|
|
|
|
|
*/ |
|
|
|
|
|
public function testGetJSONWithDetailsButNonQueries() |
|
|
|
|
|
{ |
|
|
|
|
|
Config::set('PROFILER', true); |
|
|
|
|
|
Config::set('PROFILER_DETAILS', true); |
|
|
|
|
|
|
|
|
|
|
|
$this->getMock('CommandProfiler', array('getType', 'getCommand', 'getElapsed'), array(), 'CommandProfilerMock', false); |
|
|
|
|
|
$profiler = Profiler::getInstance(); |
|
|
|
|
|
$fire_php_mock = $this->getMockBuilder('FirePHP') |
|
|
|
|
|
->disableOriginalConstructor() |
|
|
|
|
|
->setMethods(array('__construct', 'fb')) |
|
|
|
|
|
->getMock(); |
|
|
|
|
|
$fire_php_mock->expects($this->exactly(2)) |
|
|
|
|
|
->method('fb') |
|
|
|
|
|
->with($this->anything(), $this->logicalAnd($this->logicalXor($this->anything(), $this->stringContains('Queries not counted'))), $this->logicalXor($this->anything(), $this->stringContains('Queries: 1'))); // expected "Queries: 0"
|
|
|
|
|
|
$reflection_property = new ReflectionProperty('FirePHP', 'instance'); |
|
|
|
|
|
$reflection_property->setAccessible(true); |
|
|
|
|
|
$reflection_property->setValue($fire_php_mock); |
|
|
$this->assertNull($profiler->getJson()); |
|
|
$this->assertNull($profiler->getJson()); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -130,21 +255,67 @@ class ProfilerTest extends PHPUnit_Framework_TestCase |
|
|
*/ |
|
|
*/ |
|
|
public function testGetCLI() |
|
|
public function testGetCLI() |
|
|
{ |
|
|
{ |
|
|
if (!defined('DEBUG')) { |
|
|
Config::set('PROFILER', true); |
|
|
define('DEBUG', true); |
|
|
Config::set('PROFILER_DETAILS', true); |
|
|
|
|
|
|
|
|
|
|
|
$this->getMock('CommandProfiler', array('getType', 'getCommand', 'getElapsed'), array(), 'CommandProfilerMock', false); |
|
|
|
|
|
$profiler = Profiler::getInstance(); |
|
|
|
|
|
$cmdProfiler = $profiler->profilerCommand('command', 'type'); |
|
|
|
|
|
$result = $profiler->getCli(); |
|
|
|
|
|
$this->assertNotNull($result); |
|
|
|
|
|
$this->assertContains('Queries: 1', Profiler::getInstance()->getCli()); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* @runInSeparateProcess |
|
|
|
|
|
*/ |
|
|
|
|
|
public function testGetCLIWithNonDetails() |
|
|
|
|
|
{ |
|
|
|
|
|
Config::set('PROFILER', true); |
|
|
|
|
|
Config::set('PROFILER_DETAILS', false); |
|
|
|
|
|
|
|
|
|
|
|
$this->getMock('CommandProfiler', array('getType', 'getCommand', 'getElapsed'), array(), 'CommandProfilerMock', false); |
|
|
|
|
|
$profiler = Profiler::getInstance(); |
|
|
|
|
|
$result = $profiler->getCli(); |
|
|
|
|
|
$this->assertNotNull($result); |
|
|
|
|
|
$this->assertContains('Queries not counted', Profiler::getInstance()->getCli()); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* @runInSeparateProcess |
|
|
|
|
|
*/ |
|
|
|
|
|
public function testGetCLIWithNonDetailsButExistingQueries() |
|
|
|
|
|
{ |
|
|
|
|
|
Config::set('PROFILER', true); |
|
|
|
|
|
Config::set('PROFILER_DETAILS', false); |
|
|
|
|
|
|
|
|
$this->getMock('CommandProfiler', array('getType', 'getCommand', 'getElapsed'), array(), 'CommandProfilerMock', false); |
|
|
$this->getMock('CommandProfiler', array('getType', 'getCommand', 'getElapsed'), array(), 'CommandProfilerMock', false); |
|
|
$profiler = Profiler::getInstance(); |
|
|
$profiler = Profiler::getInstance(); |
|
|
$cmdProfiler = $profiler->profilerCommand('command', 'type'); |
|
|
$cmdProfiler = $profiler->profilerCommand('command', 'type'); |
|
|
$result = $profiler->getCli(); |
|
|
$result = $profiler->getCli(); |
|
|
$this->assertNotNull($result); |
|
|
$this->assertNotNull($result); |
|
|
|
|
|
$this->assertContains('Queries: 1', Profiler::getInstance()->getCli()); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* @runInSeparateProcess |
|
|
|
|
|
*/ |
|
|
|
|
|
public function testGetCLIWithDetailsButNonQueries() |
|
|
|
|
|
{ |
|
|
|
|
|
Config::set('PROFILER', true); |
|
|
|
|
|
Config::set('PROFILER_DETAILS', true); |
|
|
|
|
|
|
|
|
|
|
|
$this->getMock('CommandProfiler', array('getType', 'getCommand', 'getElapsed'), array(), 'CommandProfilerMock', false); |
|
|
|
|
|
$profiler = Profiler::getInstance(); |
|
|
|
|
|
$result = $profiler->getCli(); |
|
|
|
|
|
$this->assertNotNull($result); |
|
|
|
|
|
$this->assertContains('Queries: 0', Profiler::getInstance()->getCli()); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public function tearDown() |
|
|
public function tearDown() |
|
|
{ |
|
|
{ |
|
|
// if (defined('DEBUG')) {
|
|
|
// if (!is_null(Config::get('DEBUG'))) {
|
|
|
// $debug = DEBUG ? 'TRUE' : 'FALSE';
|
|
|
// $debug = Config::get('DEBUG') ? 'TRUE' : 'FALSE';
|
|
|
// echo PHP_EOL . __CLASS__ . ' ' . $debug . PHP_EOL;
|
|
|
// echo PHP_EOL . __CLASS__ . ' ' . $debug . PHP_EOL;
|
|
|
// } else {
|
|
|
// } else {
|
|
|
// echo PHP_EOL . __CLASS__ . ' ' . 'DEBUG NOT DEFINED' . PHP_EOL;
|
|
|
// echo PHP_EOL . __CLASS__ . ' ' . 'DEBUG NOT DEFINED' . PHP_EOL;
|
|
|
xxxxxxxxxx