【发布时间】:2021-01-13 15:49:22
【问题描述】:
我正在为一个将提供一些 blade components 的软件包做出贡献。因此,此包的用户可以将刀片模板上的组件用作:
<x-mypackage-component-a/>
组件位于我的包的src/Components 文件夹下。这些组件使用loadViewComponentsAs() 方法加载到包服务提供程序中,如here 所述:
$this->loadViewComponentsAs('mypackage', [
Components\ComponentA::class,
...
]);
现在,我需要对 phpunit 进行一些测试,以检查组件是否由包服务提供商加载,如下所示:
public function testComponentsAreLoaded()
{
$this->assertTrue(/*code that check 'x-mypackage-component-a' exists*/);
}
是否有任何方法(使用 Laravel 框架)来检查刀片组件名称是否存在和/或已加载?
我已经设法为包提供的一组刀片视图和下一个代码做类似的事情:
// Views are loaded on the package service provider as:
$this->loadViewsFrom($viewsPath, 'mypackage');
// The phpunit test method is:
public function testViewsAreLoaded()
{
$this->assertTrue(View::exists('mypackage::view-a'));
$this->assertTrue(View::exists('mypackage::view-b'));
...
}
提前致谢!
【问题讨论】:
标签: phpunit laravel-blade laravel-7