From 06806205eb916e2f94ce8cc50abc4903d6fe34be Mon Sep 17 00:00:00 2001 From: Oliver Klee Date: Sun, 16 Mar 2025 21:54:07 +0100 Subject: [PATCH] [TASK] Avoid the deprecated `__toString()` in tests Moving some tests to functional tests and splitting them up will come in later changes for #1057. --- tests/Unit/Value/ColorTest.php | 3 ++- tests/Unit/Value/ValueTest.php | 17 ++++++++++++++--- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/tests/Unit/Value/ColorTest.php b/tests/Unit/Value/ColorTest.php index f516d313..aaa25755 100644 --- a/tests/Unit/Value/ColorTest.php +++ b/tests/Unit/Value/ColorTest.php @@ -5,6 +5,7 @@ namespace Sabberworm\CSS\Tests\Unit\Value; use PHPUnit\Framework\TestCase; +use Sabberworm\CSS\OutputFormat; use Sabberworm\CSS\Parsing\ParserState; use Sabberworm\CSS\Parsing\SourceException; use Sabberworm\CSS\Settings; @@ -346,7 +347,7 @@ public function parsesAndRendersValidColor(string $color, string $expectedRender { $subject = Color::parse(new ParserState($color, Settings::create())); - $renderedResult = (string) $subject; + $renderedResult = $subject->render(OutputFormat::create()); self::assertSame($expectedRendering, $renderedResult); } diff --git a/tests/Unit/Value/ValueTest.php b/tests/Unit/Value/ValueTest.php index d6dd21af..5aa8c83c 100644 --- a/tests/Unit/Value/ValueTest.php +++ b/tests/Unit/Value/ValueTest.php @@ -5,8 +5,10 @@ namespace Sabberworm\CSS\Tests\Unit\Value; use PHPUnit\Framework\TestCase; +use Sabberworm\CSS\OutputFormat; use Sabberworm\CSS\Parsing\ParserState; use Sabberworm\CSS\Settings; +use Sabberworm\CSS\Value\CSSFunction; use Sabberworm\CSS\Value\Value; /** @@ -48,7 +50,8 @@ public function parsesArithmeticInFunctions(string $operator): void self::DEFAULT_DELIMITERS ); - self::assertSame('max(300px,50vh ' . $operator . ' 10px)', (string) $subject); + self::assertInstanceOf(CSSFunction::class, $subject); + self::assertSame('max(300px,50vh ' . $operator . ' 10px)', $subject->render(OutputFormat::createCompact())); } /** @@ -90,7 +93,11 @@ public function parsesArithmeticWithMultipleOperatorsInFunctions( self::DEFAULT_DELIMITERS ); - self::assertSame(\sprintf($expectedResultTemplate, $expression), (string) $subject); + self::assertInstanceOf(CSSFunction::class, $subject); + self::assertSame( + \sprintf($expectedResultTemplate, $expression), + $subject->render(OutputFormat::createCompact()) + ); } /** @@ -118,6 +125,10 @@ public function parsesArithmeticWithMalformedOperandsInFunctions(string $leftOpe self::DEFAULT_DELIMITERS ); - self::assertSame('max(300px,' . $leftOperand . ' + ' . $rightOperand . ')', (string) $subject); + self::assertInstanceOf(CSSFunction::class, $subject); + self::assertSame( + 'max(300px,' . $leftOperand . ' + ' . $rightOperand . ')', + $subject->render(OutputFormat::createCompact()) + ); } }