kphoen / rusty
类似Rust的测试用例风格的PHP文档
dev-master
2020-07-13 13:41 UTC
Requires
- php: ^7.2
- gregwar/rst: ^1.0
- league/commonmark: ^0.18,>=0.18.3
- nikic/php-parser: ^3.0
- symfony/console: ^4.4|^5.0
- symfony/finder: ^4.4|^5.0
- symfony/process: ^4.4|^5.0
Requires (Dev)
- mikey179/vfsstream: ^1.6
- phpunit/phpunit: ^7.0
This package is auto-updated.
Last update: 2024-09-13 22:37:23 UTC
README
记录Rust项目的主要方式是通过注释源代码。这些注释可以视为文档的一部分,但它们也可以编译并执行。他们将这称为“测试用例风格的文档”,并且他们的文档是一个宝藏。
Rusty是在PHP世界中尝试实现相同想法的一种尝试。
用法
Rusty能够从PHP文档块和Markdown文件(例如,您的文档)中提取代码示例。
运行测试
提供了一个可执行文件,用于分析您文档和文档块中分散的代码示例
rusty check -v ./src/
将文档作为测试用例编写
一个代码示例通常看起来像这样
/** * Computes the n-th Fibonacci's number. * * Examples: * * ``` * assert(fibonacci(1) === 1); * assert(fibonacci(2) === 1); * assert(fibonacci(12) === 144); * ``` * * ```should_throw * // -1 is invalid, some kind of error is expected * fibonacci(-1); * ``` * * ```no_execute * // it would take too much time to compute, we don't want to wait that long. * fibonacci(10000); * ``` */ function fibonacci($n) { if ($n < 0) { throw new \DomainException(); } return $n <= 2 ? 1 : fibonacci($n - 1) + fibonacci($n - 2); }
更多示例可以在./examples
目录中找到。
使用rusty help check
查看所有可能的选项。
安装
Rusty可以全局安装
composer global require kphoen/rusty dev-master
或本地安装
composer require kphoen/rusty dev-master
这两种方法都将提供rusty
可执行文件。
许可
此库受MIT许可证的约束。