TestBuilder

Extracts annotations from PHP source codes, creates PHPUnit test classes.
Note that it is very hard to automatically create unit tests and so this class just creates the templates for tests, and the tests must be updated manually. This class just helps to reduce the amount of time needed to create tests with PHPUnit.
Source
TestBuilder.php
Extends
Extract
Since
Artaengine 1.4.0

Constants

PARAM_TYPE_VARNAME_COMMENTS = 2

method/function @param style is as: @param type var-name comments

PARAM_VARNAME_COMMENTS = 1

method/function @param style is as: @param comments

PARAM_VARNAME_TYPE_COMMENTS = 3

method/function @param style is as: @param var-name type comments

RETURN_COMMENTS = 1

method/function @return style is as: @return comments

RETURN_TYPE_COMMENTS = 2

method/function @return style is as: @return type comments

Static Methods

arrayUpdate

void TestBuilder::arrayUpdate(array base, array source)

Updates base array with source array. The new elements of source will be added to base, the non array elements of base will be updated with the elements of source if they exists in source and have the same key. Elements with the same key that are array in base but not array in source will be updated with the source value. The elements with the same key that are array in both base and source will be updated recursively in the same way.

Arguments

    base (array)
    reference to base array which will be updated
    source (array)
    source array

Returns

void

trimArray

void TestBuilder::trimArray(&a array)

Trim array values in place.

Arguments

    array (&a)
    to be processed

Returns

void

Methods

__construct

TestBuilder $obj = new TestBuilder(array configs)

Constructor.

Arguments

    configs (array)
    RenderHtml configs

Returns

void

extractAll

array $obj->extractAll(string path)

Extract documentations from source codes and return an array. Recursively extracts docs from any file inside the directory and sub-directories.

Arguments

    path (string)
    Path to the root source directory

Returns

array
Look at return for extract()

extractFile

array $obj->extractFile(string path)

Extract documentations from a source code and return an array.

Arguments

    path (string)
    Path to source file

Returns

array
 {
     namespaces: {
         namespace-name: {
             globals: {
                 consts: {
                     const-name: {
                         file: (string),
                         atts: {
                             comment: (string),
                             doc-param: (string),
                         },
                         val: const-value,
                         type:   (string),
                     },
                 },
                 vars: {
                     var-name: {
                         file: (string),
                         atts: {
                             comment: (string),
                             other-doc-param: (string),
                         },
                         static: (bool),
                         val:    var-value,
                         type:   (string),
                     },
                 },
                 function: {
                     function-name: {
                         file: (string),
                         atts: {
                             comment: (string),
                             param:   {
                                 param-name: {
                                     comment: (string),
                                     type:    (string),
                                 },
                             },
                             return:  {
                                comment: (string),
                                type:    (string),
                            },
                             throws: {
                                 comment: (string),
                                 class:   (string),
                             },
                             other-doc-param: (string),
                         },
                         args: [function-args: default-value,],
                     },
                 },
             },
             interfaces: {
                 interface-name: {
                     file:       (string),
                     extends:    [interface-name,],
                     atts: {
                         comment:  (string),
                         att-name: att-value,
                         att-name: [att-value,],
                     },
                     consts:     same-as-for-classes,
                     methods:    same-as-for-classes,
                 },
             },
             classes: {
                 class-name: {
                     file:       (string),
                     abstract:   (bool),
                     final:      (bool),
                     extends:    class-name (string),
                     implements: [interface-names,],
                     atts: {
                         comment:  (string),
                         att-name: att-value,
                         att-name: [att-value,],
                     },
                     consts: {
                         const-name: {
                             atts: {
                                 comment:  (string),
                                 att-name: att-value,
                                 att-name: [att-value,],
                             },
                             val:  const-value,
                             type: (string),
                        },
                     },
                     properties: {
                         property-name: {
                             atts: {
                                 comment:  (string),
                                 att-name: att-value,
                                 att-name: [att-value,],
                             },
                             static: (bool),
                             access: (string) public|private|protected,
                             val:    property-value,
                             type:   (string),
                         },
                     },
                     methods: {
                         method-name: {
                             atts: {
                                 comment:  (string),
                                 att-name: att-value,
                                 att-name: [att-value,],
                                 param: {
                                     param-name: {
                                         comment: (string),
                                         type:    (string),
                                         type2:   (string),
                                     },
                                 },
                                 return: {
                                     comment: (string),
                                     type:    (string),
                                     type2:   (string),
                                 },
                                 throws: [{
                                     comment: (string),
                                     class:   (string),
                                 },],
                             },
                             final:  (bool),
                             static: (bool),
                             access: (string) public|private|protected,
                             args:   [method-args: default-value,],
                         },
                     },
                 },
             },
         },
     },
 }
 

render

void $obj->render()

Render the documentations.

SourcePath
string sourcePath the directory or file containing the source codes
OutputDir
string outputDir the directory to place the output HTMLs in

Returns

void