From 4986743f89a5585a7bbdf727d3a96dda199bbdb2 Mon Sep 17 00:00:00 2001 From: Oliver Klee Date: Sun, 31 Jul 2022 14:22:45 +0200 Subject: [PATCH] Add more detailed unit tests for `Comment` Signed-off-by: Oliver Klee --- tests/Comment/CommentTest.php | 93 +++++++++++++++++++++++++++++++++++ 1 file changed, 93 insertions(+) diff --git a/tests/Comment/CommentTest.php b/tests/Comment/CommentTest.php index 14a0b240..29385f01 100644 --- a/tests/Comment/CommentTest.php +++ b/tests/Comment/CommentTest.php @@ -3,7 +3,9 @@ namespace Sabberworm\CSS\Tests\Comment; use PHPUnit\Framework\TestCase; +use Sabberworm\CSS\Comment\Comment; use Sabberworm\CSS\OutputFormat; +use Sabberworm\CSS\Renderable; use Sabberworm\CSS\Tests\ParserTest as TestsParserTest; /** @@ -14,6 +16,97 @@ */ class CommentTest extends TestCase { + /** + * @test + */ + public function implementsRenderable() + { + $subject = new Comment(); + + self::assertInstanceOf(Renderable::class, $subject); + } + + /** + * @test + */ + public function getCommentOnEmptyInstanceReturnsReturnsEmptyString() + { + $subject = new Comment(); + + self::assertSame('', $subject->getComment()); + } + + /** + * @test + */ + public function getCommentInitiallyReturnsCommentPassedToConstructor() + { + $comment = 'There is no spoon.'; + $subject = new Comment($comment); + + self::assertSame($comment, $subject->getComment()); + } + + /** + * @test + */ + public function setCommentSetsComments() + { + $comment = 'There is no spoon.'; + $subject = new Comment(); + + $subject->setComment($comment); + + self::assertSame($comment, $subject->getComment()); + } + + /** + * @test + */ + public function getLineNoOnEmptyInstanceReturnsReturnsZero() + { + $subject = new Comment(); + + self::assertSame(0, $subject->getLineNo()); + } + + /** + * @test + */ + public function getLineNoInitiallyReturnsLineNumberPassedToConstructor() + { + $lineNumber = 42; + $subject = new Comment('', $lineNumber); + + self::assertSame($lineNumber, $subject->getLineNo()); + } + + /** + * @test + */ + public function toStringRendersCommentEnclosedInCommentDelimiters() + { + $comment = 'There is no spoon.'; + $subject = new Comment(); + + $subject->setComment($comment); + + self::assertSame('/*' . $comment . '*/', (string)$subject); + } + + /** + * @test + */ + public function renderRendersCommentEnclosedInCommentDelimiters() + { + $comment = 'There is no spoon.'; + $subject = new Comment(); + + $subject->setComment($comment); + + self::assertSame('/*' . $comment . '*/', $subject->render(new OutputFormat())); + } + /** * @test */