Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #306 from doctrine/DCOM-162

DCOM-162 - Returning the dumped value in `Doctrine\Common\Util\Debug::dump()`
  • Loading branch information...
commit ba2ad8a7db24adb37a33ff52ee64b02d59ccfee0 2 parents ad26be7 + 17711b7
@guilhermeblanco guilhermeblanco authored
View
15 lib/Doctrine/Common/Util/Debug.php
@@ -48,8 +48,11 @@ private function __construct()
* @param mixed $var The variable to dump.
* @param integer $maxDepth The maximum nesting level for object properties.
* @param boolean $stripTags Whether output should strip HTML tags.
+ * @param boolean $echo Send the dumped value to the output buffer
+ *
+ * @return string
*/
- public static function dump($var, $maxDepth = 2, $stripTags = true)
+ public static function dump($var, $maxDepth = 2, $stripTags = true, $echo = true)
{
$html = ini_get('html_errors');
@@ -65,12 +68,20 @@ public static function dump($var, $maxDepth = 2, $stripTags = true)
ob_start();
var_dump($var);
+
$dump = ob_get_contents();
+
ob_end_clean();
- echo ($stripTags ? strip_tags(html_entity_decode($dump)) : $dump);
+ $dumpText = ($stripTags ? strip_tags(html_entity_decode($dump)) : $dump);
ini_set('html_errors', $html);
+
+ if ($echo) {
+ echo $dumpText;
+ }
+
+ return $dumpText;
}
/**
View
25 tests/Doctrine/Tests/Common/Util/DebugTest.php
@@ -37,4 +37,29 @@ public function testExportArrayTraversable()
$var = Debug::export($it, 5);
$this->assertContains('foobar', $var->__STORAGE__);
}
+
+ public function testReturnsOutput()
+ {
+ ob_start();
+
+ $dump = Debug::dump('foo');
+ $outputValue = ob_get_contents();
+
+ ob_end_clean();
+
+ $this->assertSame($outputValue, $dump);
+ }
+
+ public function testDisablesOutput()
+ {
+ ob_start();
+
+ $dump = Debug::dump('foo', 2, true, false);
+ $outputValue = ob_get_contents();
+
+ ob_end_clean();
+
+ $this->assertEmpty($outputValue);
+ $this->assertNotSame($outputValue, $dump);
+ }
}
Please sign in to comment.
Something went wrong with that request. Please try again.