Skip to content

Commit

Permalink
DoctrineDataCollector: taught sanitizeParam to support classes with _…
Browse files Browse the repository at this point in the history
…_toString implemented.
  • Loading branch information
FractalizeR authored and fabpot committed Mar 2, 2017
1 parent 0413e18 commit f2970f2
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 2 deletions.
Expand Up @@ -159,7 +159,11 @@ private function sanitizeQuery($connectionName, $query)
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)) {
Expand Down
Expand Up @@ -127,7 +127,13 @@ public function paramProvider()
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,
),
);
}

Expand Down
@@ -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;
}
}

0 comments on commit f2970f2

Please sign in to comment.