Skip to content

[CLEANUP] Add more type assertions in the tests #884

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 1 commit into from
Feb 9, 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
11 changes: 0 additions & 11 deletions config/phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -234,15 +234,4 @@ parameters:
count: 1
path: ../src/Value/ValueList.php

-
message: '#^Cannot call method getColor\(\) on Sabberworm\\CSS\\Value\\RuleValueList\|string\.$#'
identifier: method.nonObject
count: 7
path: ../tests/ParserTest.php

-
message: '#^Cannot call method getListSeparator\(\) on Sabberworm\\CSS\\Value\\Value\|string\.$#'
identifier: method.nonObject
count: 4
path: ../tests/ParserTest.php

13 changes: 13 additions & 0 deletions tests/ParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
use Sabberworm\CSS\Value\Color;
use Sabberworm\CSS\Value\Size;
use Sabberworm\CSS\Value\URL;
use Sabberworm\CSS\Value\Value;
use Sabberworm\CSS\Value\ValueList;

/**
* @covers \Sabberworm\CSS\CSSList\Document
Expand Down Expand Up @@ -108,19 +110,22 @@ public function colorParsing(): void
self::assertSame('red', $colorRuleValue);
$colorRules = $ruleSet->getRules('background-');
$colorRuleValue = $colorRules[0]->getValue();
self::assertInstanceOf(Color::class, $colorRuleValue);
self::assertEquals([
'r' => new Size(35.0, null, true, $colorRuleValue->getLineNo()),
'g' => new Size(35.0, null, true, $colorRuleValue->getLineNo()),
'b' => new Size(35.0, null, true, $colorRuleValue->getLineNo()),
], $colorRuleValue->getColor());
$colorRules = $ruleSet->getRules('border-color');
$colorRuleValue = $colorRules[0]->getValue();
self::assertInstanceOf(Color::class, $colorRuleValue);
self::assertEquals([
'r' => new Size(10.0, null, true, $colorRuleValue->getLineNo()),
'g' => new Size(100.0, null, true, $colorRuleValue->getLineNo()),
'b' => new Size(230.0, null, true, $colorRuleValue->getLineNo()),
], $colorRuleValue->getColor());
$colorRuleValue = $colorRules[1]->getValue();
self::assertInstanceOf(Color::class, $colorRuleValue);
self::assertEquals([
'r' => new Size(10.0, null, true, $colorRuleValue->getLineNo()),
'g' => new Size(100.0, null, true, $colorRuleValue->getLineNo()),
Expand All @@ -129,6 +134,7 @@ public function colorParsing(): void
], $colorRuleValue->getColor());
$colorRules = $ruleSet->getRules('outline-color');
$colorRuleValue = $colorRules[0]->getValue();
self::assertInstanceOf(Color::class, $colorRuleValue);
self::assertEquals([
'r' => new Size(34.0, null, true, $colorRuleValue->getLineNo()),
'g' => new Size(34.0, null, true, $colorRuleValue->getLineNo()),
Expand All @@ -137,12 +143,14 @@ public function colorParsing(): void
} elseif ($selector === '#yours') {
$colorRules = $ruleSet->getRules('background-color');
$colorRuleValue = $colorRules[0]->getValue();
self::assertInstanceOf(Color::class, $colorRuleValue);
self::assertEquals([
'h' => new Size(220.0, null, true, $colorRuleValue->getLineNo()),
's' => new Size(10.0, '%', true, $colorRuleValue->getLineNo()),
'l' => new Size(220.0, '%', true, $colorRuleValue->getLineNo()),
], $colorRuleValue->getColor());
$colorRuleValue = $colorRules[1]->getValue();
self::assertInstanceOf(Color::class, $colorRuleValue);
self::assertEquals([
'h' => new Size(220.0, null, true, $colorRuleValue->getLineNo()),
's' => new Size(10.0, '%', true, $colorRuleValue->getLineNo()),
Expand Down Expand Up @@ -435,7 +443,9 @@ public function slashedValues(): void
self::assertSame(' ', $fontRuleValue->getListSeparator());
$fontRuleValueComponents = $fontRuleValue->getListComponents();
$commaList = $fontRuleValueComponents[1];
self::assertInstanceOf(ValueList::class, $commaList);
$slashList = $fontRuleValueComponents[0];
self::assertInstanceOf(ValueList::class, $slashList);
self::assertSame(',', $commaList->getListSeparator());
self::assertSame('/', $slashList->getListSeparator());
$borderRadiusRules = $declarationBlock->getRules('border-radius');
Expand All @@ -444,7 +454,9 @@ public function slashedValues(): void
self::assertSame('/', $slashList->getListSeparator());
$slashListComponents = $slashList->getListComponents();
$secondSlashListComponent = $slashListComponents[1];
self::assertInstanceOf(ValueList::class, $secondSlashListComponent);
$firstSlashListComponent = $slashListComponents[0];
self::assertInstanceOf(ValueList::class, $firstSlashListComponent);
self::assertSame(' ', $firstSlashListComponent->getListSeparator());
self::assertSame(' ', $secondSlashListComponent->getListSeparator());
}
Expand Down Expand Up @@ -1019,6 +1031,7 @@ public function lineNumbersParsing(): void
$rules = $secondDeclarationBlock->getRules();
// Choose the 2nd one
$valueOfSecondRule = $rules[1]->getValue();
self::assertInstanceOf(Color::class, $valueOfSecondRule);
self::assertSame(27, $rules[1]->getLineNo());

$actualColorLineNumbers = [];
Expand Down