Skip to content

Commit d2d1db5

Browse files
authored
[CLEANUP] Add more type assertions in the tests (#884)
1 parent cb3ae4b commit d2d1db5

File tree

2 files changed

+13
-11
lines changed

2 files changed

+13
-11
lines changed

config/phpstan-baseline.neon

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -234,15 +234,4 @@ parameters:
234234
count: 1
235235
path: ../src/Value/ValueList.php
236236

237-
-
238-
message: '#^Cannot call method getColor\(\) on Sabberworm\\CSS\\Value\\RuleValueList\|string\.$#'
239-
identifier: method.nonObject
240-
count: 7
241-
path: ../tests/ParserTest.php
242-
243-
-
244-
message: '#^Cannot call method getListSeparator\(\) on Sabberworm\\CSS\\Value\\Value\|string\.$#'
245-
identifier: method.nonObject
246-
count: 4
247-
path: ../tests/ParserTest.php
248237

tests/ParserTest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
use Sabberworm\CSS\Value\Color;
2525
use Sabberworm\CSS\Value\Size;
2626
use Sabberworm\CSS\Value\URL;
27+
use Sabberworm\CSS\Value\Value;
28+
use Sabberworm\CSS\Value\ValueList;
2729

2830
/**
2931
* @covers \Sabberworm\CSS\CSSList\Document
@@ -108,19 +110,22 @@ public function colorParsing(): void
108110
self::assertSame('red', $colorRuleValue);
109111
$colorRules = $ruleSet->getRules('background-');
110112
$colorRuleValue = $colorRules[0]->getValue();
113+
self::assertInstanceOf(Color::class, $colorRuleValue);
111114
self::assertEquals([
112115
'r' => new Size(35.0, null, true, $colorRuleValue->getLineNo()),
113116
'g' => new Size(35.0, null, true, $colorRuleValue->getLineNo()),
114117
'b' => new Size(35.0, null, true, $colorRuleValue->getLineNo()),
115118
], $colorRuleValue->getColor());
116119
$colorRules = $ruleSet->getRules('border-color');
117120
$colorRuleValue = $colorRules[0]->getValue();
121+
self::assertInstanceOf(Color::class, $colorRuleValue);
118122
self::assertEquals([
119123
'r' => new Size(10.0, null, true, $colorRuleValue->getLineNo()),
120124
'g' => new Size(100.0, null, true, $colorRuleValue->getLineNo()),
121125
'b' => new Size(230.0, null, true, $colorRuleValue->getLineNo()),
122126
], $colorRuleValue->getColor());
123127
$colorRuleValue = $colorRules[1]->getValue();
128+
self::assertInstanceOf(Color::class, $colorRuleValue);
124129
self::assertEquals([
125130
'r' => new Size(10.0, null, true, $colorRuleValue->getLineNo()),
126131
'g' => new Size(100.0, null, true, $colorRuleValue->getLineNo()),
@@ -129,6 +134,7 @@ public function colorParsing(): void
129134
], $colorRuleValue->getColor());
130135
$colorRules = $ruleSet->getRules('outline-color');
131136
$colorRuleValue = $colorRules[0]->getValue();
137+
self::assertInstanceOf(Color::class, $colorRuleValue);
132138
self::assertEquals([
133139
'r' => new Size(34.0, null, true, $colorRuleValue->getLineNo()),
134140
'g' => new Size(34.0, null, true, $colorRuleValue->getLineNo()),
@@ -137,12 +143,14 @@ public function colorParsing(): void
137143
} elseif ($selector === '#yours') {
138144
$colorRules = $ruleSet->getRules('background-color');
139145
$colorRuleValue = $colorRules[0]->getValue();
146+
self::assertInstanceOf(Color::class, $colorRuleValue);
140147
self::assertEquals([
141148
'h' => new Size(220.0, null, true, $colorRuleValue->getLineNo()),
142149
's' => new Size(10.0, '%', true, $colorRuleValue->getLineNo()),
143150
'l' => new Size(220.0, '%', true, $colorRuleValue->getLineNo()),
144151
], $colorRuleValue->getColor());
145152
$colorRuleValue = $colorRules[1]->getValue();
153+
self::assertInstanceOf(Color::class, $colorRuleValue);
146154
self::assertEquals([
147155
'h' => new Size(220.0, null, true, $colorRuleValue->getLineNo()),
148156
's' => new Size(10.0, '%', true, $colorRuleValue->getLineNo()),
@@ -435,7 +443,9 @@ public function slashedValues(): void
435443
self::assertSame(' ', $fontRuleValue->getListSeparator());
436444
$fontRuleValueComponents = $fontRuleValue->getListComponents();
437445
$commaList = $fontRuleValueComponents[1];
446+
self::assertInstanceOf(ValueList::class, $commaList);
438447
$slashList = $fontRuleValueComponents[0];
448+
self::assertInstanceOf(ValueList::class, $slashList);
439449
self::assertSame(',', $commaList->getListSeparator());
440450
self::assertSame('/', $slashList->getListSeparator());
441451
$borderRadiusRules = $declarationBlock->getRules('border-radius');
@@ -444,7 +454,9 @@ public function slashedValues(): void
444454
self::assertSame('/', $slashList->getListSeparator());
445455
$slashListComponents = $slashList->getListComponents();
446456
$secondSlashListComponent = $slashListComponents[1];
457+
self::assertInstanceOf(ValueList::class, $secondSlashListComponent);
447458
$firstSlashListComponent = $slashListComponents[0];
459+
self::assertInstanceOf(ValueList::class, $firstSlashListComponent);
448460
self::assertSame(' ', $firstSlashListComponent->getListSeparator());
449461
self::assertSame(' ', $secondSlashListComponent->getListSeparator());
450462
}
@@ -1019,6 +1031,7 @@ public function lineNumbersParsing(): void
10191031
$rules = $secondDeclarationBlock->getRules();
10201032
// Choose the 2nd one
10211033
$valueOfSecondRule = $rules[1]->getValue();
1034+
self::assertInstanceOf(Color::class, $valueOfSecondRule);
10221035
self::assertSame(27, $rules[1]->getLineNo());
10231036

10241037
$actualColorLineNumbers = [];

0 commit comments

Comments
 (0)