Skip to content

Commit e91084a

Browse files
committed
Add @throws annotations and expand tests for integer assertions
- Added `@throws IntegerTypeException` annotations to methods in `BaseIntType` to document potential exceptions. - Expanded test cases to validate `assertGreaterThan` and `assertLessThan` methods for exclusive and inclusive bounds.
1 parent 52ab180 commit e91084a

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

src/BaseType/BaseIntType.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818
{
1919
protected int $value;
2020

21+
/**
22+
* @throws IntegerTypeException
23+
*/
2124
public function __construct(int $value)
2225
{
2326
$this->assert($value);
@@ -43,6 +46,9 @@ public static function fromString(string $value): self
4346
return new static((int) $value);
4447
}
4548

49+
/**
50+
* @throws IntegerTypeException
51+
*/
4652
#[Override]
4753
public static function fromInt(int $value): self
4854
{

tests/Unit/BaseType/BaseIntTypeTest.php

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,38 @@
2727
expect(fn() => Integer::fromString($str))->toThrow(IntegerTypeException::class);
2828
}
2929
});
30+
31+
it('assertGreaterThan works for exclusive and inclusive bounds', function (): void {
32+
$i = new Integer(0);
33+
34+
// exclusive (default): value must be strictly greater than limit
35+
$i->assertGreaterThan(6, 5); // pass
36+
$i->assertGreaterThan(5, 4); // pass
37+
38+
// failing exclusive cases
39+
expect(fn() => $i->assertGreaterThan(5, 5))->toThrow(IntegerTypeException::class); // equal should fail
40+
expect(fn() => $i->assertGreaterThan(4, 5))->toThrow(IntegerTypeException::class); // less should fail
41+
42+
// inclusive: value can be equal to limit
43+
$i->assertGreaterThan(5, 5, true); // pass
44+
45+
// failing inclusive case: value less than limit
46+
expect(fn() => $i->assertGreaterThan(4, 5, true))->toThrow(IntegerTypeException::class);
47+
});
48+
49+
it('assertLessThan works for exclusive and inclusive bounds', function (): void {
50+
$i = new Integer(0);
51+
52+
// exclusive (default): value must be strictly less than limit
53+
$i->assertLessThan(4, 5); // pass
54+
55+
// failing exclusive cases
56+
expect(fn() => $i->assertLessThan(5, 5))->toThrow(IntegerTypeException::class); // equal should fail
57+
expect(fn() => $i->assertLessThan(6, 5))->toThrow(IntegerTypeException::class); // greater should fail
58+
59+
// inclusive: value can be equal to limit
60+
$i->assertLessThan(5, 5, true); // pass
61+
62+
// failing inclusive case: value greater than limit
63+
expect(fn() => $i->assertLessThan(6, 5, true))->toThrow(IntegerTypeException::class);
64+
});

0 commit comments

Comments
 (0)