GithubHelp home page GithubHelp logo

alexandrebellas / duskapiconf Goto Github PK

View Code? Open in Web Editor NEW

This project forked from manyapp/duskapiconf

3.0 1.0 1.0 29 KB

A Laravel module to perform live configuration changes from your Dusk tests

Home Page: https://many.app/changing-laravel-configuration-during-dusk-tests/

License: MIT License

PHP 99.53% Blade 0.47%

duskapiconf's Introduction

Dusk API configuration

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.

duskapiconf's People

Contributors

alexandrebellas avatar github-actions[bot] avatar manyapp avatar

Stargazers

Tony Lea avatar  avatar Susan Buck avatar

Watchers

James Cloos avatar

Forkers

susanbuck

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.