From c74bdd0df74395f50386855f2c04a338d3300b59 Mon Sep 17 00:00:00 2001 From: Oliver Klee Date: Sun, 9 Feb 2025 20:52:55 +0100 Subject: [PATCH 1/3] [TASK] Add more tests for `OutputFormat` --- tests/Unit/OutputFormatTest.php | 139 ++++++++++++++++++++++++++++++++ 1 file changed, 139 insertions(+) diff --git a/tests/Unit/OutputFormatTest.php b/tests/Unit/OutputFormatTest.php index d3979c20..80c36acd 100644 --- a/tests/Unit/OutputFormatTest.php +++ b/tests/Unit/OutputFormatTest.php @@ -1016,6 +1016,16 @@ public function createCompactReturnsInstanceWithSpaceAfterSelectorSeparatorSetTo self::assertSame('', $newInstance->getSpaceAfterSelectorSeparator()); } + /** + * @test + */ + public function createCompactReturnsInstanceWithSpaceAfterListArgumentSeparatorsSetToEmptyArray(): void + { + $newInstance = OutputFormat::createCompact(); + + self::assertSame([], $newInstance->getSpaceAfterListArgumentSeparators()); + } + /** * @test */ @@ -1025,4 +1035,133 @@ public function createCompactReturnsInstanceWithRenderCommentsDisabled(): void self::assertFalse($newInstance->getRenderComments()); } + + /** + * @test + */ + public function createPrettyReturnsNewOutputFormatInstance(): void + { + self::assertInstanceOf(OutputFormat::class, OutputFormat::createPretty()); + } + + /** + * @test + */ + public function createPrettyCalledTwoTimesReturnsDifferentInstances(): void + { + $firstCallResult = OutputFormat::createPretty(); + $secondCallResult = OutputFormat::createPretty(); + + self::assertNotSame($firstCallResult, $secondCallResult); + } + + /** + * @test + */ + public function createPrettyReturnsInstanceWithSpaceBeforeRulesSetToNewline(): void + { + $newInstance = OutputFormat::createPretty(); + + self::assertSame("\n", $newInstance->getSpaceBeforeRules()); + } + + /** + * @test + */ + public function createPrettyReturnsInstanceWithSpaceBetweenRulesSetToNewline(): void + { + $newInstance = OutputFormat::createPretty(); + + self::assertSame("\n", $newInstance->getSpaceBetweenRules()); + } + + /** + * @test + */ + public function createPrettyReturnsInstanceWithSpaceAfterRulesSetToNewline(): void + { + $newInstance = OutputFormat::createPretty(); + + self::assertSame("\n", $newInstance->getSpaceAfterRules()); + } + + /** + * @test + */ + public function createPrettyReturnsInstanceWithSpaceBeforeBlocksSetToNewline(): void + { + $newInstance = OutputFormat::createPretty(); + + self::assertSame("\n", $newInstance->getSpaceBeforeBlocks()); + } + + /** + * @test + */ + public function createPrettyReturnsInstanceWithSpaceBetweenBlocksSetToTwoNewlines(): void + { + $newInstance = OutputFormat::createPretty(); + + self::assertSame("\n\n", $newInstance->getSpaceBetweenBlocks()); + } + + /** + * @test + */ + public function createPrettyReturnsInstanceWithSpaceAfterBlocksSetToNewline(): void + { + $newInstance = OutputFormat::createPretty(); + + self::assertSame("\n", $newInstance->getSpaceAfterBlocks()); + } + + /** + * @test + */ + public function createPrettyReturnsInstanceWithSpaceAfterRuleNameSetSpace(): void + { + $newInstance = OutputFormat::createPretty(); + + self::assertSame(' ', $newInstance->getSpaceAfterRuleName()); + } + + /** + * @test + */ + public function createPrettyReturnsInstanceWithSpaceBeforeOpeningBraceSetToSpace(): void + { + $newInstance = OutputFormat::createPretty(); + + self::assertSame(' ', $newInstance->getSpaceBeforeOpeningBrace()); + } + + /** + * @test + */ + public function createPrettyReturnsInstanceWithSpaceAfterSelectorSeparatorSetToSpace(): void + { + $newInstance = OutputFormat::createPretty(); + + self::assertSame(' ', $newInstance->getSpaceAfterSelectorSeparator()); + } + + /** + * @test + */ + public function createPrettyReturnsInstanceWithSpaceAfterListArgumentSeparatorsSetToSpaceForComma(): void + { + $newInstance = OutputFormat::createPretty(); + + self::assertSame([',' => ' '], $newInstance->getSpaceAfterListArgumentSeparators()); + } + + /** + * @test + */ + public function createPrettyReturnsInstanceWithRenderCommentsEnabled(): void + { + $newInstance = OutputFormat::createPretty(); + + self::assertTrue($newInstance->getRenderComments()); + } } From 00defcef00b196a54b5540edef8232e3ec5a652f Mon Sep 17 00:00:00 2001 From: Oliver Klee Date: Mon, 10 Feb 2025 09:58:50 +0100 Subject: [PATCH 2/3] Update tests/Unit/OutputFormatTest.php Co-authored-by: JakeQZ --- tests/Unit/OutputFormatTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Unit/OutputFormatTest.php b/tests/Unit/OutputFormatTest.php index 80c36acd..bc0e99bb 100644 --- a/tests/Unit/OutputFormatTest.php +++ b/tests/Unit/OutputFormatTest.php @@ -1118,7 +1118,7 @@ public function createPrettyReturnsInstanceWithSpaceAfterBlocksSetToNewline(): v /** * @test */ - public function createPrettyReturnsInstanceWithSpaceAfterRuleNameSetSpace(): void + public function createPrettyReturnsInstanceWithSpaceAfterRuleNameSetToSpace(): void { $newInstance = OutputFormat::createPretty(); From ede4dd742b09e94ecaa47af60b401495d0692e6a Mon Sep 17 00:00:00 2001 From: Oliver Klee Date: Mon, 10 Feb 2025 10:00:37 +0100 Subject: [PATCH 3/3] Changes suggested in code review --- tests/Unit/OutputFormatTest.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/Unit/OutputFormatTest.php b/tests/Unit/OutputFormatTest.php index bc0e99bb..2b60b52c 100644 --- a/tests/Unit/OutputFormatTest.php +++ b/tests/Unit/OutputFormatTest.php @@ -891,7 +891,7 @@ public function getFormatterCalledTwoTimesReturnsSameInstance(): void /** * @test */ - public function createReturnsNewOutputFormatInstance(): void + public function createReturnsOutputFormatInstance(): void { self::assertInstanceOf(OutputFormat::class, OutputFormat::create()); } @@ -910,7 +910,7 @@ public function createCalledTwoTimesReturnsDifferentInstances(): void /** * @test */ - public function createCompactReturnsNewOutputFormatInstance(): void + public function createCompactReturnsOutputFormatInstance(): void { self::assertInstanceOf(OutputFormat::class, OutputFormat::createCompact()); } @@ -1039,7 +1039,7 @@ public function createCompactReturnsInstanceWithRenderCommentsDisabled(): void /** * @test */ - public function createPrettyReturnsNewOutputFormatInstance(): void + public function createPrettyReturnsOutputFormatInstance(): void { self::assertInstanceOf(OutputFormat::class, OutputFormat::createPretty()); } @@ -1148,7 +1148,7 @@ public function createPrettyReturnsInstanceWithSpaceAfterSelectorSeparatorSetToS /** * @test */ - public function createPrettyReturnsInstanceWithSpaceAfterListArgumentSeparatorsSetToSpaceForComma(): void + public function createPrettyReturnsInstanceWithSpaceAfterListArgumentSeparatorsSetToSpaceForCommaOnly(): void { $newInstance = OutputFormat::createPretty();