This repository was archived by the owner on Jan 30, 2020. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +13
-2
lines changed Expand file tree Collapse file tree 2 files changed +13
-2
lines changed Original file line number Diff line number Diff line change @@ -73,15 +73,19 @@ public function extract($value)
73
73
/**
74
74
* Converts the given value so that it can be hydrated by the hydrator.
75
75
*
76
- * @param int|string $value The original value.
76
+ * @param bool| int|string $value The original value.
77
77
* @throws InvalidArgumentException
78
78
* @return bool Returns the value that should be hydrated.
79
79
*/
80
80
public function hydrate ($ value )
81
81
{
82
+ if (is_bool ($ value )) {
83
+ return $ value ;
84
+ }
85
+
82
86
if (!is_string ($ value ) && !is_int ($ value )) {
83
87
throw new InvalidArgumentException (sprintf (
84
- 'Unable to hydrate. Expected string or int. %s was given. ' ,
88
+ 'Unable to hydrate. Expected bool, string or int. %s was given. ' ,
85
89
is_object ($ value ) ? get_class ($ value ) : gettype ($ value )
86
90
));
87
91
}
Original file line number Diff line number Diff line change @@ -86,6 +86,13 @@ public function testHydrateInteger()
86
86
$ this ->assertEquals (false , $ hydrator ->hydrate (0 ));
87
87
}
88
88
89
+ public function testHydrateBool ()
90
+ {
91
+ $ hydrator = new BooleanStrategy (1 , 0 );
92
+ $ this ->assertEquals (true , $ hydrator ->hydrate (true ));
93
+ $ this ->assertEquals (false , $ hydrator ->hydrate (false ));
94
+ }
95
+
89
96
public function testHydrateUnexpectedValueThrowsException ()
90
97
{
91
98
$ this ->setExpectedException ('Zend\Hydrator\Exception\InvalidArgumentException ' , 'Unexpected value ' );
You can’t perform that action at this time.
0 commit comments