From a081d33f32d378db91d7e8795258e358a4eae0c1 Mon Sep 17 00:00:00 2001 From: Jose Lorenzo Rodriguez Date: Sat, 8 Mar 2014 18:41:09 +0100 Subject: [PATCH] Adding __debugInfo to EntityTrait --- src/Datasource/EntityTrait.php | 17 +++++++++++++++++ tests/TestCase/ORM/EntityTest.php | 21 +++++++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/src/Datasource/EntityTrait.php b/src/Datasource/EntityTrait.php index c8fcff034e8..1358d8a52b6 100644 --- a/src/Datasource/EntityTrait.php +++ b/src/Datasource/EntityTrait.php @@ -671,4 +671,21 @@ public function __toString() { return json_encode($this, JSON_PRETTY_PRINT); } +/** + * Returns an array that can be used to describe the internal estate of this + * object. + * + * @return array + */ + public function __debugInfo() { + return [ + 'new' => $this->isNew(), + 'accessible' => array_filter($this->_accessible), + 'properties' => $this->_properties, + 'dirty' => $this->_dirty, + 'virtual' => $this->_virtual, + 'errors' => $this->_errors + ]; + } + } diff --git a/tests/TestCase/ORM/EntityTest.php b/tests/TestCase/ORM/EntityTest.php index 6aedb25d4b8..91fa8cdb34a 100644 --- a/tests/TestCase/ORM/EntityTest.php +++ b/tests/TestCase/ORM/EntityTest.php @@ -996,4 +996,25 @@ public function testToString() { $this->assertEquals(json_encode($entity, JSON_PRETTY_PRINT), (string)$entity); } +/** + * Tests __debugInfo + * + * @return void + */ + public function testDebugInfo() { + $entity = new Entity(['foo' => 'bar'], ['markClean' => true]); + $entity->accessible('name', true); + $entity->virtualProperties(['baz']); + $entity->errors('foo', ['An error']); + $result = $entity->__debugInfo(); + $expected = [ + 'new' => true, + 'accessible' => ['name'], + 'properties' => ['foo' => 'bar'], + 'dirty' => ['foo' => true], + 'virtual' => ['baz'], + 'errors' => ['foo' => ['An error']] + ]; + } + }