Skip to content

Commit

Permalink
Merge pull request #2837 from cakephp/3.0-entity-pretty-print
Browse files Browse the repository at this point in the history
3.0 entity pretty print
  • Loading branch information
markstory committed Feb 16, 2014
2 parents 03e6627 + 70c7510 commit bc5e137
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/ORM/Entity.php
Expand Up @@ -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);
}

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

Please sign in to comment.