This repository was archived by the owner on Dec 20, 2021. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +27
-1
lines changed
Expand file tree Collapse file tree 2 files changed +27
-1
lines changed Original file line number Diff line number Diff line change @@ -257,7 +257,7 @@ public function setDateFormat($dateFormat)
257257 public function assertValue ($ value )
258258 {
259259 // required?
260- if (empty ($ value )) {
260+ if (! $ this -> hasValue ($ value )) {
261261 if ($ this ->getRequired ()) {
262262 $ this ->throwInvalidParameter ($ this ->getName ().' is required ' );
263263 }
@@ -361,4 +361,20 @@ protected function throwInvalidParameter($message)
361361 new Error ($ message , 'parameter-invalid ' ),
362362 ]);
363363 }
364+
365+ /**
366+ * @param mixed $value
367+ */
368+ private function hasValue ($ value ): bool
369+ {
370+ return !empty ($ value ) || $ this ->isBooleanWithValueFalse ($ value );
371+ }
372+
373+ /**
374+ * @param mixed $value
375+ */
376+ private function isBooleanWithValueFalse ($ value ): bool
377+ {
378+ return $ this ->getType () === self ::TYPE_BOOLEAN && is_bool ($ value ) && $ value === false ;
379+ }
364380}
Original file line number Diff line number Diff line change @@ -250,4 +250,14 @@ function () {
250250 ->isInstanceOf ('\RuntimeException ' )
251251 ;
252252 }
253+
254+ public function testAssertValueOnMandatoryFalseBoolean ()
255+ {
256+ $ this ->newTestedInstance ('name ' , 'boolean ' , true );
257+ $ this
258+ ->given ($ this ->testedInstance )
259+ ->variable ($ this ->testedInstance ->assertValue (false ))
260+ ->isNull
261+ ;
262+ }
253263}
You can’t perform that action at this time.
0 commit comments