From 881098f3a5fe7183de69d6a727d4709c31c1148b Mon Sep 17 00:00:00 2001 From: Jose Lorenzo Rodriguez Date: Sat, 8 Mar 2014 23:41:31 +0100 Subject: [PATCH] Added __debugInfo to Table --- src/ORM/Table.php | 19 +++++++++++++++++++ tests/TestCase/ORM/TableTest.php | 21 +++++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/src/ORM/Table.php b/src/ORM/Table.php index f72fe3b20a0..c177cd62228 100644 --- a/src/ORM/Table.php +++ b/src/ORM/Table.php @@ -1739,4 +1739,23 @@ public function implementedEvents() { return $events; } +/** + * Returns an array that can be used to describe the internal state of this + * object. + * + * @return array + */ + public function __debugInfo() { + $conn = $this->connection(); + return [ + 'table' => $this->table(), + 'alias' => $this->alias(), + 'entityClass' => $this->entityClass(), + 'associated' => $this->_associated->keys(), + 'behaviors' => $this->_behaviors->loaded(), + 'defaultConnection' => $this->defaultConnectionName(), + 'connectionName' => $conn ? $conn->configName() : null + ]; + } + } diff --git a/tests/TestCase/ORM/TableTest.php b/tests/TestCase/ORM/TableTest.php index 1b2f218d798..19cfc8227a2 100644 --- a/tests/TestCase/ORM/TableTest.php +++ b/tests/TestCase/ORM/TableTest.php @@ -3243,4 +3243,25 @@ public function testPatchEntities() { $table->patchEntities($entities, $data); } +/** + * Tests __debugInfo + * + * @return void + */ + public function testDebugInfo() { + $articles = TableRegistry::get('articles'); + $articles->addBehavior('Timestamp'); + $result = $articles->__debugInfo(); + $expected = [ + 'table' => 'articles', + 'alias' => 'articles', + 'entityClass' => 'TestApp\Model\Entity\Article', + 'associated' => ['authors', 'tags', 'articlestags'], + 'behaviors' => ['Timestamp'], + 'defaultConnection' => 'default', + 'connectionName' => 'test' + ]; + $this->assertEquals($expected, $result); + } + }