Accessing FormRequest values during testing

Posted 4 months ago by longestdrive

Hi I’m trying to test the effectiveness of a rule within a form request.

The rule is:


‘date’ => [
    Rule::unique('orders')->where(function ($query)  {
            return $query->where('user_id', $this->user_id)
            ->where('order_id', $this->order_id);
        }),
];

And I’m trying to test this using this test:

attributes = [
    'date' => '2019-02-16',
    ‘user_id’ =>1,
    ‘order_id’=>1
];
$request = new TestRequest();
$rules = $request->rules();
$validator = Validator::make($attributes, $rules);
$fails = $validator->fails();
$this->assertEquals(false, $fails);

The problem I’m having is that the values that would normally appear to be in the `FormReque are all null.

I’m trying to avoid using a call to the URL and post a form and test this in isolation.

How should I access the values within the formrequest to make this work?

Thanks

Please sign in or create an account to participate in this conversation.