@@ -237,14 +237,14 @@ public function testItCanSetDefaultUsing()
237237
238238 $ this ->passes (Password::default (), ['abcd ' , '454qb^ ' , '接2133手田 ' ]);
239239 $ this ->assertSame ($ password , Password::default ());
240- $ this ->assertSame ([ ' required ' , $ password ] , Password::required ());
241- $ this ->assertSame ([ ' sometimes ' , $ password ] , Password::sometimes ());
240+ $ this ->assertInstanceOf (Password::class , Password::required ());
241+ $ this ->assertInstanceOf (Password::class , Password::sometimes ());
242242
243243 Password::defaults ($ password2 );
244244 $ this ->passes (Password::default (), ['Nn ' , 'Mn ' , 'âA ' ]);
245245 $ this ->assertSame ($ password2 , Password::default ());
246- $ this ->assertSame ([ ' required ' , $ password2 ] , Password::required ());
247- $ this ->assertSame ([ ' sometimes ' , $ password2 ] , Password::sometimes ());
246+ $ this ->assertInstanceOf (Password::class , Password::required ());
247+ $ this ->assertInstanceOf (Password::class , Password::sometimes ());
248248 }
249249
250250 public function testItCannotSetDefaultUsingGivenString ()
@@ -375,6 +375,74 @@ public function testCanRetrieveAllRulesApplied()
375375 ]);
376376 }
377377
378+ public function testRequired ()
379+ {
380+ $ this ->fails (Password::required (), [null ], [
381+ 'validation.required ' ,
382+ ]);
383+
384+ $ this ->passes (Password::required (), ['12345678 ' , 'password123 ' ]);
385+
386+ $ this ->fails ([Password::required ()], ['short ' ], [
387+ 'validation.min.string ' ,
388+ ]);
389+
390+ $ this ->passes (Password::required ()->mixedCase ()->numbers (), ['Password1 ' ]);
391+
392+ // Ensure it still correct when using array
393+ $ this ->passes ([Password::required ()], ['12345678 ' , 'password123 ' ]);
394+
395+ $ this ->fails ([Password::required ()], ['short ' ], [
396+ 'validation.min.string ' ,
397+ ]);
398+
399+ $ this ->passes (['string ' , Password::required ()], ['12345678 ' , 'password123 ' ]);
400+
401+ $ this ->passes ([Password::required ()->mixedCase ()->numbers ()], ['Password1 ' ]);
402+
403+ // Test with custom defaults
404+ Password::defaults (Password::min (6 )->letters ());
405+
406+ $ this ->fails (Password::required (), [null ], [
407+ 'validation.required ' ,
408+ ]);
409+
410+ $ this ->passes (Password::required (), ['Password123 ' , 'password123 ' ]);
411+ $ this ->passes ([Password::required ()], ['Password123 ' , 'password123 ' ]);
412+ }
413+
414+ public function testSometimes ()
415+ {
416+ $ this ->fails (Password::sometimes (), ['short ' ], [
417+ 'validation.min.string ' ,
418+ ]);
419+
420+ $ this ->passes (Password::sometimes (), ['12345678 ' , 'password123 ' ]);
421+
422+ $ this ->fails ([Password::sometimes ()], ['12345 ' ], [
423+ 'validation.min.string ' ,
424+ ]);
425+
426+ $ this ->passes (Password::sometimes ()->mixedCase ()->numbers (), ['Password1 ' ]);
427+
428+ // Ensure it still correct when using array
429+ $ this ->passes ([Password::sometimes ()], ['12345678 ' , 'password123 ' ]);
430+
431+ $ this ->fails ([Password::sometimes ()], ['12345 ' ], [
432+ 'validation.min.string ' ,
433+ ]);
434+
435+ $ this ->passes (['string ' , Password::sometimes ()], ['12345678 ' , 'password123 ' ]);
436+
437+ $ this ->passes ([Password::sometimes ()->mixedCase ()->numbers ()], ['Password1 ' ]);
438+
439+ // Test with custom defaults
440+ Password::defaults (Password::min (6 )->letters ());
441+
442+ $ this ->passes (Password::sometimes (), ['Password123 ' , 'password123 ' ]);
443+ $ this ->passes ([Password::sometimes ()], ['Password123 ' , 'password123 ' ]);
444+ }
445+
378446 protected function passes ($ rule , $ values )
379447 {
380448 $ this ->assertValidationRules ($ rule , $ values , true , []);
0 commit comments