anhskohbo / no-captcha

No CAPTCHA reCAPTCHA For Laravel.
https://packagist.org/packages/anhskohbo/no-captcha
MIT License
1.77k stars 234 forks source link

Unit Test Error: Class 'Tests\Feature\NoCaptcha' not found #120

Closed alexvargash closed 5 years ago

alexvargash commented 5 years ago

Hello! I'm having an issue when trying to create a test for an account creation that has the captcha.

RegisterTest.php

namespace Tests\Feature;

use Tests\TestCase;
use Illuminate\Foundation\Testing\DatabaseTransactions;

class RegisterTest extends TestCase
{
    use DatabaseTransactions;

    public function testBasicTest()
    {
        NoCaptcha::shouldReceive('verifyResponse')->once()->andReturn(true);

        $response = $this->json(
            'POST', '/register', [
                'account_name'          => 'Digizent',
                'street'                => 'New Hollow Drive',
                'suite'                 => '1234',
                'city'                  => 'Carrolton',
                'state'                 => 'TX',
                'zip_code'              => '131-666-5252',
                'name'                  => 'John',
                'lastname'              => 'Doe',
                'email'                 => 'test@domain.com',
                'password'              => 'password123',
                'password_confirmation' => 'password123',
                'recaptcha'             => '1',
                'privacy_and_terms'     => true
            ]);

        $response->assertStatus(201);
    }
}

I have a Form Request.

StoreAccount.php

namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;

class StoreAccount extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        return [
            'account_name'          => 'required|max:100',
            'street'                => 'required|max:100',
            'suite'                 => 'required|max:20',
            'city'                  => 'required|max:50',
            'state'                 => 'required|max:2',
            'zip_code'              => 'required|alpha_dash|max:10',
            'name'                  => 'required|max:50',
            'lastname'              => 'required|max:50',
            'email'                 => 'required|email|max:100|unique:users,email',
            'password'              => 'required|nullable|between:8,30|confirmed',
            'password_confirmation' => 'required',
            'recaptcha'             => 'required|captcha',
            'privacy_and_terms'     => 'required|accepted',
        ];
    }
}

When I run in my console vendor/bin/phpunit I have the following error.

PHPUnit 7.3.1 by Sebastian Bergmann and contributors.

E                                                                   1 / 1 (100%)

Time: 4.67 seconds, Memory: 12.00MB

There was 1 error:

1) Tests\Feature\RegisterTest::testBasicTest
Error: Class 'Tests\Feature\NoCaptcha' not found

/Users/Digizent/Documents/Code/flexformz/tests/Feature/RegisterTest.php:19

ERRORS!
Tests: 1, Assertions: 0, Errors: 1.

I have installed the latest version of the package and I added the Facade to the config\app.php, I'm using Laravel 5.6.

I'm I missing something or do I need to change the code?

Thank you for your help. LLAP 🖖

anhskohbo commented 5 years ago

Import NoCaptcha first or use \NoCaptcha instead NoCaptcha.