DoctrineDataCollector: taught sanitizeParam to support classes with __toString implemented.
This commit is contained in:
parent
0413e1832f
commit
f2970f22ac
@ -159,7 +159,11 @@ class DoctrineDataCollector extends DataCollector
|
||||
private function sanitizeParam($var)
|
||||
{
|
||||
if (is_object($var)) {
|
||||
return array(sprintf('Object(%s)', get_class($var)), false);
|
||||
$className = get_class($var);
|
||||
|
||||
return method_exists($var, '__toString') ?
|
||||
array(sprintf('Object(%s): "%s"', $className, $var->__toString()), false) :
|
||||
array(sprintf('Object(%s)', $className), false);
|
||||
}
|
||||
|
||||
if (is_array($var)) {
|
||||
|
@ -127,7 +127,13 @@ class DoctrineDataCollectorTest extends TestCase
|
||||
array(null, array(), null, true),
|
||||
array(new \DateTime('2011-09-11'), array('date'), '2011-09-11', true),
|
||||
array(fopen(__FILE__, 'r'), array(), 'Resource(stream)', false),
|
||||
array(new \SplFileInfo(__FILE__), array(), 'Object(SplFileInfo)', false),
|
||||
array(new \stdClass(), array(), 'Object(stdClass)', false),
|
||||
array(
|
||||
new StringRepresentableClass('presentation test'),
|
||||
array(),
|
||||
'Object(Symfony\Bridge\Doctrine\Tests\DataCollector\StringRepresentableClass): "presentation test"',
|
||||
false,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace Symfony\Bridge\Doctrine\Tests\DataCollector;
|
||||
|
||||
/**
|
||||
* A class for testing __toString method behaviour. It's __toString returns a value, that was passed into constructor.
|
||||
*/
|
||||
class StringRepresentableClass
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $representation;
|
||||
|
||||
/**
|
||||
* CustomStringableClass constructor.
|
||||
*
|
||||
* @param string $representation
|
||||
*/
|
||||
public function __construct($representation)
|
||||
{
|
||||
$this->representation = $representation;
|
||||
}
|
||||
|
||||
public function __toString()
|
||||
{
|
||||
return $this->representation;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user