Skip to content

[CLEANUP] Check for Positionable in lineNumbersParsing() test #1257

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
May 10, 2025
Merged
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
28 changes: 5 additions & 23 deletions tests/ParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use Sabberworm\CSS\Parsing\OutputException;
use Sabberworm\CSS\Parsing\SourceException;
use Sabberworm\CSS\Parsing\UnexpectedTokenException;
use Sabberworm\CSS\Position\Positionable;
use Sabberworm\CSS\Property\AtRule;
use Sabberworm\CSS\Property\Charset;
use Sabberworm\CSS\Property\CSSNamespace;
Expand Down Expand Up @@ -975,31 +976,12 @@ public function lineNumbersParsing(): void

$actual = [];
foreach ($document->getContents() as $contentItem) {
// PHPStan can see what `assertInstanceOf()` does,
// but does not understand `LogicalOr` with multiple `IsIntanceOf` constraints.
// So a more explicit type check is required.
// TODO: tidy this up when an interface with `getLineNo()` is added.
if (
!$contentItem instanceof Charset
&& !$contentItem instanceof CSSList
&& !$contentItem instanceof CSSNamespace
&& !$contentItem instanceof Import
&& !$contentItem instanceof RuleSet
) {
self::fail('Content item is not of an expected type. It\'s a `' . \get_class($contentItem) . '`.');
}
$actual[$contentItem->getLineNo()] = [\get_class($contentItem)];
self::assertInstanceOf(Positionable::class, $contentItem);
$actual[$contentItem->getLineNumber()] = [\get_class($contentItem)];
if ($contentItem instanceof KeyFrame) {
foreach ($contentItem->getContents() as $block) {
if (
!$block instanceof CSSList
&& !$block instanceof RuleSet
) {
self::fail(
'KeyFrame content item is not of an expected type. It\'s a `' . \get_class($block) . '`.'
);
}
$actual[$contentItem->getLineNo()][] = $block->getLineNo();
self::assertInstanceOf(Positionable::class, $block);
$actual[$contentItem->getLineNumber()][] = $block->getLineNumber();
}
}
}
Expand Down