Skip to content

Commit

Permalink
Re-add SQL to Query exports.
Browse files Browse the repository at this point in the history
More than just Query objects can raise exceptions in their __debugInfo
method. Debugger should be catching and gracefully handling that
situation.
  • Loading branch information
markstory committed Aug 21, 2014
1 parent bcd672f commit f7597d4
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 5 deletions.
1 change: 1 addition & 0 deletions src/Database/Query.php
Expand Up @@ -1605,6 +1605,7 @@ public function __toString() {
*/
public function __debugInfo() {
return [
'sql' => $this->sql(),
'params' => $this->valueBinder()->bindings(),
'defaultTypes' => $this->defaultTypes(),
'decorators' => count($this->_resultDecorators),
Expand Down
10 changes: 7 additions & 3 deletions src/Utility/Debugger.php
Expand Up @@ -577,9 +577,13 @@ protected static function _object($var, $depth, $indent) {
$end = "\n" . str_repeat("\t", $indent - 1);

if ($depth > 0 && method_exists($var, '__debugInfo')) {
return $out . "\n" .
substr(static::_array($var->__debugInfo(), $depth - 1, $indent), 1, -1) .
$end . '}';
try {
return $out . "\n" .
substr(static::_array($var->__debugInfo(), $depth - 1, $indent), 1, -1) .
$end . '}';
} catch (\Exception $e) {
return $out . "\n(unable to export object)\n }";
}
}

if ($depth > 0) {
Expand Down
8 changes: 6 additions & 2 deletions tests/TestCase/Database/QueryTest.php
Expand Up @@ -2658,7 +2658,10 @@ public function testDebugInfo() {
->where(['id' => '1']);

$expected = [
'params' => [],
'sql' => $query->sql(),
'params' => [
':c0' => ['value' => '1', 'type' => 'integer', 'placeholder' => 'c0']
],
'defaultTypes' => ['id' => 'integer'],
'decorators' => 0,
'executed' => false
Expand All @@ -2668,6 +2671,7 @@ public function testDebugInfo() {

$query->execute();
$expected = [
'sql' => $query->sql(),
'params' => [
':c0' => ['value' => '1', 'type' => 'integer', 'placeholder' => 'c0']
],
Expand All @@ -2676,7 +2680,7 @@ public function testDebugInfo() {
'executed' => true
];
$result = $query->__debugInfo();
$this->assertEquals($result, $expected);
$this->assertEquals($expected, $result);
}

/**
Expand Down
1 change: 1 addition & 0 deletions tests/TestCase/ORM/QueryTest.php
Expand Up @@ -1835,6 +1835,7 @@ public function testDebugInfo() {
});

$expected = [
'sql' => $query->sql(),
'params' => $query->valueBinder()->bindings(),
'defaultTypes' => [
'authors.id' => 'integer',
Expand Down

0 comments on commit f7597d4

Please sign in to comment.