comparison vendor/symfony/var-dumper/Test/VarDumperTestTrait.php @ 0:c75dbcec494b

Initial commit from drush-created site
author Chris Cannam
date Thu, 05 Jul 2018 14:24:15 +0000
parents
children a9cd425dd02b
comparison
equal deleted inserted replaced
-1:000000000000 0:c75dbcec494b
1 <?php
2
3 /*
4 * This file is part of the Symfony package.
5 *
6 * (c) Fabien Potencier <fabien@symfony.com>
7 *
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
10 */
11
12 namespace Symfony\Component\VarDumper\Test;
13
14 use Symfony\Component\VarDumper\Cloner\VarCloner;
15 use Symfony\Component\VarDumper\Dumper\CliDumper;
16
17 /**
18 * @author Nicolas Grekas <p@tchwork.com>
19 */
20 trait VarDumperTestTrait
21 {
22 public function assertDumpEquals($dump, $data, $filter = 0, $message = '')
23 {
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);
26 $message = $filter;
27 $filter = 0;
28 }
29
30 $this->assertSame(rtrim($dump), $this->getDump($data, null, $filter), $message);
31 }
32
33 public function assertDumpMatchesFormat($dump, $data, $filter = 0, $message = '')
34 {
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);
37 $message = $filter;
38 $filter = 0;
39 }
40
41 $this->assertStringMatchesFormat(rtrim($dump), $this->getDump($data, null, $filter), $message);
42 }
43
44 protected function getDump($data, $key = null, $filter = 0)
45 {
46 $flags = getenv('DUMP_LIGHT_ARRAY') ? CliDumper::DUMP_LIGHT_ARRAY : 0;
47 $flags |= getenv('DUMP_STRING_LENGTH') ? CliDumper::DUMP_STRING_LENGTH : 0;
48
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)) {
55 return;
56 }
57
58 return rtrim($dumper->dump($data, true));
59 }
60 }