HtmlDescriptorTest.php
6.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\VarDumper\Tests\Command\Descriptor;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Console\Output\BufferedOutput;
use Symfony\Component\VarDumper\Cloner\Data;
use Symfony\Component\VarDumper\Command\Descriptor\HtmlDescriptor;
use Symfony\Component\VarDumper\Dumper\HtmlDumper;
class HtmlDescriptorTest extends TestCase
{
private static $timezone;
public static function setUpBeforeClass()
{
self::$timezone = date_default_timezone_get();
date_default_timezone_set('UTC');
}
public static function tearDownAfterClass()
{
date_default_timezone_set(self::$timezone);
}
public function testItOutputsStylesAndScriptsOnFirstDescribeCall()
{
$output = new BufferedOutput();
$dumper = $this->createMock(HtmlDumper::class);
$dumper->method('dump')->willReturn('[DUMPED]');
$descriptor = new HtmlDescriptor($dumper);
$descriptor->describe($output, new Data([[123]]), ['timestamp' => 1544804268.3668], 1);
$this->assertStringMatchesFormat('<style>%A</style><script>%A</script>%A', $output->fetch(), 'styles & scripts are output');
$descriptor->describe($output, new Data([[123]]), ['timestamp' => 1544804268.3668], 1);
$this->assertStringNotMatchesFormat('<style>%A</style><script>%A</script>%A', $output->fetch(), 'styles & scripts are output only once');
}
/**
* @dataProvider provideContext
*/
public function testDescribe(array $context, string $expectedOutput)
{
$output = new BufferedOutput();
$dumper = $this->createMock(HtmlDumper::class);
$dumper->method('dump')->willReturn('[DUMPED]');
$descriptor = new HtmlDescriptor($dumper);
$descriptor->describe($output, new Data([[123]]), $context + ['timestamp' => 1544804268.3668], 1);
$this->assertStringMatchesFormat(trim($expectedOutput), trim(preg_replace('@<style>.*</style><script>.*</script>@s', '', $output->fetch())));
}
public function provideContext()
{
yield 'source' => [
[
'source' => [
'name' => 'CliDescriptorTest.php',
'line' => 30,
'file' => '/Users/ogi/symfony/src/Symfony/Component/VarDumper/Tests/Command/Descriptor/CliDescriptorTest.php',
],
],
<<<TXT
<article data-dedup-id="%s">
<header>
<div class="row">
<h2 class="col">-</h2>
<time class="col text-small" title="2018-12-14T16:17:48+00:00" datetime="2018-12-14T16:17:48+00:00">
Fri, 14 Dec 2018 16:17:48 +0000
</time>
</div>
</header>
<section class="body">
<p class="text-small">
CliDescriptorTest.php on line 30
</p>
[DUMPED]
</section>
</article>
TXT
];
yield 'source full' => [
[
'source' => [
'name' => 'CliDescriptorTest.php',
'project_dir' => 'src/Symfony/',
'line' => 30,
'file_relative' => 'src/Symfony/Component/VarDumper/Tests/Command/Descriptor/CliDescriptorTest.php',
'file' => '/Users/ogi/symfony/src/Symfony/Component/VarDumper/Tests/Command/Descriptor/CliDescriptorTest.php',
'file_link' => 'phpstorm://open?file=/Users/ogi/symfony/src/Symfony/Component/VarDumper/Tests/Command/Descriptor/CliDescriptorTest.php&line=30',
],
],
<<<TXT
<article data-dedup-id="%s">
<header>
<div class="row">
<h2 class="col">-</h2>
<time class="col text-small" title="2018-12-14T16:17:48+00:00" datetime="2018-12-14T16:17:48+00:00">
Fri, 14 Dec 2018 16:17:48 +0000
</time>
</div>
<div class="row">
<ul class="tags">
<li><span class="badge">project dir</span>src/Symfony/</li>
</ul>
</div>
</header>
<section class="body">
<p class="text-small">
<a href="phpstorm://open?file=/Users/ogi/symfony/src/Symfony/Component/VarDumper/Tests/Command/Descriptor/CliDescriptorTest.php&line=30">CliDescriptorTest.php on line 30</a>
</p>
[DUMPED]
</section>
</article>
TXT
];
yield 'cli' => [
[
'cli' => [
'identifier' => 'd8bece1c',
'command_line' => 'bin/phpunit',
],
],
<<<TXT
<article data-dedup-id="d8bece1c">
<header>
<div class="row">
<h2 class="col"><code>$ </code>bin/phpunit</h2>
<time class="col text-small" title="2018-12-14T16:17:48+00:00" datetime="2018-12-14T16:17:48+00:00">
Fri, 14 Dec 2018 16:17:48 +0000
</time>
</div>
</header>
<section class="body">
<p class="text-small">
</p>
[DUMPED]
</section>
</article>
TXT
];
yield 'request' => [
[
'request' => [
'identifier' => 'd8bece1c',
'controller' => new Data([['FooController.php']]),
'method' => 'GET',
'uri' => 'http://localhost/foo',
],
],
<<<TXT
<article data-dedup-id="d8bece1c">
<header>
<div class="row">
<h2 class="col"><code>GET</code> <a href="http://localhost/foo">http://localhost/foo</a></h2>
<time class="col text-small" title="2018-12-14T16:17:48+00:00" datetime="2018-12-14T16:17:48+00:00">
Fri, 14 Dec 2018 16:17:48 +0000
</time>
</div>
<div class="row">
<ul class="tags">
<li><span class="badge">controller</span><span class='dumped-tag'>[DUMPED]</span></li>
</ul>
</div>
</header>
<section class="body">
<p class="text-small">
</p>
[DUMPED]
</section>
</article>
TXT
];
}
}