Skip to content

Commit fd25420

Browse files
committed
Add unit tests for Assert class methods
- Introduced tests for `greaterThanEq`, `lessThanEq`, and `integerish` methods. - Validated exception throwing with default and custom messages. - Ensured correct behavior for valid inputs across scenarios.
1 parent 2514614 commit fd25420

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use PhpTypedValues\Code\Assert\Assert;
6+
use PhpTypedValues\Code\Exception\TypeException;
7+
8+
it('greaterThanEq throws with default message when empty', function (): void {
9+
expect(fn() => Assert::greaterThanEq(0, 1, ''))
10+
->toThrow(TypeException::class, 'Expected a value greater than or equal to the minimum');
11+
});
12+
13+
it('greaterThanEq throws with custom message when provided', function (): void {
14+
expect(fn() => Assert::greaterThanEq(0, 1, 'custom gt= message'))
15+
->toThrow(TypeException::class, 'custom gt= message');
16+
});
17+
18+
it('greaterThanEq does not throw when valid', function (): void {
19+
Assert::greaterThanEq(1, 1, '');
20+
Assert::greaterThanEq(2, 1, 'anything');
21+
expect(true)->toBeTrue();
22+
});
23+
24+
it('lessThanEq throws with default message when empty', function (): void {
25+
expect(fn() => Assert::lessThanEq(2, 1, ''))
26+
->toThrow(TypeException::class, 'Expected a value less than or equal to the maximum');
27+
});
28+
29+
it('lessThanEq throws with custom message when provided', function (): void {
30+
expect(fn() => Assert::lessThanEq(3, 1, 'custom lt= message'))
31+
->toThrow(TypeException::class, 'custom lt= message');
32+
});
33+
34+
it('lessThanEq does not throw when valid', function (): void {
35+
Assert::lessThanEq(1, 1, '');
36+
Assert::lessThanEq(1, 2, 'anything');
37+
expect(true)->toBeTrue();
38+
});
39+
40+
it('integerish throws with default message when empty', function (): void {
41+
expect(fn() => Assert::integerish('5.5', ''))
42+
->toThrow(TypeException::class, 'Expected an "integerish" value');
43+
});
44+
45+
it('integerish throws with custom message when provided', function (): void {
46+
expect(fn() => Assert::integerish('foo', 'custom integerish message'))
47+
->toThrow(TypeException::class, 'custom integerish message');
48+
});
49+
50+
it('integerish does not throw for integerish values', function (): void {
51+
Assert::integerish('5', '');
52+
Assert::integerish('5.0', '');
53+
Assert::integerish(5, '');
54+
expect(true)->toBeTrue();
55+
});

0 commit comments

Comments
 (0)