Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
debug() may output path that is incorrectly truncated
This happens when debug is called in core source files that resides in
a different directory to the app.
  • Loading branch information
rchavik committed Jun 1, 2012
1 parent fb0cc50 commit 483d712
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
23 changes: 12 additions & 11 deletions lib/Cake/Test/Case/BasicsTest.php
Expand Up @@ -691,7 +691,8 @@ public function testDebug() {
'this-is-a-test'
###########################
EXPECTED;
$expected = sprintf($expectedText, substr(__FILE__, strlen(ROOT)), __LINE__ - 8);
$expected = sprintf($expectedText, str_replace(CAKE_CORE_INCLUDE_PATH, '', __FILE__), __LINE__ - 8);

$this->assertEquals($expected, $result);

ob_start();
Expand All @@ -705,7 +706,7 @@ public function testDebug() {
</pre>
</div>
EXPECTED;
$expected = sprintf($expectedHtml, substr(__FILE__, strlen(ROOT)), __LINE__ - 10);
$expected = sprintf($expectedHtml, str_replace(CAKE_CORE_INCLUDE_PATH, '', __FILE__), __LINE__ - 10);
$this->assertEquals($expected, $result);

ob_start();
Expand All @@ -719,7 +720,7 @@ public function testDebug() {
</pre>
</div>
EXPECTED;
$expected = sprintf($expected, substr(__FILE__, strlen(ROOT)), __LINE__ - 10);
$expected = sprintf($expected, str_replace(CAKE_CORE_INCLUDE_PATH, '', __FILE__), __LINE__ - 10);
$this->assertEquals($expected, $result);

ob_start();
Expand All @@ -733,7 +734,7 @@ public function testDebug() {
</pre>
</div>
EXPECTED;
$expected = sprintf($expected, substr(__FILE__, strlen(ROOT)), __LINE__ - 10);
$expected = sprintf($expected, str_replace(CAKE_CORE_INCLUDE_PATH, '', __FILE__), __LINE__ - 10);
$this->assertEquals($expected, $result);

ob_start();
Expand All @@ -754,9 +755,9 @@ public function testDebug() {
###########################
EXPECTED;
if (php_sapi_name() == 'cli') {
$expected = sprintf($expectedText, substr(__FILE__, strlen(ROOT)), __LINE__ - 17);
$expected = sprintf($expectedText, str_replace(CAKE_CORE_INCLUDE_PATH, '', __FILE__), __LINE__ - 17);
} else {
$expected = sprintf($expectedHtml, substr(__FILE__, strlen(ROOT)), __LINE__ - 19);
$expected = sprintf($expectedHtml, str_replace(CAKE_CORE_INCLUDE_PATH, '', __FILE__), __LINE__ - 19);
}
$this->assertEquals($expected, $result);

Expand All @@ -778,9 +779,9 @@ public function testDebug() {
###########################
EXPECTED;
if (php_sapi_name() == 'cli') {
$expected = sprintf($expectedText, substr(__FILE__, strlen(ROOT)), __LINE__ - 17);
$expected = sprintf($expectedText, str_replace(CAKE_CORE_INCLUDE_PATH, '', __FILE__), __LINE__ - 17);
} else {
$expected = sprintf($expectedHtml, substr(__FILE__, strlen(ROOT)), __LINE__ - 19);
$expected = sprintf($expectedHtml, str_replace(CAKE_CORE_INCLUDE_PATH, '', __FILE__), __LINE__ - 19);
}
$this->assertEquals($expected, $result);

Expand All @@ -793,7 +794,7 @@ public function testDebug() {
'<div>this-is-a-test</div>'
###########################
EXPECTED;
$expected = sprintf($expected, substr(__FILE__, strlen(ROOT)), __LINE__ - 8);
$expected = sprintf($expected, str_replace(CAKE_CORE_INCLUDE_PATH, '', __FILE__), __LINE__ - 8);
$this->assertEquals($expected, $result);

ob_start();
Expand All @@ -805,7 +806,7 @@ public function testDebug() {
'<div>this-is-a-test</div>'
###########################
EXPECTED;
$expected = sprintf($expected, substr(__FILE__, strlen(ROOT)), __LINE__ - 8);
$expected = sprintf($expected, str_replace(CAKE_CORE_INCLUDE_PATH, '', __FILE__), __LINE__ - 8);
$this->assertEquals($expected, $result);

ob_start();
Expand All @@ -817,7 +818,7 @@ public function testDebug() {
'<div>this-is-a-test</div>'
###########################
EXPECTED;
$expected = sprintf($expected, substr(__FILE__, strlen(ROOT)), __LINE__ - 8);
$expected = sprintf($expected, str_replace(CAKE_CORE_INCLUDE_PATH, '', __FILE__), __LINE__ - 8);
$this->assertEquals($expected, $result);
}

Expand Down
2 changes: 1 addition & 1 deletion lib/Cake/basics.php
Expand Up @@ -77,7 +77,7 @@ function debug($var = false, $showHtml = null, $showFrom = true) {
$lineInfo = '';
if ($showFrom) {
$trace = Debugger::trace(array('start' => 1, 'depth' => 2, 'format' => 'array'));
$file = substr($trace[0]['file'], strlen(ROOT));
$file = str_replace(array(CAKE_CORE_INCLUDE_PATH, ROOT), '', $trace[0]['file']);
$line = $trace[0]['line'];
}
$html = <<<HTML
Expand Down

0 comments on commit 483d712

Please sign in to comment.