首页 > 解决方案 > Pestphp 错误:调用未定义的函数 mock()

问题描述

文件害虫.php

<?php

use Illuminate\Foundation\Testing\RefreshDatabase;

uses(Tests\TestCase::class, RefreshDatabase::class)->in('Feature', 'Unit');

File Unit/Repositories/PersonalDataRepository

文件单元/存储库/PersonalDataRepositoryTest.php

<?php


use Tests\Helpers\Api\ResponseApi;
use App\Services\ExternalApi\BigBoost\PeopleService;
use App\Services\Repositories\PersonalDataRepository;

uses(ResponseApi::class);

test('should register data in the personal data table with the bigbooster api data ', 
function () {

$dataApi = $this->responseBigboostPeople();

$placeEmail = \App\Models\PlaceEmail::factory()->make();

$peopleService = mock(PeopleService::class);

$peopleService
    ->expects($this->once())
    ->method('make')
    ->willReturn($dataApi);

$personalDataRepository = new PersonalDataRepository();

$response = $personalDataRepository->create($placeEmail, $peopleService);

$this->assertEquals($placeEmail->email, $response->email);
$this->assertEquals('TESTE DA SILVA', $response->name);
$this->assertEquals('LEAO', $response->zodiac_sign);
$this->assertEquals('Mother user', $response->mother_name);
$this->assertEquals('Father user', $response->father_name);
$this->assertEquals('11111111111', $response->cpf);
$this->assertEquals('1991-08-04', $response->birth_date);
});

使用 $ this-> createMock 方法时出现错误,Member has protected access,因为没有扩展 TestCase 类

标签: phpphp-pest

解决方案


推荐阅读