4 * This file is part of the Symfony package.
6 * (c) Fabien Potencier <fabien@symfony.com>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Symfony\Component\VarDumper\Test;
14 use Symfony\Component\VarDumper\Cloner\VarCloner;
15 use Symfony\Component\VarDumper\Dumper\CliDumper;
18 * @author Nicolas Grekas <p@tchwork.com>
20 trait VarDumperTestTrait
22 public function assertDumpEquals($dump, $data, $filter = 0, $message = '')
24 if (is_string($filter)) {
25 @trigger_error(sprintf('The $message argument of the "%s()" method at 3rd position is deprecated since Symfony 3.4 and will be moved at 4th position in 4.0.', __METHOD__), E_USER_DEPRECATED);
30 $this->assertSame(rtrim($dump), $this->getDump($data, null, $filter), $message);
33 public function assertDumpMatchesFormat($dump, $data, $filter = 0, $message = '')
35 if (is_string($filter)) {
36 @trigger_error(sprintf('The $message argument of the "%s()" method at 3rd position is deprecated since Symfony 3.4 and will be moved at 4th position in 4.0.', __METHOD__), E_USER_DEPRECATED);
41 $this->assertStringMatchesFormat(rtrim($dump), $this->getDump($data, null, $filter), $message);
44 protected function getDump($data, $key = null, $filter = 0)
46 $flags = getenv('DUMP_LIGHT_ARRAY') ? CliDumper::DUMP_LIGHT_ARRAY : 0;
47 $flags |= getenv('DUMP_STRING_LENGTH') ? CliDumper::DUMP_STRING_LENGTH : 0;
49 $cloner = new VarCloner();
50 $cloner->setMaxItems(-1);
51 $dumper = new CliDumper(null, null, $flags);
52 $dumper->setColors(false);
53 $data = $cloner->cloneVar($data, $filter)->withRefHandles(false);
54 if (null !== $key && null === $data = $data->seek($key)) {
58 return rtrim($dumper->dump($data, true));