PHPackages                             hyperia/codecept-unittest-generator - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Testing &amp; Quality](/categories/testing)
4. /
5. hyperia/codecept-unittest-generator

ActiveLibrary[Testing &amp; Quality](/categories/testing)

hyperia/codecept-unittest-generator
===================================

Unit test generator from annotations.

1.0.1(8y ago)112.2kMITHTMLPHP &gt;=7.0.0

Since Dec 8Pushed 4y ago2 watchersCompare

[ Source](https://github.com/hyperia-sk/codecept-unittest-generator)[ Packagist](https://packagist.org/packages/hyperia/codecept-unittest-generator)[ Docs](https://github.com/hyperia-sk/codecept-unittest-generator)[ RSS](/packages/hyperia-codecept-unittest-generator/feed)WikiDiscussions master Synced 2w ago

READMEChangelog (2)Dependencies (2)Versions (4)Used By (0)

Codecept UnitTest generator
===========================

[](#codecept-unittest-generator)

This package allows you to generate PHPUnit tests from annotations, which you can write in your methods documentation.

- Basic usage of this package is to generate your tests skeleton and basic tests.
- You must check and complete all tests you generate, including the most basic methods.
- Files to parse must declare one class, abstract class, trait or interface to be accepted.

[![screenshot_2017-12-08_17-12-32-github](https://user-images.githubusercontent.com/6382002/33774260-0aaacebc-dc3b-11e7-8a97-34265a4818cc.png)](https://user-images.githubusercontent.com/6382002/33774260-0aaacebc-dc3b-11e7-8a97-34265a4818cc.png)

Installation
------------

[](#installation)

The preferred way to install this extension is through [composer](http://getcomposer.org/download/).

Either run

```
composer require hyperia/codecept-unittest-generator:"^1.0"
```

or add

```
"hyperia/codecept-unittest-generator": "^1.0"

```

to the require section of your composer.json.

Configuration
-------------

[](#configuration)

enable `UnitGenerator` extension in base `/codeception.yml` config file:

```
extensions:
    enabled:
        - Codeception\Extension\RunFailed
    commands:
        - Codeception\Command\UnitGenerator
unitgenerator:
    config:
        # erase old target files with new one
        overwrite: true
        # if you want to generate tests for Interface too
        interface: false
        # automaticaly generate tests for getter / setter method
        auto: true
        # ignore errors that can be ignored
        ignore: true
        # regex (/.*config.php/ for example) that files must not match to have a tests generation
        exclude: '/.*Trait.*/'
        # regex (/.*.php/ for example) that files should match to have a tests generation
        include: '/.*.php/'
    dirs:
        # source directory => target directory
        - common/models: tests/unit/unitgen/common/models/
        - console/models: tests/unit/unitgen/console/models/
```

Usage
-----

[](#usage)

`./vendor/bin/codecept generate:unit`

### Annotations

[](#annotations)

```
/**
 * @PHPUnitGen\(:{})
 */
```

This annotation use some parameters:

- **phpunit\_assertion\_method**: It is the PHPUnit assertion method you want ot use (like *assertEquals*, *assertInstanceOf*, *assertTrue* ...).
- **expectation**: The method return expected value. Some PHPUnit methods does not need it (like *assertTrue*), so in those cases, it can be null.
- **parameters**: The method parameters.

See this example, we want to auto generate some simple test for this method:

```
