Command line

When you install this package, you can use the command line to generate your unit tests skeleton. Use this command in project root directory.


$ php ./vendor/bin/phpunitgen

For this command, you will need a configuration file written in YAML, JSON or PHP.

By default, PhpUnitGen search for a configuration file named phpunitgen.yml at the project root.

But if you want to use a custom configuration path, you can use an option:


$ php ./vendor/bin/phpunitgen --config=my/custom/config.yml

$ php ./vendor/bin/phpunitgen -c=my/custom/config.yml

Use PhpUnitGen on one file only (use of file option need a source and a target):


$ php ./vendor/bin/phpunitgen --file source/file.php target/file.php

$ php ./vendor/bin/phpunitgen -f source/file.php target/file.php

Use PhpUnitGen on one directory only (use of dir option need a source and a target):


$ php ./vendor/bin/phpunitgen --dir source/dir target/dir

$ php ./vendor/bin/phpunitgen -d source/dir target/dir

Use PhpUnitGen with the default configuration open_in_new (use of default configuration need a source and a target):


$ php ./vendor/bin/phpunitgen --default --file source/file.php target/file.php
$ php ./vendor/bin/phpunitgen --default --dir source/dir target/dir

$ php ./vendor/bin/phpunitgen -D -f source/file.php target/file.php
$ php ./vendor/bin/phpunitgen -D -d source/dir target/dir

infoNotice
  • If you use the default option with the config option, configuration will be ignored and default configuration will be used.
  • If you use the default option, and you don't provide the dir or the file option, PhpUnitGen will consider that source and target paths are directories.
  • As PhpUnitGen use the Symfony Console package, you can combine multiple option together: $ php ./vendor/bin/phpunitgen -fc my/custom/config.yml source/file.php target/file.php will parse one file with your custom configuration.

Configuration

A configuration file needs the following parameters:

  • overwrite [boolean]: Set true if you want to erase old files with the new ones.
  • backup [boolean]: Set true if you want to backup old files before erase them when overwrite is set to true. Backup files while be named as following: your_file.php.bak
  • interface [boolean]: Set true if you want to generate unit tests skeletons for interface too.
  • private [boolean]: Set true if you want to generate unit tests skeletons for private / protected methods too.
  • auto [boolean]: Set true if you want to automatically generate getter / setter unit tests, and class or trait instantiation.
  • ignore [boolean]: Set true if you want to ignore errors that are not fatal.
  • exclude [string or null]: A PHP regex to filter files that have not to be parsed. Set as null if you do not want to use an exclude regex.
  • include [string or null]: A PHP regex to filter files that have to be parsed. Set as null if you do not want to use an include regex.
  • dirs [array]: An array of source: target directories. PhpUnitGen will parse each files in your source directory (an array key) and put the generated unit tests skeletons in your target directory (an array value). It will also parse sub-directories. null if you have no directory to parse.
  • files [array]: An array of source: target files. PhpUnitGen will parse each files in your source file (an array key) and put the generated unit tests skeletons in your target file (an array value). null if you have no file to parse.

Next step

Now you know how to run PhpUnitGen on the command line, learn more on PhpUnitGen annotations.

share