【发布时间】:2018-10-31 22:17:04
【问题描述】:
我正在使用返回类型声明,并且我将 mockery 更新到 1.1 版取决于 this post,但它仍然无法正常工作。
我有一个带有方法的工厂:
public function getScrapperByUrl($type):AppScrapperInterface
{
$this->validate($type);
switch ($type) {
case self::ITUNES:
return app(ITunesScrapper::class);
break;
case self::PLAYSTORE:
return app(PlayStoreScrapper::class);
break;
default:
throw new AppScraperException("Can't scrap info");
}
}
在测试中,我在嘲笑 iTunesScrapper 的行为:
$m = m::mock(ITunesScrapper::class);
$scrapedInfo = [
'name' => "comico",
'downloads' => ""
];
$m->shouldReceive('getOfferAnchor')->with(m::any())->andReturn($scrapedInfo['name']);
$m->shouldReceive('getOfferDownloads')->with(m::any())->andReturn($scrapedInfo['downloads']);
App::instance(ITunesScrapper::class, $m);
我收到这样的错误
TypeError: Scrappers\ScrapperFactory::getScrapperByUrl() 的返回值必须是 Scrappers\AppScrapperInterface 的实例,Mockery_2__Adgate_Components_AppstoreFetchers_Itunes_ITunesScrapper 的实例返回。
我做错了什么还是我需要在错误报告中解决这个问题?
【问题讨论】: