From 0c49286a57d8d2a2d914d0c88b37e6e68d7bc995 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mario=20Sim=C3=A3o?= Date: Wed, 20 Oct 2021 17:48:40 -0300 Subject: [PATCH] Add annotations unit tests --- src/Common/Annotations.php | 2 + tests/Unit/Common/AnnotationsTest.php | 69 +++++++++++++++++++++++++++ 2 files changed, 71 insertions(+) create mode 100644 tests/Unit/Common/AnnotationsTest.php 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"); + } +}