我正在尝试为我的Laravel包添加刀片指令。
一切都很好,但在测试阶段,我得到这个错误:
1) MahbodHastamUserWalletTestsFeatureBladeTest::show_user_wallet_balance
InvalidArgumentException: View [userWalletBalance] not found.
是否应该将$this->loadViewsFrom(...)
放在服务提供商中?
查看路径:/tests/resources/views/userWalletBalance.blade.php
测试路径:/tests/Feature/BladeTest.php
我也试图将resources
目录移动到Feature
目录(BladeTest.php
旁边),但得到了同样的错误。
BladeTest.php
上的代码:
public function show_user_wallet_balance() {
$wallet = UserWallet::getWallet(wallet_id: 1);
$this->assertEquals('1000', $this->renderView('userWalletBalance', ['wallet' => $wallet]));
}
protected function renderView($view, $with) {
Artisan::call('view:clear');
return trim((string) view($view)->with($with));
}
我修复了:D
我没有从文件中加载视图,而是使用InteractsWithViews
特性(在IlluminateFoundationTestingConcerns
命名空间上)来呈现刀片,如下面的代码:
$renderedView = (string) $this->blade("@userWalletBalance($wallet)");
$this->assertEquals('1000', trim($renderedView));