Browse Source

Merge pull request #6564 from cakephp/better-debug-info

Improved __debugInfo for Entity and Query
Mark Story 11 years ago
parent
commit
8e85e1cb25

+ 1 - 0
src/Database/Query.php

@@ -1696,6 +1696,7 @@ class Query implements ExpressionInterface, IteratorAggregate
     public function __debugInfo()
     {
         return [
+            '(help)' => 'This is a Query object, to get the results execute or iterate it.',
             'sql' => $this->sql(),
             'params' => $this->valueBinder()->bindings(),
             'defaultTypes' => $this->defaultTypes(),

+ 8 - 9
src/Datasource/EntityTrait.php

@@ -885,15 +885,14 @@ trait EntityTrait
      */
     public function __debugInfo()
     {
-        return [
-            'new' => $this->isNew(),
-            'accessible' => array_filter($this->_accessible),
-            'properties' => $this->_properties,
-            'dirty' => $this->_dirty,
-            'original' => $this->_original,
-            'virtual' => $this->_virtual,
-            'errors' => $this->_errors,
-            'repository' => $this->_registryAlias
+        return $this->_properties + [
+            '[new]' => $this->isNew(),
+            '[accessible]' => array_filter($this->_accessible),
+            '[dirty]' => $this->_dirty,
+            '[original]' => $this->_original,
+            '[virtual]' => $this->_virtual,
+            '[errors]' => $this->_errors,
+            '[repository]' => $this->_registryAlias
         ];
     }
 }

+ 2 - 0
tests/TestCase/Database/QueryTest.php

@@ -2949,6 +2949,7 @@ class QueryTest extends TestCase
             ->where(['id' => '1']);
 
         $expected = [
+            '(help)' => 'This is a Query object, to get the results execute or iterate it.',
             'sql' => $query->sql(),
             'params' => [
                 ':c0' => ['value' => '1', 'type' => 'integer', 'placeholder' => 'c0']
@@ -2962,6 +2963,7 @@ class QueryTest extends TestCase
 
         $query->execute();
         $expected = [
+            '(help)' => 'This is a Query object, to get the results execute or iterate it.',
             'sql' => $query->sql(),
             'params' => [
                 ':c0' => ['value' => '1', 'type' => 'integer', 'placeholder' => 'c0']

+ 10 - 8
tests/TestCase/ORM/EntityTest.php

@@ -1163,6 +1163,7 @@ class EntityTest extends TestCase
     public function testDebugInfo()
     {
         $entity = new Entity(['foo' => 'bar'], ['markClean' => true]);
+        $entity->somethingElse = 'value';
         $entity->accessible('name', true);
         $entity->virtualProperties(['baz']);
         $entity->dirty('foo', true);
@@ -1170,14 +1171,15 @@ class EntityTest extends TestCase
         $entity->source('foos');
         $result = $entity->__debugInfo();
         $expected = [
-            'new' => true,
-            'accessible' => ['*' => true, 'name' => true],
-            'properties' => ['foo' => 'bar'],
-            'dirty' => ['foo' => true],
-            'original' => [],
-            'virtual' => ['baz'],
-            'errors' => ['foo' => ['An error']],
-            'repository' => 'foos'
+            'foo' => 'bar',
+            'somethingElse' => 'value',
+            '[new]' => true,
+            '[accessible]' => ['*' => true, 'name' => true],
+            '[dirty]' => ['somethingElse' => true, 'foo' => true],
+            '[original]' => [],
+            '[virtual]' => ['baz'],
+            '[errors]' => ['foo' => ['An error']],
+            '[repository]' => 'foos'
         ];
         $this->assertSame($expected, $result);
     }

+ 1 - 0
tests/TestCase/ORM/QueryTest.php

@@ -2177,6 +2177,7 @@ class QueryTest extends TestCase
             });
 
         $expected = [
+            '(help)' => 'This is a Query object, to get the results execute or iterate it.',
             'sql' => $query->sql(),
             'params' => $query->valueBinder()->bindings(),
             'defaultTypes' => [