Download the PHP package andi3/phpunit-docgen without Composer
On this page you can find all versions of the php package andi3/phpunit-docgen. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download andi3/phpunit-docgen
More information about andi3/phpunit-docgen
Files in andi3/phpunit-docgen
Package phpunit-docgen
Short Description Generate test evidence or documentation by using doc comments.
License MIT
Informations about the package phpunit-docgen
Documentation generator via PHPUnit
Usage
Require package:
composer require pretzlaw/phpunit-docgen
Write this in your phpunit.xml
:
<listeners>
<listener class="Pretzlaw\PHPUnit\DocGen\TestCaseListener">
<arguments>
<string>test-evidence.md</string>
</arguments>
</listener>
</listeners>
It will output all your doc comments as a nice markdown. This brings up a nice test evidence for unit tests or some kind of documentation when running integration tests.
Example / Best usage
Imaigne you need to describe an API or deliver the customer some test-evidence what is guaranteed by unit testing / integration test containing ...
- tests/
- FooController/
- CreateTest.php
- ShowTest.php
- ...
- FooControllerTest.php
Just a few doc comments can generate those documents.
The following has been generated by the doc comments of such tests (Tests\FooControllerTest
did this):
# Foo Fighters
This is an API for managing Foo. It allows:
- Create
- Read
Tests\FooController\CreateTest
added this:
## How to create a new one?
Creating is easy as long as you stick to the range.
### Request
Do `POST /foo` with some data.
Tests\FooController\ShowTest
added this:
## Read out all foo
### Restrictions
You can't see more than five. This is because ...
At least one will be at the drums. Because ...
Headings and Text
Within the FooControllerTest.php
we have:
namespace Tests;
/**
* Foo Fighters
*
* This is an API for managing Foo. It allows:
*
* - Create
* - Read
*
* @since 1994
*/
class FooControllerTest {}
This is what turns into the first section (see example doc above).
It simply puts the doc comment without @
attributes in the output.
Depth / Structure
Subsections will be done by parsing the namespace and (afterwards) by the methods a test contains:
namespace Tests\FooController;
/**
* How to create a new one?
*
* Creating is easy as long as you stick to the range.
*
*/
class CreateTest {
/**
* Request
*
* Do `POST /foo` with some data.
*
*/
function testBar() {
$this->assertTrue( (new FooController)->create() );
}
}
This is how the second section is created (see above).
Append content to another heading
When you are within one test it means you are testing one context so sometimes you like to add documentation to some heading. Just use the heading for all those tests again:
/**
* Read out all foo
*
*/
class ShowTest {
/**
* Restrictions
*
* You can't see more than five. This is because ...
*/
function testBar() {}
/**
* Restrictions
*
* At least one will be at the drums. Because ...
*/
function testBaz() {}
}
Ignore one method or class / Do not print in doc
- Mark it with an
@internal
. - Comments without heading or content will be ignored too.
Cheers!
All versions of phpunit-docgen with dependencies
phpunit/phpunit Version ~7|~8|~9
dompdf/dompdf Version ^0.8
michelf/php-markdown Version ^1.8
phpdocumentor/reflection-docblock Version ~5
symfony/finder Version ~3|~4|~5