カズ9ス/功能测试者

这是一个用于PHP遗留产品功能测试的库

0.0.2 2016-01-15 11:38 UTC

This package is not auto-updated.

Last update: 2024-09-28 18:53:09 UTC


README

Build Status

这是一个用于PHP遗留产品功能测试的库。
如果您在测试此类产品时遇到困难,这个库可以帮助您。

使用方法

首先,创建一个新的“功能测试者”实例。

您可以为您的目标产品设置会话、文档根和包含路径。

如果您调用类似于HTTP请求的request方法,您可以获取一个GuzzleHttp\Message\Response的解析响应实例

use FunctionalTester/FunctionalTester;

class IndexTest extends PHPUnit_Framework_TestCase
{
    public function testIndex
    {
        $tester = new FunctionalTester();
        
        //set session used in your target product.
        $tester->setSession(['id' => 'hogehoge']);
        
        //set your document root. you can also set as constructer 1st argument.
        $tester->setDocumentRoot('/path/to/src');
        
        //set include path used in your target product. you can also set as constructer 2nd argument.
        $tester->setIncludePath('.:/usr/bin/php');

        //you can also add
        $tester->addIncludePath(':/path/to/src');
        
        //you can call get or post method like http request
        $response = $tester->get('index.php', ['username' => 'hogehoge']);
        
        //you can assert request results like this.
        $this->assertEquals(200, $response->getStatusCode());
        $this->assertEquals('OK', $response->getBody());
    }
}

安装

您可以通过Composer 安装这个库。

$ composer require kazu9su/functional-tester

这将安装功能测试者及其所有必需的依赖项。

测试

要执行测试套件,您需要phpunit。

$ phpunit

许可协议

功能测试者遵循MIT许可协议。有关更多信息,请参阅许可文件