目标是将雄辩的结果列表转换为<select>
标记。
我这样做:
班级TransactionPurposeRepository
protected $_transactionPurpose;
function __construct(TransactionPurpose $transactionPurpose)
{
$this->_transactionPurpose = $transactionPurpose;
}
/**
* Get all the transaction purposes
*
* @return mixed
*/
public function all()
{
return $this->_transactionPurpose->all();
}
在控制器中我有:
$purposes = $this->_transactionPurposeRepo->all();
print_r($purposes->lists('id')); die();
在浏览器中(ok):
Array ( [0] => 1 [1] => 2 [2] => 3 [3] => 4 [4] => 5 [5] => 6 [6] => 7 [7] => 8 [8] => 9 [9] => 10 )
在控制台(测试)中:
PHPUnit 4.3.4 by Sebastian Bergmann.
Configuration read from /Users/yuriikrevnyi/sites/zp.dev/www/phpunit.xml
.......................................PHP Fatal error: Call to a member function lists() on a non-object in /Users/yuriikrevnyi/sites/zp.dev/www/app/zp/controllers/TransactionsController.php on line 79
Fatal error: Call to a member function lists() on a non-object in /Users/yuriikrevnyi/sites/zp.dev/www/app/zp/controllers/TransactionsController.php on line 79
关键行在这里Call to a member function lists() on a non-object
。
问题是:到底发生了什么?
答案 0 :(得分:0)
我修改了测试:
$purposes = new Collection([new TransactionPurpose, new TransactionPurpose]);
$this->_repo
->shouldReceive('all')->once()->andReturn(Mockery::mock([
'all' => $purposes,
'lists' => $purposes->toArray()
]));