Skip to content

Commit

Permalink
Test IntRange extensively
Browse files Browse the repository at this point in the history
  • Loading branch information
spawnia committed Sep 24, 2024
1 parent c2a38af commit 080b5a2
Showing 1 changed file with 64 additions and 7 deletions.
71 changes: 64 additions & 7 deletions tests/IntRangeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,42 +7,99 @@

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".');

(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.');

(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.');

(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)
);
}
}

0 comments on commit 080b5a2

Please sign in to comment.