【发布时间】:2015-01-25 12:19:34
【问题描述】:
我正在尝试用 mockery 测试我的 laravel 项目中的一个类的方法。
但是,当我尝试测试 phpunit 时说我的接口类(在我需要测试的方法中使用)不可实例化。
怎么了?
我的测试课
class HelperRSTest extends TestCase {
public function tearDown()
{
Mockery::close();
}
public function test_mockery()
{
// $mock = Mockery::mock('HelperRS');
// $mock->shouldReceive('getRecibosLocacao')->once()->andReturn('mocked');
$result = HelperRS::getRecibosLocacao(1228);
var_dump($result);
}
}
我要测试的目标类
class HelperRS extends \BaseController {
public static function getRecibosLocacao($id_locacao){
$pagamentos = App::make('PagamentoRepositoryInterface');
$locacao = Locacao::find($id_locacao);
$pagamento = $pagamentos->getByVendaByTipo($locacao->cod_locacao, 'l');
dd($pagamento);
}
}
错误:
1) HelperRSTest::test_mockery
Illuminate\Container\BindingResolutionException: Target [PagamentoRepositoryInterface] is not instantiable.
【问题讨论】:
标签: php unit-testing laravel mocking