selevia / env-validator
The script for validate env variables
Requires
- php: ^7.3 | ^8.0.0
- beberlei/assert: ^3.2
- doctrine/collections: ^1.6
- symfony/console: ^5.1
- vlucas/phpdotenv: ^5.0
Requires (Dev)
- codedungeon/phpunit-result-printer: ^0.30.1
- phpunit/phpunit: ^9.2
This package is auto-updated.
Last update: 2024-04-26 18:22:08 UTC
README
Env Validator is a utility for comparing the expected environment variables (usually defined in a .env.example
file) with the actual environment variables (usually loaded from a .env
file) that are present at runtime.
Installation
Install via composer:
composer require selevia/env-validator
Usage
As your project grows, your infrastructure concerns change, and so does the .env.example
file. Use the env-validator
utility to validate that your environment has been configured correctly.
Simply add a script to your composer.json
:
{ "scripts": { "env-validator": "env-validator" } }
and run it:
composer env-validator
or, alternatively, run the executable directly:
vendor/bin/env-validator
Options
By default, the utility looks for .env
and .env.example
files in the root directory of your project.
If you want to change the default filenames use the following options:
--actual
(-a
) for the actual file.--expected
(-e
) for the expected file.
Example:
vendor/bin/env-validator --actual=.env.dev --expected=.env.template
Output
The very first line will be a summary of each Status type (i.e. Success, Warning, and Error). Below the summary, all the Error and Warning cases will be outputted, if any.
Statuses
Each environment variable defined in both files will be given a Status
Type | Output Message | Explanation |
---|---|---|
Error | Expected env var ENV_VAR_NAME was completely missing | The variable is missing. This means it was defined in the expected file, but not in the actual one. |
Warning | Unexpected env var ENV_VAR_NAME encountered | The variable is unexpected. This means it was present in the actual file, but it was not defined in the expected file. |
Warning | Env var ENV_VAR_NAME was present, but the value was empty | The variable is blank. This means it was defined in the expected file and present in the actual file, but the value was blank. |
Success | N/A | Everything is okay |