Skip to content

Commit 9e087c5

Browse files
authored
[CLEANUP] Use the explicit OutputFormat setters in the tests (#1106)
The `set()` method will be removed soon. Also unify the tests a bit. Part of #1103
1 parent 07b4db0 commit 9e087c5

File tree

2 files changed

+46
-18
lines changed

2 files changed

+46
-18
lines changed

config/phpstan-baseline.neon

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -102,12 +102,6 @@ parameters:
102102
count: 2
103103
path: ../src/CSSList/KeyFrame.php
104104

105-
-
106-
message: '#^Parameters should have "string\|string" types as the only types passed to this method$#'
107-
identifier: typePerfect.narrowPublicClassMethodParamType
108-
count: 1
109-
path: ../src/OutputFormat.php
110-
111105
-
112106
message: '#^Returning false in non return bool class method\. Use null with type\|null instead or add bool return type$#'
113107
identifier: typePerfect.nullOverFalse

tests/OutputFormatTest.php

Lines changed: 46 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,11 @@ public function spaceAfterRuleName(): void
182182
*/
183183
public function spaceRules(): void
184184
{
185+
$outputFormat = OutputFormat::create()
186+
->setSpaceBeforeRules("\n")
187+
->setSpaceBetweenRules("\n")
188+
->setSpaceAfterRules("\n");
189+
185190
self::assertSame('.main, .test {
186191
font: italic normal bold 16px/1.2 "Helvetica",Verdana,sans-serif;
187192
background: white;
@@ -190,27 +195,40 @@ public function spaceRules(): void
190195
background-size: 100% 100%;
191196
font-size: 1.3em;
192197
background-color: #fff;
193-
}}', $this->document->render(OutputFormat::create()->set('Space*Rules', "\n")));
198+
}}', $this->document->render($outputFormat));
194199
}
195200

196201
/**
197202
* @test
198203
*/
199204
public function spaceBlocks(): void
200205
{
206+
$outputFormat = OutputFormat::create()
207+
->setSpaceBeforeBlocks("\n")
208+
->setSpaceBetweenBlocks("\n")
209+
->setSpaceAfterBlocks("\n");
210+
201211
self::assertSame('
202212
.main, .test {font: italic normal bold 16px/1.2 "Helvetica",Verdana,sans-serif;background: white;}
203213
@media screen {
204214
.main {background-size: 100% 100%;font-size: 1.3em;background-color: #fff;}
205215
}
206-
', $this->document->render(OutputFormat::create()->set('Space*Blocks', "\n")));
216+
', $this->document->render($outputFormat));
207217
}
208218

209219
/**
210220
* @test
211221
*/
212222
public function spaceBoth(): void
213223
{
224+
$outputFormat = OutputFormat::create()
225+
->setSpaceBeforeRules("\n")
226+
->setSpaceBetweenRules("\n")
227+
->setSpaceAfterRules("\n")
228+
->setSpaceBeforeBlocks("\n")
229+
->setSpaceBetweenBlocks("\n")
230+
->setSpaceAfterBlocks("\n");
231+
214232
self::assertSame('
215233
.main, .test {
216234
font: italic normal bold 16px/1.2 "Helvetica",Verdana,sans-serif;
@@ -223,18 +241,21 @@ public function spaceBoth(): void
223241
background-color: #fff;
224242
}
225243
}
226-
', $this->document->render(OutputFormat::create()->set('Space*Rules', "\n")->set('Space*Blocks', "\n")));
244+
', $this->document->render($outputFormat));
227245
}
228246

229247
/**
230248
* @test
231249
*/
232250
public function spaceBetweenBlocks(): void
233251
{
252+
$outputFormat = OutputFormat::create()
253+
->setSpaceBetweenBlocks('');
254+
234255
self::assertSame(
235256
'.main, .test {font: italic normal bold 16px/1.2 "Helvetica",Verdana,sans-serif;background: white;}'
236257
. '@media screen {.main {background-size: 100% 100%;font-size: 1.3em;background-color: #fff;}}',
237-
$this->document->render(OutputFormat::create()->setSpaceBetweenBlocks(''))
258+
$this->document->render($outputFormat)
238259
);
239260
}
240261

@@ -243,6 +264,15 @@ public function spaceBetweenBlocks(): void
243264
*/
244265
public function indentation(): void
245266
{
267+
$outputFormat = OutputFormat::create()
268+
->setSpaceBeforeRules("\n")
269+
->setSpaceBetweenRules("\n")
270+
->setSpaceAfterRules("\n")
271+
->setSpaceBeforeBlocks("\n")
272+
->setSpaceBetweenBlocks("\n")
273+
->setSpaceAfterBlocks("\n")
274+
->setIndentation('');
275+
246276
self::assertSame('
247277
.main, .test {
248278
font: italic normal bold 16px/1.2 "Helvetica",Verdana,sans-serif;
@@ -255,21 +285,21 @@ public function indentation(): void
255285
background-color: #fff;
256286
}
257287
}
258-
', $this->document->render(OutputFormat::create()
259-
->set('Space*Rules', "\n")
260-
->set('Space*Blocks', "\n")
261-
->setIndentation('')));
288+
', $this->document->render($outputFormat));
262289
}
263290

264291
/**
265292
* @test
266293
*/
267294
public function spaceBeforeBraces(): void
268295
{
296+
$outputFormat = OutputFormat::create()
297+
->setSpaceBeforeOpeningBrace('');
298+
269299
self::assertSame(
270300
'.main, .test{font: italic normal bold 16px/1.2 "Helvetica",Verdana,sans-serif;background: white;}
271301
@media screen{.main{background-size: 100% 100%;font-size: 1.3em;background-color: #fff;}}',
272-
$this->document->render(OutputFormat::create()->setSpaceBeforeOpeningBrace(''))
302+
$this->document->render($outputFormat)
273303
);
274304
}
275305

@@ -280,30 +310,34 @@ public function ignoreExceptionsOff(): void
280310
{
281311
$this->expectException(OutputException::class);
282312

313+
$outputFormat = OutputFormat::create()->setIgnoreExceptions(false);
314+
283315
$declarationBlocks = $this->document->getAllDeclarationBlocks();
284316
$firstDeclarationBlock = $declarationBlocks[0];
285317
$firstDeclarationBlock->removeSelector('.main');
286318
self::assertSame(
287319
'.test {font: italic normal bold 16px/1.2 "Helvetica",Verdana,sans-serif;background: white;}
288320
@media screen {.main {background-size: 100% 100%;font-size: 1.3em;background-color: #fff;}}',
289-
$this->document->render(OutputFormat::create()->setIgnoreExceptions(false))
321+
$this->document->render($outputFormat)
290322
);
291323
$firstDeclarationBlock->removeSelector('.test');
292-
$this->document->render(OutputFormat::create()->setIgnoreExceptions(false));
324+
$this->document->render($outputFormat);
293325
}
294326

295327
/**
296328
* @test
297329
*/
298330
public function ignoreExceptionsOn(): void
299331
{
332+
$outputFormat = OutputFormat::create()->setIgnoreExceptions(true);
333+
300334
$declarationBlocks = $this->document->getAllDeclarationBlocks();
301335
$firstDeclarationBlock = $declarationBlocks[0];
302336
$firstDeclarationBlock->removeSelector('.main');
303337
$firstDeclarationBlock->removeSelector('.test');
304338
self::assertSame(
305339
'@media screen {.main {background-size: 100% 100%;font-size: 1.3em;background-color: #fff;}}',
306-
$this->document->render(OutputFormat::create()->setIgnoreExceptions(true))
340+
$this->document->render($outputFormat)
307341
);
308342
}
309343
}

0 commit comments

Comments
 (0)