diff --git a/src/Common/Annotations.php b/src/Common/Annotations.php index 8cbd2f85..3dc87dd9 100644 --- a/src/Common/Annotations.php +++ b/src/Common/Annotations.php @@ -173,6 +173,8 @@ public function code(bool $code = true): self public function withColor(string $color): self { + $this->checkColor($color); + return new self( $this->bold, $this->italic, diff --git a/tests/Unit/Common/AnnotationsTest.php b/tests/Unit/Common/AnnotationsTest.php new file mode 100644 index 00000000..4c8d0396 --- /dev/null +++ b/tests/Unit/Common/AnnotationsTest.php @@ -0,0 +1,69 @@ +assertFalse($annotations->isBold()); + $this->assertFalse($annotations->isItalic()); + $this->assertFalse($annotations->isStrikeThrough()); + $this->assertFalse($annotations->isUnderline()); + $this->assertFalse($annotations->isCode()); + $this->assertEquals("default", $annotations->color()); + } + + public function test_bold(): void + { + $annotations = Annotations::create()->bold(); + + $this->assertTrue($annotations->isBold()); + } + + public function test_italic(): void + { + $annotations = Annotations::create()->italic(); + + $this->assertTrue($annotations->isItalic()); + } + + public function test_strike_through(): void + { + $annotations = Annotations::create()->strikeThrough(); + + $this->assertTrue($annotations->isStrikeThrough()); + } + + public function test_underline(): void + { + $annotations = Annotations::create()->underline(); + + $this->assertTrue($annotations->isUnderline()); + } + + public function test_code(): void + { + $annotations = Annotations::create()->code(); + + $this->assertTrue($annotations->isCode()); + } + + public function test_change_color(): void + { + $annotations = Annotations::create()->withColor("red"); + + $this->assertEquals("red", $annotations->color()); + } + + public function test_change_unsupported_color(): void + { + $this->expectException(\Exception::class); + Annotations::create()->withColor("not-a-color"); + } +}