1

For testing, I want to use the validator method to validate the size and minimum size of this passwordsArray:

    array:9 [
      0 => "password 0"
      1 => "password 1"
      2 => "password 2"
      3 => "password 3"
      4 => "password 4"
      5 => "password 5"
    ]

I'm trying something like:

$validator = Validator::make($passwordsArray, [
            'passwordsArray' => 'required|min:6',
        ]);

        if( $validator->passes() ){
            $this->assertTrue(true);

        }else{

            $this->assertTrue(false);
        }

I'm getting this error:

Failed asserting that false is true.

Help is appreciated, thanks :)

1

1 Answer 1

0

Your $passwordsArray needs to have an element named passwordsArray which unless you've omitted from your example, it does not appear to have.

$passwordsArray= [
    'passwordsArray' => [
        'password 0',
        'password 1',
        'password 2',
        'password 3',
        'password 4',
        'password 5',
    ]
];

$validator = Validator::make($passwordsArray, [
    'passwordsArray' => ['required', 'min:6']
]);

if ($validator->fails()) {
    dd('Failed validation');
}

dd('Passed validation');

Working example here

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks for answering. My real case doesn't have that element, that's why I asked if existed a way to implement it without it
Do you have the option to alter the input array from you request object to add the element, or create a new array from the request array?
Yes, that's what i got to do. Create a new array $passwordsArray = ['passwordsArray' => $passwordsArray]. Then use your approach

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.