PHPackages                             unitgen/unitgen - 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. unitgen/unitgen

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

unitgen/unitgen
===============

Unitgen generates a basic framework for writing unit tests.

565PHP

Since Oct 24Pushed 9y ago1 watchersCompare

[ Source](https://github.com/AlexyAV/unitgen)[ Packagist](https://packagist.org/packages/unitgen/unitgen)[ RSS](/packages/unitgen-unitgen/feed)WikiDiscussions master Synced 2mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

Unitgen
=======

[](#unitgen)

[![Build Status](https://camo.githubusercontent.com/f881d0b6862114580f9d364f52fcc1b94da78afa7a89c625c0ce1ace9e2113f3/68747470733a2f2f7472617669732d63692e6f72672f416c65787941562f756e697467656e2e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/AlexyAV/unitgen)[![Code Climate](https://camo.githubusercontent.com/0b19ad21455aff5076fbb32dff81e1b5d2b816917e1cbe44495ad4c60067c1d4/68747470733a2f2f636f6465636c696d6174652e636f6d2f6769746875622f416c65787941562f756e697467656e2f6261646765732f6770612e737667)](https://codeclimate.com/github/AlexyAV/unitgen)[![Test Coverage](https://camo.githubusercontent.com/abd926607f70ca94f7f13f7b7cdf1516fbbc305d593fb4c86ac9e791f5899cd3/68747470733a2f2f636f6465636c696d6174652e636f6d2f6769746875622f416c65787941562f756e697467656e2f6261646765732f636f7665726167652e737667)](https://codeclimate.com/github/AlexyAV/unitgen/coverage)

The generator of the basic structure for the unit tests. The generated classes are based on tests [phpunit](https://phpunit.de) version &gt;= 5.4.\*. Unitgen is is a command line tool that recursively(optional) analyze the specified path and generates unit test files. The directory structure is reproduced according to the original structure.

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

[](#installation)

Installation via [Composer](https://getcomposer.org/). Add to your composer.json file.

```
{
    "require-dev": {
        "phpunit/phpunit": "5.4.*",
        "unitgen/unitgen": "dev-master"
    }
}

```

Examlpe of created test
-----------------------

[](#examlpe-of-created-test)

For source class "SourceClass":

```
namespace source\class\path;

class SourceClass
{
    /**
     * @throws \Exception
     */
    public function bar()
    {
        ...
    }
}
```

Will be generated next structure within "SourceClassTest":

```
use PHPUnit\Framework\TestCase;

class SourceClassTest extends TestCase
{
    private $sourceClass;

    public function setUp()
    {
        $this->sourceClass = new \source\class\path\SourceClass();
    }

    public function testBar()
    {
        "//TODO Implement test for bar method\n";
        $this->assertTrue(false);
    }

    public function testBarException()
    {
        "//TODO Implement test for bar method\n";
        $this->expectException(\Exception::class);
    }

    public function tearDown()
    {
        "//TODO Implement tearDown method";
    }
}
```

Unitgen generates test method for public method only. Also it looks for annotation exception data and generates appropriate test methods.

NOTE: Unitgen does not affect existing files.

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

[](#configuration)

For use unitgen you should specify a configuration file.

Here is an exaple of configuration file with all available options:

```
return [
    'source'        => [
        'path'    => [], // required
        'exclude' => []
    ],
    'savePath'      => '', // required
    'classExclude'  => [
        'name'      => [], // array of full class names
        'regexp'    => [], // array of reqular expressions
        'parent'    => [], // array of parent classes
        'implement' => [], // array of interfaces
    ],
];
```

NameDescriptionRequiredExampleTypepathSpecified source path directory. Unitgen will walk throught recursively(optional) and generate corresponding test files. Boolean value specifies to walk recursively.true\[ 'first-source-path' =&gt; true, 'second-source-path' =&gt; false \]arrayexcludeDirectories that will be excluded from source path.false\['second-source-path'\]arraysavePathWritable path to save generated tests. Must already exist.true'generated-test-path'stringclassExcludeClasses that will be excluded from source path.false'name'=&gt; \[Examle::class\], 'regexp'=&gt; \['/^Controller.\*/'\], 'parent'=&gt; \[\\Exception::class\], 'implement' =&gt; \[\\Iterator::class\],arrayExample of usage
----------------

[](#example-of-usage)

```
$ cd "vendor/.../unitget/bin"

$ ./unitgen run "config-path"

Start test generation.
======================

Generation completed successful.
-------------------------
Number of files in source path: 9
Number of generated test classes: 3
-------------------------
Generated in:0.12969493865967

```

###  Health Score

22

—

LowBetter than 22% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity13

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity41

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/359f6a15cf5e394411373f6593f62dcbf0d21aea441350b6afaa8fd5afedd94d?d=identicon)[avpretty](/maintainers/avpretty)

---

Top Contributors

[![AlexyAV](https://avatars.githubusercontent.com/u/5259115?v=4)](https://github.com/AlexyAV "AlexyAV (10 commits)")

---

Tags

code-generatorphpunit

### Embed Badge

![Health badge](/badges/unitgen-unitgen/health.svg)

```
[![Health](https://phpackages.com/badges/unitgen-unitgen/health.svg)](https://phpackages.com/packages/unitgen-unitgen)
```

###  Alternatives

[phpspec/prophecy

Highly opinionated mocking framework for PHP 5.3+

8.5k551.7M682](/packages/phpspec-prophecy)[vimeo/psalm

A static analysis tool for finding errors in PHP applications

5.8k77.5M6.7k](/packages/vimeo-psalm)[brianium/paratest

Parallel testing for PHP

2.5k118.8M754](/packages/brianium-paratest)[beberlei/assert

Thin assertion library for input validation in business models.

2.4k96.9M570](/packages/beberlei-assert)[mikey179/vfsstream

Virtual file system to mock the real file system in unit tests.

1.4k108.0M2.7k](/packages/mikey179-vfsstream)[orchestra/testbench

Laravel Testing Helper for Packages Development

2.2k39.1M32.1k](/packages/orchestra-testbench)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
