Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/hyperia-sk/codecept-unittest-generator
Generate PHPUnit tests from annotations, which you can write in your methods documentation
https://github.com/hyperia-sk/codecept-unittest-generator
annotations php phpunit phpunit-skeleton testgenerator unittest
Last synced: 22 days ago
JSON representation
Generate PHPUnit tests from annotations, which you can write in your methods documentation
- Host: GitHub
- URL: https://github.com/hyperia-sk/codecept-unittest-generator
- Owner: hyperia-sk
- License: mit
- Created: 2017-12-08T15:53:35.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2021-08-04T10:19:06.000Z (over 3 years ago)
- Last Synced: 2024-10-01T08:02:26.291Z (about 1 month ago)
- Topics: annotations, php, phpunit, phpunit-skeleton, testgenerator, unittest
- Language: HTML
- Size: 15.6 KB
- Stars: 11
- Watchers: 4
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE.md
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# 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)
## Installation
The preferred way to install this extension is through [composer](http://getcomposer.org/download/).
Either run
```shell
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
enable `UnitGenerator` extension in base `/codeception.yml` config file:
```yaml
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
`./vendor/bin/codecept generate:unit`
### Annotations
```php
/**
* @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:
```php
assertEquals('expectation string', $this->method(1, 2, 'a string'));
$this->assertTrue($this->method(4, 5, 'another'));
$this->AssertEquals(null, $this->method());
$this->assertNull($this->method());
```#### Getter and setter annotation
```php
() {}
set() {}
```PHPUnit Generator has an "auto" option: If you activate it,
it will search for the property when it find a method beginning
with "get" or "set", and if the property exists, it will generate tests.#### Private or protected method
If the method to test is private or protected, PHPUnit Generator will access the method with PHP ReflectionClass.
## Requirements
UnitGenerator needs the following components to run:
- Codeception UnitGenerator is a module for **Codeception**. It will need a running version of this tool.
- [Phpunit-generator](https://github.com/paul-thebaud/phpunit-generator) package.