Laravel-Model-Validation icon indicating copy to clipboard operation
Laravel-Model-Validation copied to clipboard

Model validation doesn't use custom Validator

Open felixkiss opened this issue 11 years ago • 0 comments

I have installed a package to extend Validator with additional validation rules (https://github.com/Intervention/validation).

My test looks like this:

public function testShouldBeInvalidWithoutValidCreditcardNumber()
{
    $payment = Factory::payment();
    $payment->creditcard = 'foo';

    Should::beInvalid($payment);
}

PHPUnit says:

3) PaymentTest::testShouldBeInvalidWithoutValidCreditcardNumber
    BadMethodCallException: Method [validateCreditcard] does not exist.

I setup a little test route to test if the Validator is correctly configured:

Route::get('validation', function()
{
    return View::make('test.validate1');
});

Route::post('validation', function()
{
    $input = Input::all();

    $rules = array(
        'foo' => 'required|creditcard',
    );

    $validator = Validator::make($input, $rules);

    if($validator->fails())
    {
        return Redirect::back()->withErrors($validator);
    }
    else
    {
        return Redirect::back()->with('success', 'Valid!');
    }
});

Using this, the method is recognized correctly and it behaves like expected. Is it possible, that I have to configure something else for this to work in the test as well? Any help would be appreciated.

felixkiss avatar Jun 05 '13 15:06 felixkiss