when i call the feature test i get the following error:Call to undefined method AppServicesTrelloCardService::_downloadCardsFromBoard().I don't understand the reason for the error
I wrote the following service:
namespace AppServices;
use AppServicesApiTrelloCardAPIService;
class TrelloCardService
{
protected $trelloCardApiService;
public function __construct(TrelloCardAPIService $trelloCardApiService)
{
$this->trelloCardApiService = $trelloCardApiService;
}
}
then a service that calls the API:
<?php
namespace AppServicesApi;
use AppTraitsCardTrait;
use UnirestRequest;
class TrelloCardAPIService
{
public function call(string $url) {
$headers = array('Accept' => 'application/json');
$query = array('key' => env('TRELLO_KEY'), 'token' => env('TRELLO_TOKEN'));
$r = Request::get($url, $headers, $query);
return $r->body;
}
public function _downloadCardsFromBoard() {
echo "API downloadCards!
";
$url = TRELLO_API_BASE_URL . "/boards/".TRELLO_BOARDS_SPRINT."/cards";
$res = $this->call($url);
return $res;
}
}
then I wrote the test feature:
namespace TestsFeature;
use AppServicesApiTrelloCardAPIService;
use AppServicesTrelloCardService;
use IlluminateFoundationTestingRefreshDatabase;
use IlluminateFoundationTestingWithFaker;
use IlluminateSupportFacadesFile;
use TestsTestCase;
class trelloCardTest extends TestCase
{
public function test_mock_card()
{
$cards = json_decode(File::get("tests/test_data/cards.json"),FALSE);
$mock = $this->mock(TrelloCardAPIService::class, function ($mock) use ($cards) {
$mock->shouldReceive('_downloadCardsFromBoard')
->once()
->andReturn($cards);
});
//here I print the var mock if I do the DD
$mockedTrelloCardService = new TrelloCardService($mock);
$data = $mockedTrelloCardService->_downloadCardsFromBoard();//fail this
dd($data);//I would like to print $cards
}
}
give me following error:
Error: Call to undefined method AppServicesTrelloCardService::_downloadCardsFromBoard()
question from:
https://stackoverflow.com/questions/65891925/laravel-8-x-mock-api-testerror-call-to-undefined-method-app-services-trelloca 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…