Detailed explanation of YAF framework PHPUnit Integration test method

Source: Internet
Author: User
This article mainly introduces the detailed YAF framework PHPUnit integration test method, small series feel very good, now share to everyone, but also for everyone to do a reference. Let's take a look at it with a little knitting.

This article introduced the detailed YAF framework PHPUnit integration test method, share to everybody, concrete as follows:

Test Catalog


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 Test Framework Entry file


Define ("App_path", Realpath (DirName (__file__). '/.. /'));d ate_default_timezone_set ("Asia/shanghai");d efine ("Test_dir", __dir__);


testcase.php test file base class


Namespace Test;use phpunit\framework\testcase as Test;use yaf\application;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 Class Example


Namespace Service;use test\testcase;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 (' n ');    $this->assertinternaltype (' array ', $token);    $this->assertinternaltype (' string ', $token [' token ']);}  }


Basecontrollertest.php Controller Class Example


Namespace Test\controller;include test_dir. ' /testcase.php '; use Test\testcase;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);  }}


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.