From 8818f963012b9e1d6c258244a44837bcb643dac8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kai=20K=C3=B6nig?= <50620424+KaiOnGitHub@users.noreply.github.com> Date: Sat, 17 Feb 2024 15:07:39 +0100 Subject: [PATCH 1/2] [FEATURE] Add support for the `dvh`, `lvh` and `svh` length units (#415) Fixes #412 For now, the `TestCase` just tests that all the unit values are parsed. (Other tests can be added here, but are beyond the scope of this change.) --- CHANGELOG.md | 2 ++ src/Value/Size.php | 7 +++++- tests/Value/SizeTest.php | 51 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 59 insertions(+), 1 deletion(-) create mode 100644 tests/Value/SizeTest.php diff --git a/CHANGELOG.md b/CHANGELOG.md index 86ceb2ca..348b62de 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,8 @@ This project adheres to [Semantic Versioning](https://semver.org/). ### Added +- Add support for the `dvh`, `lvh` and `svh` length units (#415) + ### Changed ### Deprecated diff --git a/src/Value/Size.php b/src/Value/Size.php index 19a29d52..5b5ab772 100644 --- a/src/Value/Size.php +++ b/src/Value/Size.php @@ -19,7 +19,12 @@ class Size extends PrimitiveValue * * @internal */ - const ABSOLUTE_SIZE_UNITS = ['px', 'cm', 'mm', 'mozmm', 'in', 'pt', 'pc', 'vh', 'vw', 'vmin', 'vmax', 'rem']; + const ABSOLUTE_SIZE_UNITS = [ + 'px', 'pt', 'pc', + 'cm', 'mm', 'mozmm', 'in', + 'vh', 'dvh', 'svh', 'lvh', + 'vw', 'vmin', 'vmax', 'rem', + ]; /** * @var array diff --git a/tests/Value/SizeTest.php b/tests/Value/SizeTest.php new file mode 100644 index 00000000..3aecce05 --- /dev/null +++ b/tests/Value/SizeTest.php @@ -0,0 +1,51 @@ + + */ + public static function provideUnit(): array + { + $units = [ + 'px', 'pt', 'pc', + 'cm', 'mm', 'mozmm', 'in', + 'vh', 'dvh', 'svh', 'lvh', + 'vw', 'vmin', 'vmax', 'rem', + '%', 'em', 'ex', 'ch', 'fr', + 'deg', 'grad', 'rad', 's', 'ms', 'turn', 'Hz', 'kHz', + ]; + + return \array_combine( + $units, + \array_map( + function (string $unit): array { + return [$unit]; + }, + $units + ) + ); + } + + /** + * @test + * + * @dataProvider provideUnit + */ + public function parsesUnit(string $unit): void + { + $subject = Size::parse(new ParserState('1' . $unit, Settings::create())); + + self::assertSame($unit, $subject->getUnit()); + } +} From a86276479efb7f4a1e78de1aada991c208cb0c5b Mon Sep 17 00:00:00 2001 From: Jake Hotson Date: Fri, 28 Jun 2024 22:54:04 +0100 Subject: [PATCH 2/2] Remove type hints for PHP5 --- tests/Value/SizeTest.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/Value/SizeTest.php b/tests/Value/SizeTest.php index 3aecce05..d743087a 100644 --- a/tests/Value/SizeTest.php +++ b/tests/Value/SizeTest.php @@ -15,7 +15,7 @@ final class SizeTest extends TestCase /** * @return array */ - public static function provideUnit(): array + public static function provideUnit() { $units = [ 'px', 'pt', 'pc', @@ -29,7 +29,7 @@ public static function provideUnit(): array return \array_combine( $units, \array_map( - function (string $unit): array { + function ($unit) { return [$unit]; }, $units @@ -42,7 +42,7 @@ function (string $unit): array { * * @dataProvider provideUnit */ - public function parsesUnit(string $unit): void + public function parsesUnit($unit) { $subject = Size::parse(new ParserState('1' . $unit, Settings::create()));