This package helps automate the creation of PHPUnit test files for your PHP project. It scans specified source directories for PHP files and generates corresponding test classes.
To install the package, you’ll need Composer. Run the following command in your terminal:
composer require stoufa06/generate-tests --dev
After installing the package, use the generate-tests
script from the command line to generate test files for your source code.
The script supports several command line options to customize its behavior:
-
--src=<path>
: Specify the source directory containing the PHP files for which tests should be generated. Default issrc
. If a relative path is provided, it will be resolved using the base directory. -
--tests=<path>
: Specify the output directory where the test files will be generated. Default istests
. If a relative path is provided, it will be resolved using the base directory. -
--backup=<file>
: Specify a file containing a list of test files that should always be regenerated. Default isbackup_list.txt
. -
--exclude=<file>
: Specify a file listing folders to exclude from test generation. Default isexcluded_folders.txt
. -
--marker=<bool>
: Enable or disable the check for a specific marker in test files. By default, only files containing a '// Generated by script' comment will be regenerated if they already exist. -
--baseDir=<path>
: Specify the base directory to resolve relative paths. Default is the current working directory. If provided, all relative paths forsrc
,tests
,backup
, andexclude
will be based on this directory.
vendor/bin/generate-tests --src=src --tests=tests --backup=backup_list.txt --exclude=excluded_folders.txt --marker=1 --baseDir=/path/to/base
This command will generate test files for all PHP files within the src
directory, output them to the tests
directory, check against backup_list.txt
and excluded_folders.txt
for any specific rules, and regenerate any previously scripted files containing the marker.
Feel free to submit issues or pull requests. Contributions are welcome!
This project is licensed under the MIT License. See the LICENSE
file for details.