Mercurial > hg > isophonics-drupal-site
comparison vendor/symfony/var-dumper/Tests/Caster/CasterTest.php @ 0:4c8ae668cc8c
Initial import (non-working)
author | Chris Cannam |
---|---|
date | Wed, 29 Nov 2017 16:09:58 +0000 |
parents | |
children | 129ea1e6d783 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:4c8ae668cc8c |
---|---|
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\Tests\Caster; | |
13 | |
14 use PHPUnit\Framework\TestCase; | |
15 use Symfony\Component\VarDumper\Caster\Caster; | |
16 use Symfony\Component\VarDumper\Test\VarDumperTestTrait; | |
17 | |
18 /** | |
19 * @author Nicolas Grekas <p@tchwork.com> | |
20 */ | |
21 class CasterTest extends TestCase | |
22 { | |
23 use VarDumperTestTrait; | |
24 | |
25 private $referenceArray = array( | |
26 'null' => null, | |
27 'empty' => false, | |
28 'public' => 'pub', | |
29 "\0~\0virtual" => 'virt', | |
30 "\0+\0dynamic" => 'dyn', | |
31 "\0*\0protected" => 'prot', | |
32 "\0Foo\0private" => 'priv', | |
33 ); | |
34 | |
35 /** | |
36 * @dataProvider provideFilter | |
37 */ | |
38 public function testFilter($filter, $expectedDiff, $listedProperties = null) | |
39 { | |
40 if (null === $listedProperties) { | |
41 $filteredArray = Caster::filter($this->referenceArray, $filter); | |
42 } else { | |
43 $filteredArray = Caster::filter($this->referenceArray, $filter, $listedProperties); | |
44 } | |
45 | |
46 $this->assertSame($expectedDiff, array_diff_assoc($this->referenceArray, $filteredArray)); | |
47 } | |
48 | |
49 public function provideFilter() | |
50 { | |
51 return array( | |
52 array( | |
53 0, | |
54 array(), | |
55 ), | |
56 array( | |
57 Caster::EXCLUDE_PUBLIC, | |
58 array( | |
59 'null' => null, | |
60 'empty' => false, | |
61 'public' => 'pub', | |
62 ), | |
63 ), | |
64 array( | |
65 Caster::EXCLUDE_NULL, | |
66 array( | |
67 'null' => null, | |
68 ), | |
69 ), | |
70 array( | |
71 Caster::EXCLUDE_EMPTY, | |
72 array( | |
73 'null' => null, | |
74 'empty' => false, | |
75 ), | |
76 ), | |
77 array( | |
78 Caster::EXCLUDE_VIRTUAL, | |
79 array( | |
80 "\0~\0virtual" => 'virt', | |
81 ), | |
82 ), | |
83 array( | |
84 Caster::EXCLUDE_DYNAMIC, | |
85 array( | |
86 "\0+\0dynamic" => 'dyn', | |
87 ), | |
88 ), | |
89 array( | |
90 Caster::EXCLUDE_PROTECTED, | |
91 array( | |
92 "\0*\0protected" => 'prot', | |
93 ), | |
94 ), | |
95 array( | |
96 Caster::EXCLUDE_PRIVATE, | |
97 array( | |
98 "\0Foo\0private" => 'priv', | |
99 ), | |
100 ), | |
101 array( | |
102 Caster::EXCLUDE_VERBOSE, | |
103 array( | |
104 'public' => 'pub', | |
105 "\0*\0protected" => 'prot', | |
106 ), | |
107 array('public', "\0*\0protected"), | |
108 ), | |
109 array( | |
110 Caster::EXCLUDE_NOT_IMPORTANT, | |
111 array( | |
112 'null' => null, | |
113 'empty' => false, | |
114 "\0~\0virtual" => 'virt', | |
115 "\0+\0dynamic" => 'dyn', | |
116 "\0Foo\0private" => 'priv', | |
117 ), | |
118 array('public', "\0*\0protected"), | |
119 ), | |
120 array( | |
121 Caster::EXCLUDE_VIRTUAL | Caster::EXCLUDE_DYNAMIC, | |
122 array( | |
123 "\0~\0virtual" => 'virt', | |
124 "\0+\0dynamic" => 'dyn', | |
125 ), | |
126 ), | |
127 array( | |
128 Caster::EXCLUDE_NOT_IMPORTANT | Caster::EXCLUDE_VERBOSE, | |
129 $this->referenceArray, | |
130 array('public', "\0*\0protected"), | |
131 ), | |
132 array( | |
133 Caster::EXCLUDE_NOT_IMPORTANT | Caster::EXCLUDE_EMPTY, | |
134 array( | |
135 'null' => null, | |
136 'empty' => false, | |
137 "\0~\0virtual" => 'virt', | |
138 "\0+\0dynamic" => 'dyn', | |
139 "\0*\0protected" => 'prot', | |
140 "\0Foo\0private" => 'priv', | |
141 ), | |
142 array('public', 'empty'), | |
143 ), | |
144 array( | |
145 Caster::EXCLUDE_VERBOSE | Caster::EXCLUDE_EMPTY | Caster::EXCLUDE_STRICT, | |
146 array( | |
147 'empty' => false, | |
148 ), | |
149 array('public', 'empty'), | |
150 ), | |
151 ); | |
152 } | |
153 | |
154 /** | |
155 * @requires PHP 7.0 | |
156 */ | |
157 public function testAnonymousClass() | |
158 { | |
159 $c = eval('return new class extends stdClass { private $foo = "foo"; };'); | |
160 | |
161 $this->assertDumpMatchesFormat( | |
162 <<<'EOTXT' | |
163 stdClass@anonymous { | |
164 -foo: "foo" | |
165 } | |
166 EOTXT | |
167 , $c | |
168 ); | |
169 | |
170 $c = eval('return new class { private $foo = "foo"; };'); | |
171 | |
172 $this->assertDumpMatchesFormat( | |
173 <<<'EOTXT' | |
174 @anonymous { | |
175 -foo: "foo" | |
176 } | |
177 EOTXT | |
178 , $c | |
179 ); | |
180 } | |
181 } |