#Mocking Custom Rule

1 messages · Page 1 of 1 (latest)

cyan hollow
#

Does anyone know how you would mock a custom validation rule with L10? I know the validate method doesn't return true/false like the L9 passes() method did so I'm trying to mock $fails argument is called. This is what I currently have. I think this is close to what I need BUT I need to make sure I'm able to set the attribute correctly however I'm not sure how to do so with this.

        ->shouldReceive('validate')
        ->withArgs(function (string $attribute, $value, $closure) {
            $closure();
        });```
cyan hollow
#

I've also tried the following but I don't think it is invoking that closure.

    $closure();
    return;
});

->with('myAttribute', 1, function ($closure) {
    return $closure();
});```
fiery dragon
#

What’s your entire test method look like ?

raw ruin
#

Does your rule call some external service? Why are you mocking it

fiery dragon
#

Yeah don’t see why you can’t just test the rule normally

cyan hollow
#

Wanted to report his problem has been solved.