This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 271100 - php-unit skelgen update
Summary: php-unit skelgen update
Status: NEW
Alias: None
Product: php
Classification: Unclassified
Component: PHPUnit (show other bugs)
Version: Dev
Hardware: All All
: P3 normal with 1 vote (vote)
Assignee: issues@php
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-07-14 22:53 UTC by twifty
Modified: 2017-07-16 19:36 UTC (History)
2 users (show)

See Also:
Issue Type: ENHANCEMENT
Exception Reporter:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description twifty 2017-07-14 22:53:07 UTC
I've completely rewritten the abandoned php-unit skelgen.

https://github.com/twifty/test-generator

Three commands are available:

Common options:
 [-b|--bootstrap BOOTSTRAP] Good old bootstrap
 [-s|--skelgen SKELGEN] A config file usually in the project root
 [-p|--project-base PROJECT-BASE] The project root directory
 [-j|--json [JSON]] Output to console or file

Multiple skelgen files can exist within a project. Each configures how the test files are created for the classes alongside and below it within the directory structure. If a file is passed on the command line, it overrides all other files. Otherwise the generator will search beginning at the class to be tested up to the <project-base>. If the base is not given it will search up to the current working directory or drive root, whichever comes first.

1. generate-test command:

generate-test
 [--overwrite] Allows existing files to be overwritten
 [-a|--auto-rename] Allows name collisions to be resolved
 [--] <source-class> [<source-path>] [<target-path>]

I've dropped the <target-class> argument, <target-path> ideally should be the test directory, but it will accept full file paths (appended with '.php').

IMPORTANT NOTE:
Any target files passed in are only a hint. The skelgen file has full control over the target path and class names. Actual written files are either written to the console or dumped to a json file.

The generator will create test classes for abstract classes and traits. Currently the IDE does not invoke the command for traits. Also, the IDE will issue an error if the created file doesn't exist at the path it passed on the command line.

2. generate-batch

generate-batch
 [--overwrite]
 [-r|--recursive]
 [--] <source-path> [<target-path>]

Given a directory, it will create tests for all found classes and traits. <target-path> should be the test directory. Again, the skelgen file can customize the paths. The default implementation is to follow a PSR-4 structure.

3. generate-method

generate-method
 [--] <method-names> <source-class> [<source-path>] [<target-path>]

This command will add a new method to an existing test class, or create a new test class containing only that method. Using this, developers should be able to right click on a method and jump right to the test classes newly added method.

JSON format:

Both generate-test and generate-method will output a single record, generate-batch will output an array of records. Each record is a hash with the following structure:

{
    "status": "error", One of 'error', 'success' or 'skipped'
    "source-class": "\\Foo2", All records have this entry.

    These may not exist if an error occured 

    "source-path": "/foo2.php", Full path to source
    "target-class": "\\Bar2", The fully qualified name
    "target-path": "/bar2.php", The full path of written file
    "methods": [
        "testThis" An array of written method names
    ",

    Only available if status === error

    "error-code": 8, Full list and texts can be provided
    "error-text": "File Exists", The error code in text format
    "error-message": "File xxx not found" A more descriptive message
}

The skipped status indicates that the skelgen file prevented the test from being created.

If there is anything you feel needs changing, I will be happy to discuss.