_restoreError) { restore_error_handler(); } } /** * testDocRef method * * @return void */ public function testDocRef() { ini_set('docref_root', ''); $this->assertEquals(ini_get('docref_root'), ''); new Debugger(); $this->assertEquals(ini_get('docref_root'), 'http://php.net/'); } /** * test Excerpt writing * * @return void */ public function testExcerpt() { $result = Debugger::excerpt(__FILE__, __LINE__, 2); $this->assertTrue(is_array($result)); $this->assertEquals(5, count($result)); $this->assertMatchesRegularExpression('/function(.+)testExcerpt/', $result[1]); $result = Debugger::excerpt(__FILE__, 2, 2); $this->assertTrue(is_array($result)); $this->assertEquals(4, count($result)); $pattern = '/.*?.*?<\?php/'; $this->assertMatchesRegularExpression($pattern, $result[0]); $result = Debugger::excerpt(__FILE__, 11, 2); $this->assertEquals(5, count($result)); $pattern = '/\*<\/span>/'; $this->assertMatchesRegularExpression($pattern, $result[0]); $return = Debugger::excerpt('[internal]', 2, 2); $this->assertTrue(empty($return)); } /** * testOutput method * * @return void */ public function testOutput() { // In PHP8.0+, // the errcontext argument will no longer be passed to custom error handlers set with set_error_handler(). // see: https://www.php.net/manual/en/migration80.incompatible.php // Therefore, the contents of the Context (variables that existed in the scope the error was triggered in) // are not output when a PHP error occurs. // Except for the above, Debugger::output() works. // However, it is incomplete, so marked. if (PHP_MAJOR_VERSION >= 8) { $this->markTestIncomplete('Context output no longer works in PHP 8.0+.'); } set_error_handler('Debugger::showError'); $this->_restoreError = true; $result = Debugger::output(false); $this->assertEquals('', $result); $out .= ''; $result = Debugger::output(true); $this->assertEquals('Notice', $result[0]['error']); $this->assertMatchesRegularExpression('/Undefined variable\:\s+out/', $result[0]['description']); $this->assertMatchesRegularExpression('/DebuggerTest::testOutput/i', $result[0]['trace']); ob_start(); Debugger::output('txt'); $other .= ''; $result = ob_get_clean(); $this->assertMatchesRegularExpression('/Undefined variable:\s+other/', $result); $this->assertMatchesRegularExpression('/Context:/', $result); $this->assertMatchesRegularExpression('/DebuggerTest::testOutput/i', $result); ob_start(); Debugger::output('html'); $wrong .= ''; $result = ob_get_clean(); $this->assertMatchesRegularExpression('/
.+<\/pre>/', $result);
		$this->assertMatchesRegularExpression('/Notice<\/b>/', $result);
		$this->assertMatchesRegularExpression('/variable:\s+wrong/', $result);

		ob_start();
		Debugger::output('js');
		$buzz .= '';
		$result = explode('', ob_get_clean());
		$this->assertTags($result[0], array(
			'pre' => array('class' => 'cake-error'),
			'a' => array(
				'href' => "javascript:void(0);",
				'onclick' => "preg:/document\.getElementById\('cakeErr[a-z0-9]+\-trace'\)\.style\.display = " .
					"\(document\.getElementById\('cakeErr[a-z0-9]+\-trace'\)\.style\.display == 'none'" .
					" \? '' \: 'none'\);/"
			),
			'b' => array(), 'Notice', '/b', ' (8)',
		));

		$this->assertMatchesRegularExpression('/Undefined variable:\s+buzz/', $result[1]);
		$this->assertMatchesRegularExpression('/]+>Code/', $result[1]);
		$this->assertMatchesRegularExpression('/]+>Context/', $result[2]);
		$this->assertStringContainsString('$wrong = ''', $result[3], 'Context should be HTML escaped.');
	}

/**
 * test encodes error messages
 *
 * @return void
 */
	public function testOutputEncodeDescription() {
		set_error_handler('Debugger::showError');
		$this->_restoreError = true;

		ob_start();
		Debugger::output('js');
		$a = array();
		$b = $a[''];
		$result = ob_get_clean();

		$this->assertStringNotContainsString('