* @link http://netmonsters.ru * @package Majestic * @subpackage UnitTests * @since 2011-10-28 * * Unit tests for CommandProfiler class */ 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/profiler/Profiler.php'; /** * @TODO: Profiler->getJson() hardly depends on FB library */ class ProfilerTest extends PHPUnit_Framework_TestCase { public function run(PHPUnit_Framework_TestResult $result = NULL) { $this->setPreserveGlobalState(false); return parent::run($result); } public function setUp() { set_new_overload(array($this, 'newCallback')); } /** * @expectedException GeneralException * @expectedExceptionMessage Need to turn on DEBUG before use. * @runInSeparateProcess */ public function testGetInstaceNoDebug() { if (!defined('DEBUG')) { define('DEBUG', false); } Profiler::getInstance(); } /** * @runInSeparateProcess */ public function testGetInstance() { if (!defined('DEBUG')) { define('DEBUG', true); } $profiler = Profiler::getInstance(); $this->assertInstanceOf('Profiler', $profiler); $this->assertSame($profiler, Profiler::getInstance()); } /** * @runInSeparateProcess */ public function testProfilerCommand() { if (!defined('DEBUG')) { define('DEBUG', true); } $this->getMock('CommandProfiler', array('getType', 'getCommand', 'getElapsed'), array(), 'CommandProfilerMock', false); $profiler = Profiler::getInstance(); $cmdProfiler = $profiler->profilerCommand('command', 'type'); $this->assertInstanceOf('CommandProfiler', $cmdProfiler); } /** * @runInSeparateProcess */ public function testStartEndNoCommandProfiler() { if (!defined('DEBUG')) { define('DEBUG', true); } $profiler = Profiler::getInstance(); $profiler->start(); $result = $profiler->end('
'); $this->assertNotEquals('', $result); $this->assertStringStartsWith('', $result); $this->assertStringEndsWith(']