Skip to content

Commit

Permalink
Adding __debugInfo to EntityTrait
Browse files Browse the repository at this point in the history
  • Loading branch information
lorenzo committed Mar 8, 2014
1 parent f7b0912 commit a081d33
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/Datasource/EntityTrait.php
Expand Up @@ -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
];
}

}
21 changes: 21 additions & 0 deletions tests/TestCase/ORM/EntityTest.php
Expand Up @@ -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']]
];
}

}

0 comments on commit a081d33

Please sign in to comment.