Skip to content

[CLEANUP] Use the explicit OutputFormat setters in the tests #1106

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions config/phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,6 @@ parameters:
count: 2
path: ../src/CSSList/KeyFrame.php

-
message: '#^Parameters should have "string\|string" types as the only types passed to this method$#'
identifier: typePerfect.narrowPublicClassMethodParamType
count: 1
path: ../src/OutputFormat.php

-
message: '#^Returning false in non return bool class method\. Use null with type\|null instead or add bool return type$#'
identifier: typePerfect.nullOverFalse
Expand Down
58 changes: 46 additions & 12 deletions tests/OutputFormatTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,11 @@ public function spaceAfterRuleName(): void
*/
public function spaceRules(): void
{
$outputFormat = OutputFormat::create()
->setSpaceBeforeRules("\n")
->setSpaceBetweenRules("\n")
->setSpaceAfterRules("\n");

self::assertSame('.main, .test {
font: italic normal bold 16px/1.2 "Helvetica",Verdana,sans-serif;
background: white;
Expand All @@ -190,27 +195,40 @@ public function spaceRules(): void
background-size: 100% 100%;
font-size: 1.3em;
background-color: #fff;
}}', $this->document->render(OutputFormat::create()->set('Space*Rules', "\n")));
}}', $this->document->render($outputFormat));
}

/**
* @test
*/
public function spaceBlocks(): void
{
$outputFormat = OutputFormat::create()
->setSpaceBeforeBlocks("\n")
->setSpaceBetweenBlocks("\n")
->setSpaceAfterBlocks("\n");

self::assertSame('
.main, .test {font: italic normal bold 16px/1.2 "Helvetica",Verdana,sans-serif;background: white;}
@media screen {
.main {background-size: 100% 100%;font-size: 1.3em;background-color: #fff;}
}
', $this->document->render(OutputFormat::create()->set('Space*Blocks', "\n")));
', $this->document->render($outputFormat));
}

/**
* @test
*/
public function spaceBoth(): void
{
$outputFormat = OutputFormat::create()
->setSpaceBeforeRules("\n")
->setSpaceBetweenRules("\n")
->setSpaceAfterRules("\n")
->setSpaceBeforeBlocks("\n")
->setSpaceBetweenBlocks("\n")
->setSpaceAfterBlocks("\n");

self::assertSame('
.main, .test {
font: italic normal bold 16px/1.2 "Helvetica",Verdana,sans-serif;
Expand All @@ -223,18 +241,21 @@ public function spaceBoth(): void
background-color: #fff;
}
}
', $this->document->render(OutputFormat::create()->set('Space*Rules', "\n")->set('Space*Blocks', "\n")));
', $this->document->render($outputFormat));
}

/**
* @test
*/
public function spaceBetweenBlocks(): void
{
$outputFormat = OutputFormat::create()
->setSpaceBetweenBlocks('');

self::assertSame(
'.main, .test {font: italic normal bold 16px/1.2 "Helvetica",Verdana,sans-serif;background: white;}'
. '@media screen {.main {background-size: 100% 100%;font-size: 1.3em;background-color: #fff;}}',
$this->document->render(OutputFormat::create()->setSpaceBetweenBlocks(''))
$this->document->render($outputFormat)
);
}

Expand All @@ -243,6 +264,15 @@ public function spaceBetweenBlocks(): void
*/
public function indentation(): void
{
$outputFormat = OutputFormat::create()
->setSpaceBeforeRules("\n")
->setSpaceBetweenRules("\n")
->setSpaceAfterRules("\n")
->setSpaceBeforeBlocks("\n")
->setSpaceBetweenBlocks("\n")
->setSpaceAfterBlocks("\n")
->setIndentation('');

self::assertSame('
.main, .test {
font: italic normal bold 16px/1.2 "Helvetica",Verdana,sans-serif;
Expand All @@ -255,21 +285,21 @@ public function indentation(): void
background-color: #fff;
}
}
', $this->document->render(OutputFormat::create()
->set('Space*Rules', "\n")
->set('Space*Blocks', "\n")
->setIndentation('')));
', $this->document->render($outputFormat));
}

/**
* @test
*/
public function spaceBeforeBraces(): void
{
$outputFormat = OutputFormat::create()
->setSpaceBeforeOpeningBrace('');

self::assertSame(
'.main, .test{font: italic normal bold 16px/1.2 "Helvetica",Verdana,sans-serif;background: white;}
@media screen{.main{background-size: 100% 100%;font-size: 1.3em;background-color: #fff;}}',
$this->document->render(OutputFormat::create()->setSpaceBeforeOpeningBrace(''))
$this->document->render($outputFormat)
);
}

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

$outputFormat = OutputFormat::create()->setIgnoreExceptions(false);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test uses two separate OutputFormats.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've now changed it to use the same instance (as it doesn't seem relevant to me to use two instances with identical settings).

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it doesn't seem relevant to me to use two instances with identical settings

Me neither - given that it's just testing that an exception is thrown when attempting to render a declaration block without a selector.


$declarationBlocks = $this->document->getAllDeclarationBlocks();
$firstDeclarationBlock = $declarationBlocks[0];
$firstDeclarationBlock->removeSelector('.main');
self::assertSame(
'.test {font: italic normal bold 16px/1.2 "Helvetica",Verdana,sans-serif;background: white;}
@media screen {.main {background-size: 100% 100%;font-size: 1.3em;background-color: #fff;}}',
$this->document->render(OutputFormat::create()->setIgnoreExceptions(false))
$this->document->render($outputFormat)
);
$firstDeclarationBlock->removeSelector('.test');
$this->document->render(OutputFormat::create()->setIgnoreExceptions(false));
$this->document->render($outputFormat);
}

/**
* @test
*/
public function ignoreExceptionsOn(): void
{
$outputFormat = OutputFormat::create()->setIgnoreExceptions(true);

$declarationBlocks = $this->document->getAllDeclarationBlocks();
$firstDeclarationBlock = $declarationBlocks[0];
$firstDeclarationBlock->removeSelector('.main');
$firstDeclarationBlock->removeSelector('.test');
self::assertSame(
'@media screen {.main {background-size: 100% 100%;font-size: 1.3em;background-color: #fff;}}',
$this->document->render(OutputFormat::create()->setIgnoreExceptions(true))
$this->document->render($outputFormat)
);
}
}