Mercurial > hg > isophonics-drupal-site
comparison vendor/symfony/var-dumper/Tests/Caster/ExceptionCasterTest.php @ 0:4c8ae668cc8c
Initial import (non-working)
author | Chris Cannam |
---|---|
date | Wed, 29 Nov 2017 16:09:58 +0000 |
parents | |
children | 7a779792577d |
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\ExceptionCaster; | |
16 use Symfony\Component\VarDumper\Caster\FrameStub; | |
17 use Symfony\Component\VarDumper\Cloner\VarCloner; | |
18 use Symfony\Component\VarDumper\Dumper\HtmlDumper; | |
19 use Symfony\Component\VarDumper\Test\VarDumperTestTrait; | |
20 | |
21 class ExceptionCasterTest extends TestCase | |
22 { | |
23 use VarDumperTestTrait; | |
24 | |
25 private function getTestException($msg, &$ref = null) | |
26 { | |
27 return new \Exception(''.$msg); | |
28 } | |
29 | |
30 protected function tearDown() | |
31 { | |
32 ExceptionCaster::$srcContext = 1; | |
33 ExceptionCaster::$traceArgs = true; | |
34 } | |
35 | |
36 public function testDefaultSettings() | |
37 { | |
38 $ref = array('foo'); | |
39 $e = $this->getTestException('foo', $ref); | |
40 | |
41 $expectedDump = <<<'EODUMP' | |
42 Exception { | |
43 #message: "foo" | |
44 #code: 0 | |
45 #file: "%sExceptionCasterTest.php" | |
46 #line: 27 | |
47 trace: { | |
48 %sExceptionCasterTest.php:27: { | |
49 : { | |
50 : return new \Exception(''.$msg); | |
51 : } | |
52 } | |
53 %sExceptionCasterTest.php:%d: { | |
54 : $ref = array('foo'); | |
55 : $e = $this->getTestException('foo', $ref); | |
56 : | |
57 arguments: { | |
58 $msg: "foo" | |
59 &$ref: array:1 [ …1] | |
60 } | |
61 } | |
62 %A | |
63 EODUMP; | |
64 | |
65 $this->assertDumpMatchesFormat($expectedDump, $e); | |
66 $this->assertSame(array('foo'), $ref); | |
67 } | |
68 | |
69 public function testSeek() | |
70 { | |
71 $e = $this->getTestException(2); | |
72 | |
73 $expectedDump = <<<'EODUMP' | |
74 { | |
75 %sExceptionCasterTest.php:27: { | |
76 : { | |
77 : return new \Exception(''.$msg); | |
78 : } | |
79 } | |
80 %sExceptionCasterTest.php:%d: { | |
81 : { | |
82 : $e = $this->getTestException(2); | |
83 : | |
84 arguments: { | |
85 $msg: 2 | |
86 } | |
87 } | |
88 %A | |
89 EODUMP; | |
90 | |
91 $this->assertStringMatchesFormat($expectedDump, $this->getDump($e, 'trace')); | |
92 } | |
93 | |
94 public function testNoArgs() | |
95 { | |
96 $e = $this->getTestException(1); | |
97 ExceptionCaster::$traceArgs = false; | |
98 | |
99 $expectedDump = <<<'EODUMP' | |
100 Exception { | |
101 #message: "1" | |
102 #code: 0 | |
103 #file: "%sExceptionCasterTest.php" | |
104 #line: 27 | |
105 trace: { | |
106 %sExceptionCasterTest.php:27: { | |
107 : { | |
108 : return new \Exception(''.$msg); | |
109 : } | |
110 } | |
111 %sExceptionCasterTest.php:%d: { | |
112 : { | |
113 : $e = $this->getTestException(1); | |
114 : ExceptionCaster::$traceArgs = false; | |
115 } | |
116 %A | |
117 EODUMP; | |
118 | |
119 $this->assertDumpMatchesFormat($expectedDump, $e); | |
120 } | |
121 | |
122 public function testNoSrcContext() | |
123 { | |
124 $e = $this->getTestException(1); | |
125 ExceptionCaster::$srcContext = -1; | |
126 | |
127 $expectedDump = <<<'EODUMP' | |
128 Exception { | |
129 #message: "1" | |
130 #code: 0 | |
131 #file: "%sExceptionCasterTest.php" | |
132 #line: 27 | |
133 trace: { | |
134 %sExceptionCasterTest.php: 27 | |
135 %sExceptionCasterTest.php: %d | |
136 %A | |
137 EODUMP; | |
138 | |
139 $this->assertDumpMatchesFormat($expectedDump, $e); | |
140 } | |
141 | |
142 public function testHtmlDump() | |
143 { | |
144 $e = $this->getTestException(1); | |
145 ExceptionCaster::$srcContext = -1; | |
146 | |
147 $cloner = new VarCloner(); | |
148 $cloner->setMaxItems(1); | |
149 $dumper = new HtmlDumper(); | |
150 $dumper->setDumpHeader('<foo></foo>'); | |
151 $dumper->setDumpBoundaries('<bar>', '</bar>'); | |
152 $dump = $dumper->dump($cloner->cloneVar($e)->withRefHandles(false), true); | |
153 | |
154 $expectedDump = <<<'EODUMP' | |
155 <foo></foo><bar><span class=sf-dump-note>Exception</span> {<samp> | |
156 #<span class=sf-dump-protected title="Protected property">message</span>: "<span class=sf-dump-str>1</span>" | |
157 #<span class=sf-dump-protected title="Protected property">code</span>: <span class=sf-dump-num>0</span> | |
158 #<span class=sf-dump-protected title="Protected property">file</span>: "<span class=sf-dump-str title="%sExceptionCasterTest.php | |
159 %d characters"><span class="sf-dump-ellipsis sf-dump-ellipsis-path">%s%eVarDumper</span><span class=sf-dump-ellipsis>%e</span>Tests%eCaster%eExceptionCasterTest.php</span>" | |
160 #<span class=sf-dump-protected title="Protected property">line</span>: <span class=sf-dump-num>27</span> | |
161 <span class=sf-dump-meta>trace</span>: {<samp> | |
162 <span class=sf-dump-meta title="%sExceptionCasterTest.php | |
163 Stack level %d."><span class="sf-dump-ellipsis sf-dump-ellipsis-path">%s%eVarDumper</span><span class=sf-dump-ellipsis>%e</span>Tests%eCaster%eExceptionCasterTest.php</span>: <span class=sf-dump-num>27</span> | |
164 …%d | |
165 </samp>} | |
166 </samp>} | |
167 </bar> | |
168 EODUMP; | |
169 | |
170 $this->assertStringMatchesFormat($expectedDump, $dump); | |
171 } | |
172 | |
173 /** | |
174 * @requires function Twig\Template::getSourceContext | |
175 */ | |
176 public function testFrameWithTwig() | |
177 { | |
178 require_once dirname(__DIR__).'/Fixtures/Twig.php'; | |
179 | |
180 $f = array( | |
181 new FrameStub(array( | |
182 'file' => dirname(__DIR__).'/Fixtures/Twig.php', | |
183 'line' => 20, | |
184 'class' => '__TwigTemplate_VarDumperFixture_u75a09', | |
185 )), | |
186 new FrameStub(array( | |
187 'file' => dirname(__DIR__).'/Fixtures/Twig.php', | |
188 'line' => 21, | |
189 'class' => '__TwigTemplate_VarDumperFixture_u75a09', | |
190 'object' => new \__TwigTemplate_VarDumperFixture_u75a09(null, __FILE__), | |
191 )), | |
192 ); | |
193 | |
194 $expectedDump = <<<'EODUMP' | |
195 array:2 [ | |
196 0 => { | |
197 class: "__TwigTemplate_VarDumperFixture_u75a09" | |
198 src: { | |
199 %sTwig.php:1: { | |
200 : | |
201 : foo bar | |
202 : twig source | |
203 } | |
204 } | |
205 } | |
206 1 => { | |
207 class: "__TwigTemplate_VarDumperFixture_u75a09" | |
208 object: __TwigTemplate_VarDumperFixture_u75a09 { | |
209 %A | |
210 } | |
211 src: { | |
212 %sExceptionCasterTest.php:2: { | |
213 : foo bar | |
214 : twig source | |
215 : | |
216 } | |
217 } | |
218 } | |
219 ] | |
220 | |
221 EODUMP; | |
222 | |
223 $this->assertDumpMatchesFormat($expectedDump, $f); | |
224 } | |
225 } |