Skip to content

Commit

Permalink
Merge pull request #12 from stellarwp/feat/float-datetime
Browse files Browse the repository at this point in the history
Adding float as valid type.
  • Loading branch information
stratease authored Sep 9, 2024
2 parents 7c21d23 + 478549e commit 6d0d833
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
4 changes: 4 additions & 0 deletions src/Models/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
10 changes: 6 additions & 4 deletions tests/_support/Helper/MockModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
];
}
2 changes: 2 additions & 0 deletions tests/wpunit/ModelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
];
}
}

0 comments on commit 6d0d833

Please sign in to comment.