diff --git a/tests/IntRangeTest.php b/tests/IntRangeTest.php index 1f78215..9c13964 100644 --- a/tests/IntRangeTest.php +++ b/tests/IntRangeTest.php @@ -7,7 +7,7 @@ final class IntRangeTest extends TestCase { - public function testSerializeThrowsIfNotAnInt(): void + public function testSerializeThrowsIfString(): void { $this->expectException(\InvalidArgumentException::class); $this->expectExceptionMessage('Value not in range 1-12: "12".'); @@ -15,7 +15,15 @@ public function testSerializeThrowsIfNotAnInt(): void (new UpToADozen())->serialize('12'); } - public function testSerializeThrowsIfInvalid(): void + public function testSerializeThrowsIfFloat(): void + { + $this->expectException(\InvalidArgumentException::class); + $this->expectExceptionMessage('Value not in range 1-12: 5.43.'); + + (new UpToADozen())->serialize(5.43); + } + + public function testSerializeThrowsIfTooHigh(): void { $this->expectException(\InvalidArgumentException::class); $this->expectExceptionMessage('Value not in range 1-12: 13.'); @@ -23,14 +31,39 @@ public function testSerializeThrowsIfInvalid(): void (new UpToADozen())->serialize(13); } - public function testSerializePassesWhenValid(): void + public function testSerializeThrowsIfZero(): void { - $serializedResult = (new UpToADozen())->serialize(12); + $this->expectException(\InvalidArgumentException::class); + $this->expectExceptionMessage('Value not in range 1-12: 0.'); - self::assertSame(12, $serializedResult); + (new UpToADozen())->serialize(0); } - public function testParseValueThrowsIfInvalid(): void + public function testSerializeThrowsIfTooLow(): void + { + $this->expectException(\InvalidArgumentException::class); + $this->expectExceptionMessage('Value not in range 1-12: -1.'); + + (new UpToADozen())->serialize(-1); + } + + public function testSerializePassesWithHighest(): void + { + self::assertSame( + 12, + (new UpToADozen())->serialize(12) + ); + } + + public function testSerializePassesWithLowest(): void + { + self::assertSame( + 1, + (new UpToADozen())->serialize(1) + ); + } + + public function testParseValueThrowsIfTooHigh(): void { $this->expectException(Error::class); $this->expectExceptionMessage('Value not in range 1-12: 13.'); @@ -38,11 +71,35 @@ public function testParseValueThrowsIfInvalid(): void (new UpToADozen())->parseValue(13); } - public function testParseValuePassesIfValid(): void + public function testParseValueThrowsIfZero(): void + { + $this->expectException(Error::class); + $this->expectExceptionMessage('Value not in range 1-12: 0.'); + + (new UpToADozen())->parseValue(0); + } + + public function testParseValueThrowsIfTooLow(): void + { + $this->expectException(Error::class); + $this->expectExceptionMessage('Value not in range 1-12: -1.'); + + (new UpToADozen())->parseValue(-1); + } + + public function testParseValuePassesWithHighest(): void { self::assertSame( 12, (new UpToADozen())->parseValue(12) ); } + + public function testParseValuePassesWithLowest(): void + { + self::assertSame( + 1, + (new UpToADozen())->parseValue(1) + ); + } }