详解Yaf框架PHPUnit集成测试方法

本文介绍了详解Yaf框架PHPUnit集成测试方法分享给大家,具体如下:

测试目录

rush:plain;"> test ├── TestCase.PHP ├── bootstrap.PHP ├── controller │ ├── BaseControllerTest.PHP │ └── IndexControllerTest.PHP ├── model ├── PHPunit.xml └── service └── TokenServiceTest.PHP

PHPunit.xml

rush:xml;"> <PHPunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.PHPunit.de/6.2/PHPunit.xsd" extensionsDirectory="dbunit.phar" bootstrap="./bootstrap.PHP">

bootstrap.PHP 测试框架入口文件

rush:PHP;"> define("APP_PATH",realpath(dirname(__FILE__) . '/../')); date_default_timezone_set("Asia/Shanghai"); define("TEST_DIR",__DIR__);

TestCase.PHP 测试文件基础类

getApplication(); parent::setUp(); }

public function testAppPath()
{
$this->assertEquals('/Users/xiong/Sites/kyYaf',APP_PATH);
}

public function testApp()
{
$this->assertEquals(Application::app(),self::$_application);
}

public function testApplication()
{
$this->assertNotNull(self::$_application);
}

public function getApplication()
{
if (self::$_application == null) {
$this->setApplication();
}
return self::$_application;
}

public function setApplication()
{
$application = new Application(APP_PATH . '/conf/application.ini');
$application->bootstrap();
self::$_application = $application;
}
}

TokenServiceTest.PHP service类例子

public function testCreateToken()
{
$token = self::$tokenService->createtoken('22');
$this->assertInternalType('array',$token);
$this->assertInternalType('string',$token['token']);
}

}

BaseControllerTest.PHP controller类例子

getdispatcher()->returnResponse(true)->dispatch($request); $contents = $response->getBody(); $data = json_decode($contents,true); $this->assertInternalType('array',$data); } }

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持编程之家。

相关文章

统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
前言 之前做了微信登录,所以总结一下微信授权登录并获取用户...
FastAdmin是我第一个接触的后台管理系统框架。FastAdmin是一...
之前公司需要一个内部的通讯软件,就叫我做一个。通讯软件嘛...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...