jocarreira / hamcrest

Automatically exported from code.google.com/p/hamcrest
0 stars 0 forks source link

PHP: Create script to generate hamcrest.php from an @factory doctag #119

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
The hamcrest.php module that defines all of the global function helpers should 
be generated by a script that scans the source for @factory tags.

Without any arguments, it should use the name of the function to which it is 
attached. With arguments, each should be defined with the same body, but the 
second and more should include a comment that they are aliases for the first.

    /**
     * Tests if a value is greater than the expected value.
     *
     * @param mixed $expected the minimum value to pass
     * @return Hamcrest_Core_GreaterThanOrEqual a new configured matcher
     *
     * @factory greaterThanOrEqual atLeast
     */
    public static function greaterThanOrEqual($expected) { ... }

should produce

    /**
     * Tests if a value is greater than the expected value.
     *
     * @param mixed $expected the minimum value to pass
     * @return Hamcrest_Core_GreaterThanOrEqual a new configured matcher
     */
    function greaterThanOrEqual($expected) {
        return Hamcrest_Matchers::greatThanOrEqual($expected);
    }

    /**
     * Tests if a value is greater than the expected value.
     *
     * Alias for greatThanOrEqual().
     *
     * @param mixed $expected the minimum value to pass
     * @return Hamcrest_Core_GreaterThanOrEqual a new configured matcher
     */
    function atLeast($expected) {
        return Hamcrest_Matchers::greatThanOrEqual($expected);
    }

Bonus points if the script also generates the Hamcrest_Matchers.php static 
factory module.

Question: Are there any factory methods that have a different name from the 
main factory function? If not, there's no need to allow for renaming. Aliases 
can be listed without also listing the method itself which would be nicer.

Original issue reported on code.google.com by dharkn...@gmail.com on 9 Aug 2010 at 6:08

GoogleCodeExporter commented 8 years ago
I've committed the tool and added @factory to every static factory method.

- Add any number of aliases after the doctag
    @factory atMost     [alias for lessThanOrEqualTo]
- Add minus (-) as an alias to skip the actual method name
    @factory - atMost   [lessThanOrEqualTo won't be a factory method]
- Add ellipses (...) as an alias for methods that use func_get_args().

Original comment by dharkn...@gmail.com on 17 Aug 2010 at 10:29