Skip to content

Commit 1f12856

Browse files
committed
Add toInt() and toFloat() implementation to Undefined type
1 parent 0f4b45f commit 1f12856

File tree

3 files changed

+23
-1
lines changed

3 files changed

+23
-1
lines changed

src/Usage/Integer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
testPositiveInt(IntegerPositive::fromInt(10)->value());
2121
testNonNegativeInt(IntegerNonNegative::fromInt(10)->value());
2222
testWeekDayInt(IntegerWeekDay::fromInt(7)->value());
23-
echo WeekDay::fromInt(7)->value() . PHP_EOL;
23+
echo WeekDay::fromInt(7)->value() . \PHP_EOL;
2424

2525
// DB tinyint usage
2626
echo Tiny::fromInt(-5)->toString() . \PHP_EOL;

src/Usage/Undefined.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,16 @@
1616
} catch (UndefinedTypeException $e) {
1717
// suppress
1818
}
19+
try {
20+
UndefinedStandard::create()->toInt();
21+
} catch (UndefinedTypeException $e) {
22+
// suppress
23+
}
24+
try {
25+
UndefinedStandard::create()->toFloat();
26+
} catch (UndefinedTypeException $e) {
27+
// suppress
28+
}
1929
try {
2030
NotExist::create()->value();
2131
} catch (UndefinedTypeException $e) {

tests/Unit/Undefined/UndefinedStandardTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,18 @@
1616
->toThrow(UndefinedTypeException::class, 'Undefined type cannot be converted to string.');
1717
});
1818

19+
it('throws on toInt for UndefinedStandard', function (): void {
20+
$u = UndefinedStandard::create();
21+
expect(fn() => $u->toInt())
22+
->toThrow(UndefinedTypeException::class, 'Undefined type cannot be converted to integer.');
23+
});
24+
25+
it('throws on toFloat for UndefinedStandard', function (): void {
26+
$u = UndefinedStandard::create();
27+
expect(fn() => $u->toFloat())
28+
->toThrow(UndefinedTypeException::class, 'Undefined type cannot be converted to float.');
29+
});
30+
1931
it('throws on value for UndefinedStandard', function (): void {
2032
$u = UndefinedStandard::create();
2133
expect(fn() => $u->value())

0 commit comments

Comments
 (0)