Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/idrinth/phpunit-test-generator
Generates tests for phpunit
https://github.com/idrinth/phpunit-test-generator
generator phpunit test-generation unittest
Last synced: 3 months ago
JSON representation
Generates tests for phpunit
- Host: GitHub
- URL: https://github.com/idrinth/phpunit-test-generator
- Owner: Idrinth
- License: mit
- Created: 2018-01-23T17:48:05.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2024-07-21T17:10:51.000Z (6 months ago)
- Last Synced: 2024-09-29T16:02:01.783Z (3 months ago)
- Topics: generator, phpunit, test-generation, unittest
- Language: PHP
- Size: 1.72 MB
- Stars: 3
- Watchers: 4
- Forks: 0
- Open Issues: 12
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Test-Generator for PHPUnit
[![Codacy Badge](https://api.codacy.com/project/badge/Grade/cabd3fc70be847d4b2f28c9472598c61)](https://www.codacy.com/app/Idrinth/phpunit-test-generator?utm_source=github.com&utm_medium=referral&utm_content=Idrinth/phpunit-test-generator&utm_campaign=Badge_Grade)
[![Codacy Badge](https://api.codacy.com/project/badge/Coverage/cabd3fc70be847d4b2f28c9472598c61)](https://www.codacy.com/app/Idrinth/phpunit-test-generator?utm_source=github.com&utm_medium=referral&utm_content=Idrinth/phpunit-test-generator&utm_campaign=Badge_Coverage)
[![Build Status](https://travis-ci.org/Idrinth/phpunit-test-generator.svg?branch=master)](https://travis-ci.org/Idrinth/phpunit-test-generator)
[![CodeFactor](https://www.codefactor.io/repository/github/idrinth/phpunit-test-generator/badge)](https://www.codefactor.io/repository/github/idrinth/phpunit-test-generator)
[![BCH compliance](https://bettercodehub.com/edge/badge/Idrinth/phpunit-test-generator?branch=master)](https://bettercodehub.com/)## Command & Options
```
php bin/generate-tests --dir=/path/to/alternative/dir --mode=replace
```### dir
Dir is optional and will default to the current working directory. Pick the directory that the composer.json is in.
### replace (deprecated, see mode)
If set old testfiles will be overwritten, if not set they will be renamed instead. Usually you shouldn't need this.
### mode
One of replace, skip or move. Defines how to handle file conflicts and defaults to moving the old file.
### output
If set will be prepended to the relative paths of dev-autoload paths.
## How does it work?
The composer.json at the working directory(or the supplied dir) will pe parsed for namespaces(psr 0 and 4), the folders targeted by none-dev namespaces will be searched for classes and test classes will be generated in the appropriate development-autoloading-folder.
To determine the testing class to be used, the phpunit dev-dependency is parsed, so you need to supply a constraint to make the generation work.## Generated Test - Example
This is a generated testfile for the actual Controller of this library. The intention is to generate PSR2-compatible code, obviously that might not yet be the case everywhere. If you find one where it fails, feel free to file a bug.
```php
getMockBuilder('Symfony\Component\Finder\Finder')->getMock(),
$this->getMockBuilder('De\Idrinth\TestGenerator\Interfaces\ClassReader')->getMock(),
$this->getMockBuilder('De\Idrinth\TestGenerator\Interfaces\ClassWriter')->getMock(),
$this->getMockBuilder('De\Idrinth\TestGenerator\Interfaces\Composer')->getMock(),
null
);
}/**
* From Controller
* @test
* @todo replace with actual tests
**/
public function testInit ()
{
$instance = $this->getInstance();
$return = $instance->init();$this->assertInternalType(
'object',
$return,
'Return didn\'t match expected type object'
);$this->assertInstanceOf(
'De\Idrinth\TestGenerator\Controller',
$return,
'Return didn\'t match expected instance De\Idrinth\TestGenerator\Controller'
);$this->markTestIncomplete(
'This test has not been implemented yet.'
);
}/**
* From Controller
* @test
* @todo replace with actual tests
**/
public function testRun ()
{
$instance = $this->getInstance();
$return = $instance->run();$this->assertInternalType(
'null',
$return,
'Return didn\'t match expected type null'
);$this->markTestIncomplete(
'This test has not been implemented yet.'
);
}
}
```