why shouldReceive method not recognize in Laravel unit test?

167 Views Asked by At

I need to test unit my service in Laravel app. When i writing this code:

<?php

namespace Tests\Unit;

use App\Http\Requests\LoginUserRequest;
use App\Models\User;
use App\Repositories\UserRepository;
use Mockery;
use Mockery\MockInterface;
use PHPUnit\Framework\TestCase;

class AuthServiceTest extends TestCase
{
    /**
     * A basic unit test example.
     */
    public function corretLoginUserTest(): void
    {
        $loginUserRequest = Mockery::mock(LoginUserRequest::class);
        $loginUserRequest->shouldReceive('input')->with('email')->andReturn('[email protected]');
        $loginUserRequest->shouldReceive('input')->with('password')->andReturn('kowal12@');

        $user = new User();
        $userRepository = Mockery::mock(UserRepository::class);
        $userRepository->shouldReceive('findByEmail')->once()->with('[email protected]')->andReturn($user);
        $userRepository->shouldReceive('comparePassword')->with('password123', $user)->andReturn(true);
        $userRepository->shouldReceive('createToken')->with($user)->andReturn($user->createToken('token')->plainTextToken);
    }
}

I have errors, because my Visual Studio Code tell me in words shouldReceinve below line $user = new User()

Undefined method 'shouldReceive'.intelephense(1013)
<?php
public function shouldReceive(...$methodNames);
Set expected method calls

How i can solve this problem. Please help me, because I need to test my service.

0

There are 0 best solutions below