diff --git a/src/Models/Model.php b/src/Models/Model.php index 5ddc042..d3ba731 100644 --- a/src/Models/Model.php +++ b/src/Models/Model.php @@ -328,6 +328,10 @@ public function isPropertyTypeValid( string $key, $value ) : bool { return is_bool( $value ); case 'array': return is_array( $value ); + case 'float': + return is_float( $value ); + case 'number': + return is_int( $value ) || is_float( $value ); default: return $value instanceof $type; } diff --git a/tests/_support/Helper/MockModel.php b/tests/_support/Helper/MockModel.php index 334706b..8508191 100644 --- a/tests/_support/Helper/MockModel.php +++ b/tests/_support/Helper/MockModel.php @@ -6,9 +6,11 @@ class MockModel extends Model { protected $properties = [ - 'id' => 'int', - 'firstName' => [ 'string', 'Michael' ], - 'lastName' => 'string', - 'emails' => [ 'array', [] ], + 'id' => 'int', + 'firstName' => [ 'string', 'Michael' ], + 'lastName' => 'string', + 'emails' => [ 'array', [] ], + 'microseconds' => 'float', + 'number' => 'number', ]; } diff --git a/tests/wpunit/ModelTest.php b/tests/wpunit/ModelTest.php index 1adf2e4..aab6a85 100644 --- a/tests/wpunit/ModelTest.php +++ b/tests/wpunit/ModelTest.php @@ -306,6 +306,8 @@ public function invalidTypeProvider() { [ 'id', 'Not an integer' ], [ 'firstName', 100 ], [ 'emails', 'Not an array' ], + [ 'microseconds', 'Not a float' ], + [ 'number', '12' ] // numeric strings do not work; must be int or float ]; } }