Mercurial > hg > isophonics-drupal-site
comparison vendor/symfony/var-dumper/Tests/Caster/StubCasterTest.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\ArgsStub; | |
16 use Symfony\Component\VarDumper\Caster\ClassStub; | |
17 use Symfony\Component\VarDumper\Caster\LinkStub; | |
18 use Symfony\Component\VarDumper\Cloner\VarCloner; | |
19 use Symfony\Component\VarDumper\Dumper\HtmlDumper; | |
20 use Symfony\Component\VarDumper\Test\VarDumperTestTrait; | |
21 use Symfony\Component\VarDumper\Tests\Fixtures\FooInterface; | |
22 | |
23 class StubCasterTest extends TestCase | |
24 { | |
25 use VarDumperTestTrait; | |
26 | |
27 public function testArgsStubWithDefaults($foo = 234, $bar = 456) | |
28 { | |
29 $args = array(new ArgsStub(array(123), __FUNCTION__, __CLASS__)); | |
30 | |
31 $expectedDump = <<<'EODUMP' | |
32 array:1 [ | |
33 0 => { | |
34 $foo: 123 | |
35 } | |
36 ] | |
37 EODUMP; | |
38 | |
39 $this->assertDumpMatchesFormat($expectedDump, $args); | |
40 } | |
41 | |
42 public function testArgsStubWithExtraArgs($foo = 234) | |
43 { | |
44 $args = array(new ArgsStub(array(123, 456), __FUNCTION__, __CLASS__)); | |
45 | |
46 $expectedDump = <<<'EODUMP' | |
47 array:1 [ | |
48 0 => { | |
49 $foo: 123 | |
50 ...: { | |
51 456 | |
52 } | |
53 } | |
54 ] | |
55 EODUMP; | |
56 | |
57 $this->assertDumpMatchesFormat($expectedDump, $args); | |
58 } | |
59 | |
60 public function testArgsStubNoParamWithExtraArgs() | |
61 { | |
62 $args = array(new ArgsStub(array(123), __FUNCTION__, __CLASS__)); | |
63 | |
64 $expectedDump = <<<'EODUMP' | |
65 array:1 [ | |
66 0 => { | |
67 123 | |
68 } | |
69 ] | |
70 EODUMP; | |
71 | |
72 $this->assertDumpMatchesFormat($expectedDump, $args); | |
73 } | |
74 | |
75 public function testArgsStubWithClosure() | |
76 { | |
77 $args = array(new ArgsStub(array(123), '{closure}', null)); | |
78 | |
79 $expectedDump = <<<'EODUMP' | |
80 array:1 [ | |
81 0 => { | |
82 123 | |
83 } | |
84 ] | |
85 EODUMP; | |
86 | |
87 $this->assertDumpMatchesFormat($expectedDump, $args); | |
88 } | |
89 | |
90 public function testLinkStub() | |
91 { | |
92 $var = array(new LinkStub(__CLASS__, 0, __FILE__)); | |
93 | |
94 $cloner = new VarCloner(); | |
95 $dumper = new HtmlDumper(); | |
96 $dumper->setDumpHeader('<foo></foo>'); | |
97 $dumper->setDumpBoundaries('<bar>', '</bar>'); | |
98 $dumper->setDisplayOptions(array('fileLinkFormat' => '%f:%l')); | |
99 $dump = $dumper->dump($cloner->cloneVar($var), true); | |
100 | |
101 $expectedDump = <<<'EODUMP' | |
102 <foo></foo><bar><span class=sf-dump-note>array:1</span> [<samp> | |
103 <span class=sf-dump-index>0</span> => "<a href="%sStubCasterTest.php:0" target="_blank" rel="noopener noreferrer"><span class=sf-dump-str title="55 characters">Symfony\Component\VarDumper\Tests\Caster\StubCasterTest</span></a>" | |
104 </samp>] | |
105 </bar> | |
106 EODUMP; | |
107 | |
108 $this->assertStringMatchesFormat($expectedDump, $dump); | |
109 } | |
110 | |
111 public function testClassStub() | |
112 { | |
113 $var = array(new ClassStub('hello', array(FooInterface::class, 'foo'))); | |
114 | |
115 $cloner = new VarCloner(); | |
116 $dumper = new HtmlDumper(); | |
117 $dumper->setDumpHeader('<foo></foo>'); | |
118 $dumper->setDumpBoundaries('<bar>', '</bar>'); | |
119 $dump = $dumper->dump($cloner->cloneVar($var), true, array('fileLinkFormat' => '%f:%l')); | |
120 | |
121 $expectedDump = <<<'EODUMP' | |
122 <foo></foo><bar><span class=sf-dump-note>array:1</span> [<samp> | |
123 <span class=sf-dump-index>0</span> => "<a href="%sFooInterface.php:10" target="_blank" rel="noopener noreferrer"><span class=sf-dump-str title="5 characters">hello</span></a>" | |
124 </samp>] | |
125 </bar> | |
126 EODUMP; | |
127 | |
128 $this->assertStringMatchesFormat($expectedDump, $dump); | |
129 } | |
130 | |
131 public function testClassStubWithNotExistingClass() | |
132 { | |
133 $var = array(new ClassStub(NotExisting::class)); | |
134 | |
135 $cloner = new VarCloner(); | |
136 $dumper = new HtmlDumper(); | |
137 $dumper->setDumpHeader('<foo></foo>'); | |
138 $dumper->setDumpBoundaries('<bar>', '</bar>'); | |
139 $dump = $dumper->dump($cloner->cloneVar($var), true); | |
140 | |
141 $expectedDump = <<<'EODUMP' | |
142 <foo></foo><bar><span class=sf-dump-note>array:1</span> [<samp> | |
143 <span class=sf-dump-index>0</span> => "<span class=sf-dump-str title="Symfony\Component\VarDumper\Tests\Caster\NotExisting | |
144 52 characters"><span class="sf-dump-ellipsis sf-dump-ellipsis-class">Symfony\Component\VarDumper\Tests\Caster</span><span class=sf-dump-ellipsis>\</span>NotExisting</span>" | |
145 </samp>] | |
146 </bar> | |
147 EODUMP; | |
148 | |
149 $this->assertStringMatchesFormat($expectedDump, $dump); | |
150 } | |
151 | |
152 public function testClassStubWithNotExistingMethod() | |
153 { | |
154 $var = array(new ClassStub('hello', array(FooInterface::class, 'missing'))); | |
155 | |
156 $cloner = new VarCloner(); | |
157 $dumper = new HtmlDumper(); | |
158 $dumper->setDumpHeader('<foo></foo>'); | |
159 $dumper->setDumpBoundaries('<bar>', '</bar>'); | |
160 $dump = $dumper->dump($cloner->cloneVar($var), true, array('fileLinkFormat' => '%f:%l')); | |
161 | |
162 $expectedDump = <<<'EODUMP' | |
163 <foo></foo><bar><span class=sf-dump-note>array:1</span> [<samp> | |
164 <span class=sf-dump-index>0</span> => "<a href="%sFooInterface.php:5" target="_blank" rel="noopener noreferrer"><span class=sf-dump-str title="5 characters">hello</span></a>" | |
165 </samp>] | |
166 </bar> | |
167 EODUMP; | |
168 | |
169 $this->assertStringMatchesFormat($expectedDump, $dump); | |
170 } | |
171 } |