0fffd55122218106e9471ce86ec1a20e458dcd32
[yaffs-website] / vendor / symfony / var-dumper / Test / VarDumperTestTrait.php
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 }