qortex/laravel-7-visual-diff 问题修复 & 功能扩展

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

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

qortex/laravel-7-visual-diff

Composer 安装命令:

composer require qortex/laravel-7-visual-diff

包简介

Marcel Pociot's based beyondcode/laravel-visual-diff adapted for Laravel 7

README 文档

README

Latest Version on Packagist Build Status Quality Score Total Downloads

This package can create a visual diff of two screenshots of your Laravel application. It works for both - regular HTTP tests, as well as tests using Laravel Dusk. Behind the scenes, it uses Pixelmatch to diff the two images.

Here are two basic examples of how the package works:

Using Laravel Dusk:

class ExampleTest extends DuskTestCase
{
    /**
     * A basic browser test example.
     *
     * @return void
     */
    public function testBasicExample()
    {
        $this->browse(function (Browser $browser) {
            $browser->visit('/')
                    ->visualDiff();
        });
    }
}

Using Laravel HTTP Testing:

class ExampleTest extends TestCase
{
    /**
     * A basic test example.
     *
     * @return void
     */
    public function testBasicExample()
    {
        $this->get('/')
             ->visualDiff();
    }
}

Requirements

This package requires node 7.6.0 or higher and the Pixelmatch Node library.

You can install the Pixelmatch on MacOS via NPM:

npm install pixelmatch

Or you could install it globally

npm install pixelmatch --global

Custom node and npm binaries

Depending on your setup, node or npm might be not directly available to VisualDiff. If you need to manually set these binary paths, you can do this by setting the npm_binary and node_binary config settings in the visualdiff.php configuration file.

Installation

This package can be installed through Composer.

composer require beyondcode/laravel-visual-diff

Usage

The package will automatically register the VisualDiffServiceProvider with your Laravel application.

The package adds a new method to either the TestResponse or the Browser class which is called visualDiff. Depending on how you want to create visual diffs, follow the usage guidelines for the Laravel Dusk integration or the HTTP testing integration.

The visualDiff method accepts a name, that will be used for the screenshot generation. If you do not provide a name, the package will try and guess the test name. If this does not work for you, please provide a name manually instead.

Dusk Integration

Just call the visualDiff() method on the Laravel Dusk Browser instance that you use for testing:

$this->browse(function (Browser $browser) {
    $browser->visit('/')
            ->visualDiff();
});

This will automatically create a screenshot in all provided resolutions and create a diff, if a previous screenshot is available.

HTTP Testing Integration

Just call the visualDiff() method on the TestResponse instance that you use for testing:

$this->get('/')
     ->visualDiff();

This will automatically create a screenshot in all provided resolutions and create a diff, if a previous screenshot is available.

Dealing with diffs

When VisualDiff detects differences in the new screenshot compared to the previous successfully created screenshot, the PHPUnit test will fail. It will tell you which test caused the visual difference as well as giving you the filename of the screenshot diff.

Now you need to handle with this visual diff, just as you would with a code-diff. Review the changes and either approve the visual difference, or revert the UI state back to the successful state.

You can approve the new screenshots by adding a -d --update-screenshots flag to the phpunit command.

> ./vendor/bin/phpunit -d --update-screenshots

OK (1 test, 1 assertion)

Specify multiple resolutions

Creating diffs for multiple resolutions can be very useful - especially if you want to test responsive websites and applications.

You can define all possible resolutions in your visualdiff.php configuration file:

/**
 * Define all different resolutions that you want to use when performing
 * the regression tests.
 */
'resolutions' => [
    [
        'width' => 1920,
        'height'=> 1080
    ]
]

Alternatively, you may want to only create one specific diff in multiple resolutions. You can do this using the visualDiffForResolutions method and provide an array with the resolutions to test.

$this->get('/')
     ->visualDiffForResolutions([
        [
            'width' => 1920,
            'height' => 1080
        ],
        [
            'width' => 640,
            'height' => 480
        ],
     ]);

See diff results in your terminal window

If you use iTerm2 as your terminal of choice, you will see an image representation of the diff when you run your tests.

iTerm 2

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security related issues, please email marcel@beyondco.de instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.

qortex/laravel-7-visual-diff 适用场景与选型建议

qortex/laravel-7-visual-diff 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.64k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2020 年 08 月 08 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「beyondcode」 「visual regression」 「laravel-visual-diff」 「qortex」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

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

围绕 qortex/laravel-7-visual-diff 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

  • 总下载量: 1.64k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 11
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 23
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-08-08