michaeldoehler/phpunit-generator

该软件包的最新版本(0.9.2)没有提供许可证信息。

Php Unit Generator

0.9.2 2015-07-07 15:43 UTC

This package is not auto-updated.

Last update: 2024-09-18 09:36:04 UTC


README

安装

检出仓库并运行 composer install 以安装依赖项

配置

创建一个 config.php 如下

<?php

//instantiate configuration
$configuration = \PhpUnitTestGenerator\Configuration\Configuration::getInstance();

//overwrite base class, per default \PHPUnit_Framework_TestCase is used
//$configuration->setBaseClass("");

//set source directory of classes
$configuration->setSourceDirectory(dirname(__FILE__) . '/example/src');

//set target directory of classes
$configuration->setTargetDirectory(dirname(__FILE__) . '/example/test');

//configure namespace mappings, e.g. if your tests exists in different namespace
$configuration->setNamespaceMappings(array(
    "Example" => "Example\\Tests",
));
?>

Cli 命令

php phpunit-generator.php generate
php phpunit-generator.php test

组件

基本

基本配置,如基类、源目录和目标目录。

索引器

创建一个可生成的索引,例如从文件系统创建,并提供一个包含每个文件的 Testable 类实例的迭代器!

生成器

生成器链,可用于生成测试类或测试方法。

有两种生成策略:第一种是基于类的,第二种是基于方法的。

生成器提供者提供了生成整个类或仅生成测试方法的可能性

  • PhpUnitTestGenerator\Generator\Provider\Definition\ObjectInterface

  • PhpUnitTestGenerator\Generator\Provider\Definition\MethodInterface

架构

索引器构建一个可测试的 PHP 类的索引。索引器将此作为索引结果集提供。

可测试构建器遍历每个找到的类,并从给定的类创建一个可测试对象。

生成器生成给定的可测试结果集的每个结果,并尝试根据给定的对象和/或方法策略生成测试类。