From 8cf8beba644c09a6b0710c15efd6856968c93258 Mon Sep 17 00:00:00 2001 From: Eddie Date: Fri, 6 Sep 2024 16:44:08 +0100 Subject: [PATCH] Adding numeric type. --- src/Models/Model.php | 2 ++ tests/_support/Helper/MockModel.php | 1 + tests/wpunit/ModelTest.php | 3 ++- 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Models/Model.php b/src/Models/Model.php index 1fb0285..f978d23 100644 --- a/src/Models/Model.php +++ b/src/Models/Model.php @@ -330,6 +330,8 @@ public function isPropertyTypeValid( string $key, $value ) : bool { return is_array( $value ); case 'float': return is_float( $value ); + case 'numeric': + return is_numeric( $value ); default: return $value instanceof $type; } diff --git a/tests/_support/Helper/MockModel.php b/tests/_support/Helper/MockModel.php index 37db8e4..e65234e 100644 --- a/tests/_support/Helper/MockModel.php +++ b/tests/_support/Helper/MockModel.php @@ -11,5 +11,6 @@ class MockModel extends Model { 'lastName' => 'string', 'emails' => [ 'array', [] ], 'microseconds' => 'float', + 'number' => 'numeric', ]; } diff --git a/tests/wpunit/ModelTest.php b/tests/wpunit/ModelTest.php index e6a5973..ba2ed62 100644 --- a/tests/wpunit/ModelTest.php +++ b/tests/wpunit/ModelTest.php @@ -306,7 +306,8 @@ public function invalidTypeProvider() { [ 'id', 'Not an integer' ], [ 'firstName', 100 ], [ 'emails', 'Not an array' ], - [ 'microseconds', 'Not a float' ] + [ 'microseconds', 'Not a float' ], + [ 'number', 'Not a number' ] ]; } }