定制 alebatistella/duskapiconf 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

alebatistella/duskapiconf

最新稳定版本:v1.2.5

Composer 安装命令:

composer require alebatistella/duskapiconf

包简介

Change your Laravel configuration for each Dusk test with an easy API

README 文档

README

A Laravel module to perform live configuration changes from your Dusk tests. Forked from Manyapp DuskApiConf repository.

The issue

Currently, the only way to define the configuration of your Laravel app during Dusk tests is to set the relevant variables in a dedicated .env.dusk.local file. This file is copied and read during the application's boot, and therefore cannot be changed within Dusk tests.

This behavior can be problematic, as a lot of developers need to change the configuration in specific tests to see if the application reacts accordingly.

As mentioned here, there is no easy way to tackle this problem.

The solution

This modules offers an easy possibility to change the configuration of your application during the runtime of your Dusk tests.

It works by making available a hidden API route to register the configuration in a temporary file, which is read on the further requests from the dusk tests.

Installation

composer require alebatistella/duskapiconf --dev

You will have to add the trait to your DustTestCase.php as shown:

<?php

use Laravel\Dusk\TestCase as BaseTestCase;
use AleBatistella\DuskApiConfig\Traits\UsesDuskApiConfig;

abstract class DuskTestCase extends BaseTestCase {
    use UsesDuskApiConfig;

    // ...
}

Usage

To use it, use the defined methods below directly in your Dusk tests.

/** @test */
public function test_should_use_dusk_for_something ()
{
    // Get a config variable
    // Here, $appName will be "Laravel" on a fresh install
    $appName = $this->getConfig('app.name');

    // Change a config variable
    $this->setConfig('app.name', 'Laravel is fantastic');

    // Here, $appName will be "Laravel is fantastic"
    $appName = $this->getConfig('app.name');

    // Your tests with assertions
    // ...

    // You can reset all config variables set before.
    // This is not mandatory: you can keep the variables set for the next test
    // if you want (even though it is not a good practice).
    $this->resetConfig();
}

Publish configuration file

php artisan vendor:publish --provider="AleBatistella\DuskApiConf\DuskApiConfServiceProvider"

With this command, you'll create a new duskapiconf.php in the config folder. Then, you can modify the storage disk and the name of the temporary file, including configuration about the used environment.

License

MIT.

统计信息

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

GitHub 信息

  • Stars: 4
  • Watchers: 0
  • Forks: 3
  • 开发语言: PHP

其他信息

  • 授权协议: mit
  • 更新时间: 2023-07-07