Skip to content
Permalink
Browse files

Adding a __toString method to Entity for easier debugging

  • Loading branch information...
lorenzo committed Feb 16, 2014
1 parent 03e6627 commit 70c7510bb548a59906433f1a9441968151fca8b0
Showing with 19 additions and 0 deletions.
  1. +9 −0 src/ORM/Entity.php
  2. +10 −0 tests/TestCase/ORM/EntityTest.php
@@ -703,4 +703,13 @@ public function accessible($property, $set = null) {
return $this;
}
/**
* Returns a string representation of this object in a humna readable format.
*
* @return string
*/
public function __toString() {
return json_encode($this, JSON_PRETTY_PRINT);
}
}
@@ -986,4 +986,14 @@ public function testSetWithAccessibleSingleProperty() {
$this->assertEquals('Yes', $entity->body, 'Single set should bypass guards.');
}
/**
* Tests the entity's __toString method
*
* @return void
*/
public function testToString() {
$entity = new Entity(['foo' => 1, 'bar' => 2]);
$this->assertEquals(json_encode($entity, JSON_PRETTY_PRINT), (string)$entity);
}
}

0 comments on commit 70c7510

Please sign in to comment.
You can’t perform that action at this time.