Skip to content

Commit 19fc5b2

Browse files
[12.x] Introducing Rules\Password::appliedRules Method (#55206)
* introducing the method * introducing basic tests and rewriting the docblock * Update Password.php --------- Co-authored-by: Taylor Otwell <[email protected]>
1 parent c74e7e3 commit 19fc5b2

File tree

2 files changed

+56
-0
lines changed

2 files changed

+56
-0
lines changed

src/Illuminate/Validation/Rules/Password.php

+20
Original file line numberDiff line numberDiff line change
@@ -379,4 +379,24 @@ protected function fail($messages)
379379

380380
return false;
381381
}
382+
383+
/**
384+
* Get information about the current state of the password validation rules.
385+
*
386+
* @return array
387+
*/
388+
public function appliedRules()
389+
{
390+
return [
391+
'min' => $this->min,
392+
'max' => $this->max,
393+
'mixedCase' => $this->mixedCase,
394+
'letters' => $this->letters,
395+
'numbers' => $this->numbers,
396+
'symbols' => $this->symbols,
397+
'uncompromised' => $this->uncompromised,
398+
'compromisedThreshold' => $this->compromisedThreshold,
399+
'customRules' => $this->customRules,
400+
];
401+
}
382402
}

tests/Validation/ValidationPasswordRuleTest.php

+36
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,42 @@ public function message()
339339
]);
340340
}
341341

342+
public function testCanRetrieveAllRulesApplied()
343+
{
344+
$password = Password::min(2)
345+
->max(4)
346+
->mixedCase()
347+
->numbers()
348+
->letters()
349+
->symbols();
350+
351+
$this->assertSame($password->appliedRules(), [
352+
'min' => 2,
353+
'max' => 4,
354+
'mixedCase' => true,
355+
'letters' => true,
356+
'numbers' => true,
357+
'symbols' => true,
358+
'uncompromised' => false,
359+
'compromisedThreshold' => 0,
360+
'customRules' => [],
361+
]);
362+
363+
$password = Password::min(2);
364+
365+
$this->assertSame($password->appliedRules(), [
366+
'min' => 2,
367+
'max' => null,
368+
'mixedCase' => false,
369+
'letters' => false,
370+
'numbers' => false,
371+
'symbols' => false,
372+
'uncompromised' => false,
373+
'compromisedThreshold' => 0,
374+
'customRules' => [],
375+
]);
376+
}
377+
342378
protected function passes($rule, $values)
343379
{
344380
$this->assertValidationRules($rule, $values, true, []);

0 commit comments

Comments
 (0)