2017 © Pedro Peláez
 

library unitgen

Unitgen generates a basic framework for writing unit tests.

image

unitgen/unitgen

Unitgen generates a basic framework for writing unit tests.

  • Monday, October 24, 2016
  • by avpretty
  • Repository
  • 1 Watchers
  • 4 Stars
  • 46 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

Unitgen

Build Status Code Climate Test Coverage, (*1)

The generator of the basic structure for the unit tests. The generated classes are based on tests phpunit version >= 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., (*2)

Installation

Installation via Composer. Add to your composer.json file., (*3)

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

Examlpe of created test

For source class "SourceClass":, (*4)

namespace source\class\path;

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

Will be generated next structure within "SourceClassTest":, (*5)

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., (*6)

NOTE: Unitgen does not affect existing files., (*7)

Configuration

For use unitgen you should specify a configuration file., (*8)

Here is an exaple of configuration file with all available options:, (*9)

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
    ],
];
Name Description Required Example Type
path Specified source path directory. Unitgen will walk throught recursively(optional) and generate corresponding test files. Boolean value specifies to walk recursively. true [ 'first-source-path' => true, 'second-source-path' => false ] array
exclude Directories that will be excluded from source path. false ['second-source-path'] array
savePath Writable path to save generated tests. Must already exist. true 'generated-test-path' string
classExclude Classes that will be excluded from source path. false 'name'=> [Examle::class], 'regexp'=> ['/^Controller.*/'], 'parent'=> [\Exception::class], 'implement' => [\Iterator::class], array

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

The Versions

24/10 2016

dev-master

9999999-dev

Unitgen generates a basic framework for writing unit tests.

  Sources   Download

MIT

The Requires

 

The Development Requires

by AlexyAV

skeleton generator unit-test