|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +namespace Sabberworm\CSS\Tests\Unit\Comment; |
| 6 | + |
| 7 | +use PHPUnit\Framework\TestCase; |
| 8 | +use Sabberworm\CSS\Comment\Comment; |
| 9 | +use Sabberworm\CSS\OutputFormat; |
| 10 | +use Sabberworm\CSS\Renderable; |
| 11 | + |
| 12 | +/** |
| 13 | + * @covers \Sabberworm\CSS\Comment\Comment |
| 14 | + */ |
| 15 | +final class CommentTest extends TestCase |
| 16 | +{ |
| 17 | + /** |
| 18 | + * @test |
| 19 | + */ |
| 20 | + public function implementsRenderable(): void |
| 21 | + { |
| 22 | + $subject = new Comment(); |
| 23 | + |
| 24 | + self::assertInstanceOf(Renderable::class, $subject); |
| 25 | + } |
| 26 | + |
| 27 | + /** |
| 28 | + * @test |
| 29 | + */ |
| 30 | + public function getCommentOnEmptyInstanceReturnsEmptyString(): void |
| 31 | + { |
| 32 | + $subject = new Comment(); |
| 33 | + |
| 34 | + self::assertSame('', $subject->getComment()); |
| 35 | + } |
| 36 | + |
| 37 | + /** |
| 38 | + * @test |
| 39 | + */ |
| 40 | + public function getCommentInitiallyReturnsCommentPassedToConstructor(): void |
| 41 | + { |
| 42 | + $comment = 'There is no spoon.'; |
| 43 | + $subject = new Comment($comment); |
| 44 | + |
| 45 | + self::assertSame($comment, $subject->getComment()); |
| 46 | + } |
| 47 | + |
| 48 | + /** |
| 49 | + * @test |
| 50 | + */ |
| 51 | + public function setCommentSetsComments(): void |
| 52 | + { |
| 53 | + $comment = 'There is no spoon.'; |
| 54 | + $subject = new Comment(); |
| 55 | + |
| 56 | + $subject->setComment($comment); |
| 57 | + |
| 58 | + self::assertSame($comment, $subject->getComment()); |
| 59 | + } |
| 60 | + |
| 61 | + /** |
| 62 | + * @test |
| 63 | + */ |
| 64 | + public function getLineNoOnEmptyInstanceReturnsZero(): void |
| 65 | + { |
| 66 | + $subject = new Comment(); |
| 67 | + |
| 68 | + self::assertSame(0, $subject->getLineNo()); |
| 69 | + } |
| 70 | + |
| 71 | + /** |
| 72 | + * @test |
| 73 | + */ |
| 74 | + public function getLineNoInitiallyReturnsLineNumberPassedToConstructor(): void |
| 75 | + { |
| 76 | + $lineNumber = 42; |
| 77 | + $subject = new Comment('', $lineNumber); |
| 78 | + |
| 79 | + self::assertSame($lineNumber, $subject->getLineNo()); |
| 80 | + } |
| 81 | + |
| 82 | + /** |
| 83 | + * @test |
| 84 | + */ |
| 85 | + public function toStringRendersCommentEnclosedInCommentDelimiters(): void |
| 86 | + { |
| 87 | + $comment = 'There is no spoon.'; |
| 88 | + $subject = new Comment(); |
| 89 | + |
| 90 | + $subject->setComment($comment); |
| 91 | + |
| 92 | + self::assertSame('/*' . $comment . '*/', (string) $subject); |
| 93 | + } |
| 94 | + |
| 95 | + /** |
| 96 | + * @test |
| 97 | + */ |
| 98 | + public function renderRendersCommentEnclosedInCommentDelimiters(): void |
| 99 | + { |
| 100 | + $comment = 'There is no spoon.'; |
| 101 | + $subject = new Comment(); |
| 102 | + |
| 103 | + $subject->setComment($comment); |
| 104 | + |
| 105 | + self::assertSame('/*' . $comment . '*/', $subject->render(new OutputFormat())); |
| 106 | + } |
| 107 | +} |
0 commit comments