Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closure Based Rules Doesn't Pass Unit Validation Test #29

Open
JeffreyDavidson opened this issue Sep 7, 2021 · 1 comment
Open

Closure Based Rules Doesn't Pass Unit Validation Test #29

JeffreyDavidson opened this issue Sep 7, 2021 · 1 comment

Comments

@JeffreyDavidson
Copy link

JeffreyDavidson commented Sep 7, 2021

Currently I have a test that doesn't pass because of the Rule class having a closure attached to the rule. I'm seeing this happen with Rule::requiredIf but could also be seeing this using the new Rule::when() but that's just newly introduced to the Laravel framework. Has anyone come across this unexpected situation?

'started_at' => [
    Rule::requiredIf(function () {
        return  ! $this->route('user')->isUnactivated();
    }),
]

Running the following test gives me the following result.

/**
   * @test
    */
   public function rules_returns_validation_requirements()
   {
       $subject = $this->createFormRequest(UpdateRequest::class);

       $rules = $subject->rules();

       $this->assertValidationRules([
           'started_at' => ['nullable', 'string', 'date'],
       ], $rules);

       $this->assertValidationRuleContains($rules['started_at'], RequiredIf::class);
   }
array (
       0 => 'nullable',
  -    1 => 'string',
  -    2 => 'date',
  +    1 => 
  +    Illuminate\Validation\Rules\RequiredIf::__set_state(array(
  +       'condition' => 
  +      Closure::__set_state(array(
  +      )),
  +    )),
  +    2 => 'string',
       3 => 'date',
@julianphp
Copy link

+1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants