From b97b6e714aebc0b99526a24357d35399d0b2a297 Mon Sep 17 00:00:00 2001 From: Jake Hotson Date: Mon, 21 Jul 2025 15:40:25 +0100 Subject: [PATCH 1/2] [CLEANUP] Use `getAllDeclarationBlocks` in `colorParsing` test ... instead of `getAllRuleSets`. This avoids testing if `RuleSet`s are `DeclarationBlock`s, and will be needed for #1194. --- tests/ParserTest.php | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/tests/ParserTest.php b/tests/ParserTest.php index da991ee7f..4bbf5b800 100644 --- a/tests/ParserTest.php +++ b/tests/ParserTest.php @@ -91,10 +91,7 @@ public function files(): void public function colorParsing(): void { $document = self::parsedStructureForFile('colortest'); - foreach ($document->getAllRuleSets() as $ruleSet) { - if (!($ruleSet instanceof DeclarationBlock)) { - continue; - } + foreach ($document->getAllDeclarationBlocks() as $ruleSet) { $selectors = $ruleSet->getSelectors(); $selector = $selectors[0]->getSelector(); if ($selector === '#mine') { From 292bda955cb516814586d2c66189a68eb05d593e Mon Sep 17 00:00:00 2001 From: Jake Hotson Date: Mon, 21 Jul 2025 17:21:46 +0100 Subject: [PATCH 2/2] Rename local variable to `$declarationBlock`. Also similarly rename local variable in `unicodeParsing()`. --- tests/ParserTest.php | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/tests/ParserTest.php b/tests/ParserTest.php index 4bbf5b800..15af0fd78 100644 --- a/tests/ParserTest.php +++ b/tests/ParserTest.php @@ -91,14 +91,14 @@ public function files(): void public function colorParsing(): void { $document = self::parsedStructureForFile('colortest'); - foreach ($document->getAllDeclarationBlocks() as $ruleSet) { - $selectors = $ruleSet->getSelectors(); + foreach ($document->getAllDeclarationBlocks() as $declarationBlock) { + $selectors = $declarationBlock->getSelectors(); $selector = $selectors[0]->getSelector(); if ($selector === '#mine') { - $colorRules = $ruleSet->getRules('color'); + $colorRules = $declarationBlock->getRules('color'); $colorRuleValue = $colorRules[0]->getValue(); self::assertSame('red', $colorRuleValue); - $colorRules = $ruleSet->getRules('background-'); + $colorRules = $declarationBlock->getRules('background-'); $colorRuleValue = $colorRules[0]->getValue(); self::assertInstanceOf(Color::class, $colorRuleValue); self::assertEquals([ @@ -106,7 +106,7 @@ public function colorParsing(): void 'g' => new Size(35.0, null, true, $colorRuleValue->getLineNumber()), 'b' => new Size(35.0, null, true, $colorRuleValue->getLineNumber()), ], $colorRuleValue->getColor()); - $colorRules = $ruleSet->getRules('border-color'); + $colorRules = $declarationBlock->getRules('border-color'); $colorRuleValue = $colorRules[0]->getValue(); self::assertInstanceOf(Color::class, $colorRuleValue); self::assertEquals([ @@ -122,7 +122,7 @@ public function colorParsing(): void 'b' => new Size(231.0, null, true, $colorRuleValue->getLineNumber()), 'a' => new Size('0000.3', null, true, $colorRuleValue->getLineNumber()), ], $colorRuleValue->getColor()); - $colorRules = $ruleSet->getRules('outline-color'); + $colorRules = $declarationBlock->getRules('outline-color'); $colorRuleValue = $colorRules[0]->getValue(); self::assertInstanceOf(Color::class, $colorRuleValue); self::assertEquals([ @@ -131,7 +131,7 @@ public function colorParsing(): void 'b' => new Size(34.0, null, true, $colorRuleValue->getLineNumber()), ], $colorRuleValue->getColor()); } elseif ($selector === '#yours') { - $colorRules = $ruleSet->getRules('background-color'); + $colorRules = $declarationBlock->getRules('background-color'); $colorRuleValue = $colorRules[0]->getValue(); self::assertInstanceOf(Color::class, $colorRuleValue); self::assertEquals([ @@ -147,7 +147,7 @@ public function colorParsing(): void 'l' => new Size(220.0, '%', true, $colorRuleValue->getLineNumber()), 'a' => new Size(0000.3, null, true, $colorRuleValue->getLineNumber()), ], $colorRuleValue->getColor()); - $colorRules = $ruleSet->getRules('outline-color'); + $colorRules = $declarationBlock->getRules('outline-color'); self::assertEmpty($colorRules); } } @@ -176,13 +176,13 @@ public function colorParsing(): void public function unicodeParsing(): void { $document = self::parsedStructureForFile('unicode'); - foreach ($document->getAllDeclarationBlocks() as $ruleSet) { - $selectors = $ruleSet->getSelectors(); + foreach ($document->getAllDeclarationBlocks() as $declarationBlock) { + $selectors = $declarationBlock->getSelectors(); $selector = $selectors[0]->getSelector(); if (\substr($selector, 0, \strlen('.test-')) !== '.test-') { continue; } - $contentRules = $ruleSet->getRules('content'); + $contentRules = $declarationBlock->getRules('content'); $firstContentRuleAsString = $contentRules[0]->getValue()->render(OutputFormat::create()); if ($selector === '.test-1') { self::assertSame('" "', $firstContentRuleAsString);