pretzlaw/phpunit-docgen
Composer 安装命令:
composer require pretzlaw/phpunit-docgen
包简介
Generate test evidence or documentation by using doc comments.
README 文档
README
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
- FooController/
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!
pretzlaw/phpunit-docgen 适用场景与选型建议
pretzlaw/phpunit-docgen 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 18.69k 次下载、GitHub Stars 达 2, 最近一次更新时间为 2016 年 12 月 06 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 pretzlaw/phpunit-docgen 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 pretzlaw/phpunit-docgen 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 18.69k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 18
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2016-12-06