php - 在我的 laravel 包测试中找不到视图
问题描述
我正在尝试为我的Laravel 包添加刀片指令。
一切都很好,但在测试阶段,我收到了这个错误:
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));
}
解决方案
我修好了:D
我没有从文件中加载视图,而是使用InteractsWithViews
trait(位于Illuminate\Foundation\Testing\Concerns
命名空间中)来渲染刀片,如下面的代码:
$renderedView = (string) $this->blade("@userWalletBalance($wallet)");
$this->assertEquals('1000', trim($renderedView));
推荐阅读
- php - PHP中的动态类使用
- jboss - Jboss Fuse ESB 6.3 上的 Appdynamics Instrumentation
- model - 在 gensim 包装器中访问模型
- php - 在 CodeIgniter 中通过 jQuery AJAX 插入和移动多个图像
- ios - 在 iOS SDK 的 App Modules 中添加框架
- php - 如何使用 PHP 在我所有来自 mysql 的帖子中获得最受欢迎的帖子
- arrays - swift中连续数组的数据结构
- azure - 如何查找流的订阅 ID 和资源组名称
- html - iPhone VoiceOver 不发音箭头的文本
- python - 通过 Selenium 选择下拉选项