PluginProbe ʕ •ᴥ•ʔ
Kubio AI Page Builder / trunk
Kubio AI Page Builder vtrunk
2.9.0 2.8.6 2.8.5 2.8.4 2.8.3 2.8.2 2.8.1 trunk 1.0.0 1.0.1 1.1.0 1.2.0 1.2.1 1.2.2 1.2.3 1.3.0 1.3.1 1.3.2 1.4.0 1.4.1 1.4.2 1.4.3 1.5.0 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 1.7.0 1.7.1 1.7.2 1.7.3 1.8.0 1.8.1 1.8.2 1.9.0 2.0.0 2.1.1 2.1.2 2.1.3 2.2.0 2.2.3 2.2.4 2.2.5 2.3.0 2.3.1 2.3.3 2.3.4 2.4.0 2.4.1 2.4.2 2.4.3 2.4.5 2.5.0 2.5.1 2.5.2 2.5.3 2.6.0 2.6.1 2.6.2 2.6.3 2.6.5 2.6.6 2.6.7 2.7.0 2.7.1 2.7.2 2.7.3 2.8.0
kubio / vendor / symfony / var-dumper / Test / VarDumperTestTrait.php
kubio / vendor / symfony / var-dumper / Test Last commit date
VarDumperTestTrait.php 1 year ago
VarDumperTestTrait.php
85 lines
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 /**
23 * @internal
24 */
25 private $varDumperConfig = [
26 'casters' => [],
27 'flags' => null,
28 ];
29
30 protected function setUpVarDumper(array $casters, ?int $flags = null): void
31 {
32 $this->varDumperConfig['casters'] = $casters;
33 $this->varDumperConfig['flags'] = $flags;
34 }
35
36 /**
37 * @after
38 */
39 protected function tearDownVarDumper(): void
40 {
41 $this->varDumperConfig['casters'] = [];
42 $this->varDumperConfig['flags'] = null;
43 }
44
45 public function assertDumpEquals($expected, $data, int $filter = 0, string $message = '')
46 {
47 $this->assertSame($this->prepareExpectation($expected, $filter), $this->getDump($data, null, $filter), $message);
48 }
49
50 public function assertDumpMatchesFormat($expected, $data, int $filter = 0, string $message = '')
51 {
52 $this->assertStringMatchesFormat($this->prepareExpectation($expected, $filter), $this->getDump($data, null, $filter), $message);
53 }
54
55 protected function getDump($data, $key = null, int $filter = 0): ?string
56 {
57 if (null === $flags = $this->varDumperConfig['flags']) {
58 $flags = getenv('DUMP_LIGHT_ARRAY') ? CliDumper::DUMP_LIGHT_ARRAY : 0;
59 $flags |= getenv('DUMP_STRING_LENGTH') ? CliDumper::DUMP_STRING_LENGTH : 0;
60 $flags |= getenv('DUMP_COMMA_SEPARATOR') ? CliDumper::DUMP_COMMA_SEPARATOR : 0;
61 }
62
63 $cloner = new VarCloner();
64 $cloner->addCasters($this->varDumperConfig['casters']);
65 $cloner->setMaxItems(-1);
66 $dumper = new CliDumper(null, null, $flags);
67 $dumper->setColors(false);
68 $data = $cloner->cloneVar($data, $filter)->withRefHandles(false);
69 if (null !== $key && null === $data = $data->seek($key)) {
70 return null;
71 }
72
73 return rtrim($dumper->dump($data, true));
74 }
75
76 private function prepareExpectation($expected, int $filter): string
77 {
78 if (!\is_string($expected)) {
79 $expected = $this->getDump($expected, null, $filter);
80 }
81
82 return rtrim($expected);
83 }
84 }
85