tom-sapletta-com / unittest-generator
生成PHP单元测试
dev-master
2016-10-29 08:07 UTC
Requires
- php: ^5.3.3 || ^7.0
- phpunit/phpunit: 5.5.*
This package is not auto-updated.
Last update: 2024-09-18 19:14:14 UTC
README
关于
使用UnittestGenerator可以创建部分文件,但不是全部,因为这需要用户定义,但我将尝试在未来找到一些简单的方法,以帮助测试数据类型和许多方法。
- 文件
- 类名
- 一个方法
文章
https://tom.sapletta.com/project/a-tool-to-automatically-generate-phpunit-tests/
示例
配置(在test.php中)
$folder_project = 'src';
$folder_test = 'tests';
$namespace_project = 'Phunc';
$project_author = 'tom-sapletta-com';
$needle = ['interface', 'abstract'];
$files = new FilesGenerator($folder_project, $needle);
用法
$result = new UnittestGenerator($files, $folder_test, $namespace_project, $project_author);
在控制台开始
php test.php
控制台结果,摘要
folder_test: tests
namespace_project: Phunc
project_author: tom-sapletta-com
FILE excluded:0
FILE scanned:0
FILE todo:4
FILE existing (not created):0
FILE TESTS created:4
+ tests\CreateSummaryTest.php
+ tests\FilesGeneratorTest.php
+ tests\TemplateTest.php
+ tests\UnittestGeneratorTest.php
测试文件结果
CreateSummaryTest.php
FilesGeneratorTest.php
TemplateTest.php
UnittestGeneratorTest.php
测试文件存在时的控制台摘要
folder_test: tests
namespace_project: Phunc
project_author: tom-sapletta-com
FILE excluded:0
FILE scanned:0
FILE todo:5
FILE existing (not created):5
FILE TESTS created:0
工作原理
配置数据
- 设置路径_source以搜索PHP类
- 设置测试路径_test文件夹
- 单元测试模板
在路径_source中查找PHP文件并获取类
- 无接口
- 无抽象
- 无函数
在路径_test文件夹中生成测试内容的文件,并显示摘要