Skip to content

Commit

Permalink
Improving Entity::__debugInfo() to better hint what is accessible.
Browse files Browse the repository at this point in the history
  • Loading branch information
lorenzo committed May 15, 2015
1 parent a1d97df commit 8977882
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 17 deletions.
17 changes: 8 additions & 9 deletions src/Datasource/EntityTrait.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -885,15 +885,14 @@ public function __toString()
*/ */
public function __debugInfo() public function __debugInfo()
{ {
return [ return $this->_properties + [
'new' => $this->isNew(), '[new]' => $this->isNew(),
'accessible' => array_filter($this->_accessible), '[accessible]' => array_filter($this->_accessible),
'properties' => $this->_properties, '[dirty]' => $this->_dirty,
'dirty' => $this->_dirty, '[original]' => $this->_original,
'original' => $this->_original, '[virtual]' => $this->_virtual,
'virtual' => $this->_virtual, '[errors]' => $this->_errors,
'errors' => $this->_errors, '[repository]' => $this->_registryAlias
'repository' => $this->_registryAlias
]; ];
} }
} }
18 changes: 10 additions & 8 deletions tests/TestCase/ORM/EntityTest.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -1163,21 +1163,23 @@ public function testToString()
public function testDebugInfo() public function testDebugInfo()
{ {
$entity = new Entity(['foo' => 'bar'], ['markClean' => true]); $entity = new Entity(['foo' => 'bar'], ['markClean' => true]);
$entity->somethingElse = 'value';
$entity->accessible('name', true); $entity->accessible('name', true);
$entity->virtualProperties(['baz']); $entity->virtualProperties(['baz']);
$entity->dirty('foo', true); $entity->dirty('foo', true);
$entity->errors('foo', ['An error']); $entity->errors('foo', ['An error']);
$entity->source('foos'); $entity->source('foos');
$result = $entity->__debugInfo(); $result = $entity->__debugInfo();
$expected = [ $expected = [
'new' => true, 'foo' => 'bar',
'accessible' => ['*' => true, 'name' => true], 'somethingElse' => 'value',
'properties' => ['foo' => 'bar'], '[new]' => true,
'dirty' => ['foo' => true], '[accessible]' => ['*' => true, 'name' => true],
'original' => [], '[dirty]' => ['somethingElse' => true, 'foo' => true],
'virtual' => ['baz'], '[original]' => [],
'errors' => ['foo' => ['An error']], '[virtual]' => ['baz'],
'repository' => 'foos' '[errors]' => ['foo' => ['An error']],
'[repository]' => 'foos'
]; ];
$this->assertSame($expected, $result); $this->assertSame($expected, $result);
} }
Expand Down

0 comments on commit 8977882

Please sign in to comment.