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

前端之家收集整理的这篇文章主要介绍了详解Yaf框架PHPUnit集成测试方法前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

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

测试目录

PHP ├── bootstrap.PHP ├── controller │ ├── BaseControllerTest.PHP │ └── IndexControllerTest.PHP ├── model ├── PHPunit.xml └── service └── TokenServiceTest.PHP

PHPunit.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 测试框架入口文件

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); } }

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

原文链接:https://www.f2er.com/php/16448.html

猜你在找的PHP相关文章