【发布时间】:2021-10-18 01:49:44
【问题描述】:
我正在尝试为我的 Laravel package 添加刀片指令。
一切都很好,但在测试阶段,我收到了这个错误:
1) MahbodHastam\UserWallet\Tests\Feature\BladeTest::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));
}
【问题讨论】:
-
您可以参考laravelpackage.com/09-routing.html#views了解更多关于在包中加载视图的信息。
-
文档说要在整个包上加载视图,但我想在测试中加载视图以测试我之前添加的刀片指令。
标签: php laravel package package-development