Browse files

Added __debugInfo to Table

  • Loading branch information...
1 parent 70d6956 commit 881098f3a5fe7183de69d6a727d4709c31c1148b @lorenzo lorenzo committed Mar 8, 2014
Showing with 40 additions and 0 deletions.
  1. +19 −0 src/ORM/Table.php
  2. +21 −0 tests/TestCase/ORM/TableTest.php
View
19 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
+ ];
+ }
+
}
View
21 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);
+ }
+
}

0 comments on commit 881098f

Please sign in to comment.