Skip to content

Commit 74392fa

Browse files
authored
Merge pull request #12 from emulgeator/float-cast-fix
Fixing float casting
2 parents b859347 + fd02c10 commit 74392fa

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-2
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](http://keepachangelog.com/)
66
and this project adheres to [Semantic Versioning](http://semver.org/).
77

8+
## [1.1.1] - 2024-04-12
9+
10+
### Fixed
11+
- Casting float properly
12+
13+
814
## [1.1.0] - 2024-04-08
915

1016
### Added

src/Mapper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ private function setValueByPhpType(\ReflectionNamedType $type, ?DocBlockType $do
146146
break;
147147

148148
case 'float':
149-
$value = Caster::castToInt($value);
149+
$value = Caster::castToFloat($value);
150150
break;
151151
}
152152
$property->setValue($object, $value);

test/Unit/MapperTest.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,12 +71,16 @@ public function testMapWhenKeyContainsSpecialCharacter_shouldSetByRemovingSpecia
7171
public function testMapWhenBuiltInTypedPropertyGiven_shouldCast()
7272
{
7373
$mapper = $this->getMapper();
74-
$input = ['int' => '1'];
74+
$input = [
75+
'int' => '1',
76+
'float' => '1.23',
77+
];
7578

7679
/** @var ScalarTypedStub $result */
7780
$result = $mapper->map($input, ScalarTypedStub::class);
7881

7982
$this->assertSame(1, $result->getInt());
83+
$this->assertSame(1.23, $result->getFloat());
8084
}
8185

8286
public function testMapWithBoolean_shouldCastProperly()

0 commit comments

Comments
 (0)