'bar', 'inner' => new self()]; } } class SecurityThing { public $password = 'pass1234'; } /** * DebuggerTest class * * !!! Be careful with changing code below as it may * !!! change line numbers which are used in the tests */ class DebuggerTest extends TestCase { protected $_restoreError = false; /** * setUp method * * @return void */ public function setUp() { parent::setUp(); Configure::write('debug', true); Log::drop('stderr'); Log::drop('stdout'); } /** * tearDown method * * @return void */ public function tearDown() { parent::tearDown(); if ($this->_restoreError) { restore_error_handler(); } } /** * testDocRef method * * @return void */ public function testDocRef() { $this->skipIf( defined('HHVM_VERSION'), 'HHVM does not output doc references' ); ini_set('docref_root', ''); $this->assertEquals(ini_get('docref_root'), ''); new Debugger(); $this->assertEquals(ini_get('docref_root'), 'https://secure.php.net/'); } /** * test Excerpt writing * * @return void */ public function testExcerpt() { $result = Debugger::excerpt(__FILE__, __LINE__ - 1, 2); $this->assertTrue(is_array($result)); $this->assertCount(5, $result); $this->assertRegExp('/function(.+)testExcerpt/', $result[1]); $result = Debugger::excerpt(__FILE__, 2, 2); $this->assertTrue(is_array($result)); $this->assertCount(4, $result); $this->skipIf(defined('HHVM_VERSION'), 'HHVM does not highlight php code'); $pattern = '/.*?.*?<\?php/'; $this->assertRegExp($pattern, $result[0]); $result = Debugger::excerpt(__FILE__, 11, 2); $this->assertCount(5, $result); $pattern = '/\*<\/span>/'; $this->assertRegExp($pattern, $result[0]); $return = Debugger::excerpt('[internal]', 2, 2); $this->assertEmpty($return); $result = Debugger::excerpt(__FILE__, __LINE__, 5); $this->assertCount(11, $result); $this->assertContains('Debugger', $result[5]); $this->assertContains('excerpt', $result[5]); $this->assertContains('__FILE__', $result[5]); $result = Debugger::excerpt(__FILE__, 1, 2); $this->assertCount(3, $result); $lastLine = count(explode("\n", file_get_contents(__FILE__))); $result = Debugger::excerpt(__FILE__, $lastLine, 2); $this->assertCount(3, $result); } /** * Test that outputAs works. * * @group deprecated * @return void */ public function testOutputAs() { $this->deprecated(function () { Debugger::outputAs('html'); $this->assertEquals('html', Debugger::outputAs()); }); } /** * Test that setOutputFormat works. * * @return void */ public function testSetOutputFormat() { Debugger::setOutputFormat('html'); $this->assertEquals('html', Debugger::getOutputFormat()); } /** * Test that choosing a non-existent format causes an exception * * @group deprecated * @expectedException \InvalidArgumentException * @return void */ public function testOutputAsException() { $this->deprecated(function () { Debugger::outputAs('Invalid junk'); }); } /** * Test that getOutputFormat/setOutputFormat works. * * @return void */ public function testGetSetOutputFormat() { Debugger::setOutputFormat('html'); $this->assertEquals('html', Debugger::getOutputFormat()); } /** * Test that choosing a non-existent format causes an exception * * @expectedException \InvalidArgumentException * @return void */ public function testSetOutputAsException() { Debugger::setOutputFormat('Invalid junk'); } /** * Test outputError with description encoding * * @return void */ public function testOutputErrorDescriptionEncoding() { Debugger::setOutputFormat('html'); ob_start(); $debugger = Debugger::getInstance(); $debugger->outputError([ 'error' => 'Notice', 'code' => E_NOTICE, 'level' => E_NOTICE, 'description' => 'Undefined index ', 'file' => __FILE__, 'line' => __LINE__, ]); $result = ob_get_clean(); $this->assertContains('<script>', $result); $this->assertNotContains('