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

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

内容导读

收集整理的这篇技术教程文章主要介绍了详解Yaf框架PHPUnit集成测试方法讲解,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2946字,纯文字阅读大概需要5分钟

内容图文

这篇文章主要介绍了详解Yaf框架PHPUnit集成测试方法,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧

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

测试目录


test├── TestCase.php├── bootstrap.php├── controller│
├── BaseControllerTest.php│
└── IndexControllerTest.php├── model├── phpunit.xml└── service
└── TokenServiceTest.php


phpunit.xml


<?xml version="1.0" encoding="UTF-8"?><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"></phpunit>


bootstrap.php 测试框架入口文件


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


TestCase.php 测试文件基础类


namespace test;use PHPUnitFrameworkTestCase as Test;use YafApplication;class TestCase extends Test{
protected static $_application = null;
protected function setUp()
{

self::$_application = $this->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类例子


namespace Service;use testTestCase;include TEST_DIR . '/TestCase.php';include APP_PATH . '/application/library/Service/BaseService.php';include APP_PATH . '/application/library/Service/TokenService.php';class TokenServiceTest extends TestCase{
/**
 * @var TokenService
 */
protected static $tokenService;
public function setUp()
{

self::$tokenService = TokenService::getInstance();

parent::setUp();
}
public function testCreateToken()
{

$token = self::$tokenService->createToken('22');

$this->assertInternalType('array', $token);

$this->assertInternalType('string', $token['token']);
}}


BaseControllerTest.php controller类例子


namespace testcontroller;include TEST_DIR .'/TestCase.php';use testTestCase;class BaseControllerTest extends TestCase{
public function testGetConfigAction()
{

$request = new Simple('CLI', '', 'Index', 'getConfig');

$response = self::$_application->getDispatcher()->returnResponse(true)->dispatch($request);

$contents = $response->getBody();

$data = json_decode($contents, true);

$this->assertInternalType('array', $data);
}}


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


您可能感兴趣的文章:

快速解决PHP调用Word组件DCOM权限的问题讲解

PHP获取数组中指定的一列实例讲解

PHP数组式访问接口ArrayAccess的用法分析


以上就是详解Yaf框架PHPUnit集成测试方法讲解的详细内容,更多请关注Gxl网其它相关文章!

内容总结

以上是为您收集整理的详解Yaf框架PHPUnit集成测试方法讲解全部内容,希望文章能够帮你解决详解Yaf框架PHPUnit集成测试方法讲解所遇到的程序开发问题。 如果觉得技术教程内容还不错,欢迎将网站推荐给程序员好友。

内容备注

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。


本文关键词:

联系我们

在线咨询:点击这里给我发消息

邮件:w420220301@qq.com