mardi 3 septembre 2019

Method does not exist when mocking using overload

I am getting this error while trying to mock Vimeo ( a vendor package ) by using overload keyword:

Mockery\Exception\BadMethodCallException: Method Vimeo\Vimeo::request() does not exist on this mock object

I am following the docs on how to use overload:

use Vimeo\Vimeo;

class VimeoService
{
    private $client;

    public function __construct()
    {
        $config = config('vimeo');

        $this->client = new Vimeo(
            $config['client_id'],
            $config['client_secret'],
            $config['access_token']
        );
    }

    public function upload()
    {
        return $this->client->request('/me/videos', 'POST');
    }
}

The test

use Mockery;
use Vimeo\Vimeo;
use Tests\TestCase;
use App\Services\VimeoService;

class VimeoServiceTest extends TestCase
{
    /** @test */
    public function can_upload()
    {
        $externalMock = Mockery::mock('overload:'.Vimeo::class);
        $externalMock->shouldReceive('upload')->once()->andReturn(true);

        $service = new VimeoService();

        $this->assertTrue($service->upload());
    }
}

Aucun commentaire:

Enregistrer un commentaire