Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ Please also have a look at our

### Fixed

- Parse `@font-face` `src` property as comma-delimited list (#790)
- Fix type errors in PHP strict mode (#664)
- Fix undefined local variable in `CalcFunction::parse()` (#593)
- Fix PHP notice caused by parsing invalid color values having less than 6
Expand Down
14 changes: 12 additions & 2 deletions src/Rule/Rule.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,16 +114,26 @@ public static function parse(ParserState $oParserState): Rule
}

/**
* Returns a list of delimiters (or separators).
* The first item is the innermost separator (or, put another way, the highest-precedence operator).
* The sequence continues to the outermost separator (or lowest-precedence operator).
*
* @param string $sRule
*
* @return array<int, string>
* @return list<non-empty-string>
*/
private static function listDelimiterForRule($sRule): array
{
if (\preg_match('/^font($|-)/', $sRule)) {
return [',', '/', ' '];
}
return [',', ' ', '/'];

switch ($sRule) {
case 'src':
return [' ', ','];
default:
return [',', ' ', '/'];
}
}

/**
Expand Down
Empty file removed tests/Unit/.gitkeep
Empty file.
61 changes: 61 additions & 0 deletions tests/Unit/Rule/RuleTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?php

declare(strict_types=1);

namespace Sabberworm\CSS\Tests\Value;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
namespace Sabberworm\CSS\Tests\Value;
namespace Sabberworm\CSS\Tests\Unit\Value;

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It lost my comment.

The namespace should also have been Rule not Value - mistake arising from copying and pasting from another file as a template.


use PHPUnit\Framework\TestCase;
use Sabberworm\CSS\Parsing\ParserState;
use Sabberworm\CSS\Settings;
use Sabberworm\CSS\Rule\Rule;
use Sabberworm\CSS\Value\RuleValueList;
use Sabberworm\CSS\Value\ValueList;

/**
* @covers \Sabberworm\CSS\Rule\Rule
*/
final class RuleTest extends TestCase
{
/**
* @return array<string, array{0: string, 1: list<class-string>}>
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
* @return array<string, array{0: string, 1: list<class-string>}>
* @return array<string, array{0: string, 1: list<class-string>}>

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Corrected.

*/
public static function provideRulesAndExpectedParsedValueListTypes(): array
{
return [
'src (e.g. in @font-face)' => [
"
src: url('../fonts/open-sans-italic-300.woff2') format('woff2'),
url('../fonts/open-sans-italic-300.ttf') format('truetype');
",
[RuleValueList::class, RuleValueList::class],
],
];
}

/**
* @test
*
* @param list<class-string> $expectedTypeClassnames
*
* @dataProvider provideRulesAndExpectedParsedValueListTypes
*/
public function parsesValuesIntoExpectedTypeList(string $rule, array $expectedTypeClassnames): void
{
$subject = Rule::parse(new ParserState($rule, Settings::create()));

$value = $subject->getValue();
self::assertInstanceOf(ValueList::class, $value);

$actualClassnames = \array_map(
/**
* @param Value|string $component
*/
static function ($component): string {
return \is_string($component) ? 'string' : \get_class($component);
},
$value->getListComponents()
);

self::assertSame($expectedTypeClassnames, $actualClassnames);
}
}