Skip to content

msamgan/laravel-env-keys-checker

Repository files navigation

Check if all the keys are available across all the .env files.

image

Latest Version on Packagist GitHub Tests Action Status Total Downloads

This package checks if all the keys are available across all the .env files. This package is useful when you have multiple .env files and want to ensure all the keys are available across all the .env files.

With a team of developers, it is possible that some developers might forget to add the keys they used in their .env file to the .env.example file or the other way around.

Table of Contents

Features

  • Check if all the keys are available across all the .env files.
  • Add the missing keys to the .env files automatically (configurable) considering the line numbers and empty lines.
  • Check if the .env and other provided files are present in .gitignore, so that they are not committed to git by mistake.
  • Sync all the available keys by line across all the .env files. Referencing the master .env file. (Configurable, default is .env)

Installation

You can install the package via composer:

composer require msamgan/laravel-env-keys-checker --dev

To configure this package, you can add environment variables to your .env files. See the config file for details. Please make sure that you refresh the config cache after adding/updating the environment variables. php artisan config:cache

If you prefer, you can also publish the config file with:

php artisan vendor:publish --tag="env-keys-checker-config"

Usage

To check if all the keys are available across all the .env files.

php artisan env:keys-check

Options

--auto-add: This option will add the missing keys to the .env files automatically. The possible values are ask, auto, and none. The default value is ask.

--no-progress: This option will disable the progress bar.

--no-display: This option will disable all output.

To check if the .env and other provided files are present in .gitignore.

php artisan env:in-git-ignore

To sync all the available keys by line across all the .env files.

php artisan env:sync-keys

In Test

You can also use this package in your test cases to make sure the required feature is working as expected.

To check if all the keys are available across all the .env files.

Add the following code to your test case.

Make sure to add --auto-add=none to override the default configuration.

it('tests that the .env key are same across all .env files.', function () {
    $this->artisan('env:keys-check --auto-add=none')->assertExitCode(0);
});

To check if the .env and other provided files are present in .gitignore.

Add the following code to your test case.

it('tests that the .env and other provided files are present in .gitignore.', function () {
    $this->artisan('env:in-git-ignore')->assertExitCode(0);
});

Configuration

You can configure the package by publishing the configuration file.

# config/env-keys-checker.php
# List of all the .env files to ignore while checking the env keys
# .env key: KEYS_CHECKER_IGNORE_FILES (coma separated string)
 
'ignore_files' => [],
# config/env-keys-checker.php
# List of all the .env keys to ignore while checking the env keys
# .env key: KEYS_CHECKER_IGNORE_KEYS (coma separated string)

'ignore_keys' => [],
# config/env-keys-checker.php  
# strategy to add the missing keys to the .env file
# ask: will ask the user to add the missing keys
# auto: will add the missing keys automatically
# none: will not add the missing keys
# .env key: KEYS_CHECKER_AUTO_ADD (string)

'auto_add' => 'ask',
# config/env-keys-checker.php
# List of all the .env.* files to be checked if they
# are present in the .gitignore file.
# .env key: KEYS_CHECKER_GITIGNORE_FILES (coma separated string)

'gitignore_files' => ['.env'],
# Master .env file to be used for syncing the keys
'master_env' => env('MASTER_ENV', '.env'),

Testing

composer test

Changelog

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

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

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

About

check if all the keys are available across all the .env files.

Resources

License

Stars

Watchers

Forks

Sponsor this project

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •  

Languages