joshhanley/livewire-dusk-testbench 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

joshhanley/livewire-dusk-testbench

Composer 安装命令:

composer require joshhanley/livewire-dusk-testbench

包简介

A Laravel Dusk testing helper for Livewire package development.

README 文档

README

Livewire Dusk Testbench is a convenience wrapper around Orchestral Testbench Dusk to make testing Livewire components in your package using Laravel Dusk easier.

The code was developed by Caleb Porzio for testing Livewire itself, and packaged up by Josh Hanley for use by others.

Getting Started

It's recommended you read the documentation of these packages before going through this document:

Installation

To install through composer, run the following command from terminal:

composer require --dev joshhanley/livewire-dusk-testbench

Upgrading from V2 of this package

  • App key in phpunit.xml is no longer needed.
  • Signature of public array $packageProviders = []; now has array type definition.
  • configureViewDirectory() method has been renamed to viewsDirectory and should now return a string of the path for the views directory. A string return type is also required.
  • $testsNamespace property and configureTestsDirectory() method are no longer needed so can be deleted.
  • tweatApplicationHook() method is now a static method.
  • Almost all of the items listed in the Possible Overrides in the old README are no longer relevant and can be removed. Remaining ones are listed in that section below.
  • Tests no longer need the $this->browse() method to be called, instead you can call Livewire::visit(MyComponent::class) and the first parameter of Livewire:visit is no longer $browser and instead is your component class. See below examples:

Old test structure:

/** @test */
public function it_can_count()
{
    $this->browse(function (Browser $browser) {
        Livewire::visit($browser, CounterComponent::class)
            // Assertions here
            ;
    });
}

New test structure:

/** @test */
public function it_can_count()
{
    Livewire::visit(CounterComponent::class)
        // Assertions here
        ;
}

Usage

To use this package you need to:

  • Setup your base browser testcase
  • Register your package service providers (if required)
  • Setup layout views (if required)
  • Configure test directory and namespace (if required)

Then you are ready to start testing.

There are other configuration options you can override depending on your needs.

Setup Browser TestCase

To use Livewire Dusk Testbench, all you need to do is extend LivewireDuskTestbench\TestCase instead of Orchestra\Testbench\Dusk\TestCase in your dusk tests.

Or configure this in your base browser testcase:

<?php

class BrowserTestCase extends LivewireDuskTestbench\TestCase
{
    //
}

Register Package Service Providers

Register your package services providers in $packageProviders property to ensure they are loaded for testing:

public array $packageProviders = [
    YourPackageServiceProvider::class,
];

Setup Layout Views

To add other packages to your app layout for testing with, such as AlpineJS, you will need to create a custom layout.

Create your own app layout by creating a views/components/layouts folder somewhere in your package and add a app.blade.php file inside the layouts folder.

Populate your app layout as required.

Then set your base view folder by overridding viewsDirectory method to return a path to the views folder you created.

For Example

A good location to store your views folder and app layout would be in your Dusk browser tests folder.

In the root of your package, create the following directories and file tests/Browser/views/components/layouts/app.blade.php

Then in your tests/Browser/TestCase.php file add:

public function viewsDirectory(): string
{
    // Resolves to 'tests/Browser/views'
    return __DIR__.'/views';
}

Livewire Dusk Macros

Livewire comes with a bunch of Dusk macros which you can use.

Check them out in the Livewire source in 'livewire/src/Features/SupportTesting/DuskBrowserMacros.php'.

In addition, the package provides the following:

  • assertSeeInOrder('@container', ['a', 'b', 'c'])
  • assertIsVisibleInContainer('@container', '@item')
  • assertIsNotVisibleInContainer('@container', '@item')
  • assertHasClasses('@selector', ['class1', 'class2', 'class3'])
  • assertHasOnlyClasses('@selector', ['class1', 'class2', 'class3'])
  • assertMissingClasses('@selector', ['class1', 'class2', 'class3'])
  • assertConsoleLogHasErrors()
  • assertConsoleLogMissingErrors()
  • assertConsoleLogHasError($message)
  • assertConsoleLogMissingError($message)

Demo Package

A demo package has been setup which gives a sample of how this package can be used. Check it out here

Livewire Package Demo

Possible Overrides

Below is a list of some of the settings you can override inside your browser TestCase file to suit your testing needs. Listed below are the defaults:

public $packageProviders = [];

public function viewsDirectory(): string
{
    return '';
}

public static function tweakApplicationHook()
{
    return function () {};
}

Troubleshooting

This is just a convenience wrapper around Orchestral Testbench Dusk to make testing Livewire Components in your package easier.

Consult the documentation for the relevant packages for troubleshooting.

joshhanley/livewire-dusk-testbench 适用场景与选型建议

joshhanley/livewire-dusk-testbench 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 4.39k 次下载、GitHub Stars 达 17, 最近一次更新时间为 2021 年 01 月 12 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 joshhanley/livewire-dusk-testbench 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 joshhanley/livewire-dusk-testbench 我们能提供哪些服务?
定制开发 / 二次开发

基于 joshhanley/livewire-dusk-testbench 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 4.39k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 17
  • 点击次数: 12
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 17
  • Watchers: 2
  • Forks: 2
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2021-01-12