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