Table of Contents
Articles you may be interested in:
Home Backend Development PHP Tutorial Detailed explanation of Yaf framework PHPUnit integration testing method

Detailed explanation of Yaf framework PHPUnit integration testing method

Jul 04, 2018 pm 05:51 PM
phpunit yaf Integration Testing

This article mainly introduces the detailed Yaf framework PHPUnit integration testing method. The editor thinks it is quite good. Now I will share it with you and give it a reference. Let’s follow the editor and take a look.

This article introduces the detailed Yaf framework PHPUnit integration test method and shares it with everyone. The details are as follows:

Test directory


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


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>
Copy after login


bootstrap.php test framework entry file


define("APP_PATH", realpath(dirname(__FILE__) . &#39;/../&#39;));
date_default_timezone_set("Asia/Shanghai");
define("TEST_DIR", __DIR__);
Copy after login


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(&#39;/Users/xiong/Sites/kyYaf&#39;, 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 . &#39;/conf/application.ini&#39;);
    $application->bootstrap();
    self::$_application = $application;
  }
}
Copy after login


TokenServiceTest.php service class example


namespace Service;
use test\TestCase;
include TEST_DIR . &#39;/TestCase.php&#39;;
include APP_PATH . &#39;/application/library/Service/BaseService.php&#39;;
include APP_PATH . &#39;/application/library/Service/TokenService.php&#39;;
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(&#39;22&#39;);
    $this->assertInternalType(&#39;array&#39;, $token);
    $this->assertInternalType(&#39;string&#39;, $token[&#39;token&#39;]);
  }

}
Copy after login


BaseControllerTest.php controller class example


namespace test\controller;
include TEST_DIR .&#39;/TestCase.php&#39;;
use test\TestCase;
class BaseControllerTest extends TestCase
{
  public function testGetConfigAction()
  {
    $request = new Simple(&#39;CLI&#39;, &#39;&#39;, &#39;Index&#39;, &#39;getConfig&#39;);
    $response = self::$_application->getDispatcher()->returnResponse(true)->dispatch($request);
    $contents = $response->getBody();
    $data = json_decode($contents, true);
    $this->assertInternalType(&#39;array&#39;, $data);
  }
}
Copy after login


The above is the entire content of this article. I hope it will be helpful to everyone’s study. I also hope that everyone will support the php Chinese website.


Articles you may be interested in:

Quickly solve the problem of DCOM permissions of PHP calling the Word component

Explanation of PHP getting a specified column in an array

Usage analysis of PHP array access interface ArrayAccess


The above is the detailed content of Detailed explanation of Yaf framework PHPUnit integration testing method. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to use PHPUnit for Mock testing in PHP development How to use PHPUnit for Mock testing in PHP development Jun 27, 2023 am 10:25 AM

In PHP development, testing is a very important link. Testing can greatly reduce the occurrence of errors and improve code quality. Mock testing is a form of testing that can simulate fake objects or data in order to test a specific function or scenario of our code. PHPUnit is a very popular testing framework in PHP, which supports Mock testing. In this article, we will explore how to use PHPUnit for mock testing. 1. What is Mock testing? Before we start, let’s come first

Test reporting tool in PHP Test reporting tool in PHP May 24, 2023 am 08:24 AM

PHP is a common open source programming language that is widely used in Web development. Its advantages are that it is easy to learn, easy to use, and highly scalable. As developers, in order to improve development efficiency while ensuring code quality, it is essential to use testing and test reports. In PHP development, there are many testing and test reporting tools, the most common of which is PHPUnit. However, although PHPUnit is simple and easy to use, it requires some basic knowledge of writing test cases. If you are not familiar with it, it is still difficult to use it.

How to perform unit testing and integration testing in Go language development How to perform unit testing and integration testing in Go language development Jun 29, 2023 am 11:58 AM

How to perform unit testing and integration testing in Go language development Summary: In software development, unit testing and integration testing are important means to ensure code quality and functional stability. In the Go language, there is also a complete set of tool support, making unit testing and integration testing easier and more efficient. This article will introduce how to perform unit testing and integration testing in Go language development, and demonstrate it through some sample codes. Introduction Go language is an open source programming language that is favored by more and more developers because of its simplicity and powerful features.

Laravel Development Advice: How to Perform Unit and Integration Testing Laravel Development Advice: How to Perform Unit and Integration Testing Nov 23, 2023 am 10:29 AM

Laravel is an excellent PHP framework that provides a series of components and tools to help us develop web applications more efficiently. However, in the face of increasingly complex business requirements, developers must constantly look for ways to improve software quality, reduce technical risks, and increase code reusability. In Laravel development, unit testing and integration testing are two very effective testing methods. They can help developers effectively verify the behavior of the application and allow developers to deliver software with more confidence. Book

What is the difference between unit testing and integration testing in golang function testing? What is the difference between unit testing and integration testing in golang function testing? Apr 27, 2024 am 08:30 AM

Unit testing and integration testing are two different types of Go function testing, used to verify the interaction and integration of a single function or multiple functions respectively. Unit tests only test the basic functionality of a specific function, while integration tests test the interaction between multiple functions and integration with other parts of the application.

Unit testing and integration testing in Go language Unit testing and integration testing in Go language Jun 02, 2023 am 10:40 AM

As software development becomes more complex, testing becomes more and more important. In actual development, there are two common testing methods: unit testing and integration testing. In this article, we will focus on these two testing methods in Go language. 1. Unit testing Unit testing is an independent testing unit used to test logical units in the program, such as functions, methods, classes, etc. These tests are usually written by the developers themselves and are used to verify that various units of the program work according to predetermined rules. In Go language, we can use the standard library

Code inspection tools in PHP Code inspection tools in PHP May 24, 2023 pm 12:01 PM

Checking code quality is a task that every programmer must do, and there are many tools in PHP that can be used to check the quality and style of code, thereby improving the readability and maintainability of the code, and improving the reliability and security of the code. sex. This article will introduce several common PHP code inspection tools and conduct a simple comparison and evaluation of them. I hope it can help readers choose appropriate tools during the development process and improve code quality and efficiency. PHP_CodeSnifferPHP_CodeSniffer is a widely used

How to use PHPUnit and Mockery for unit testing? How to use PHPUnit and Mockery for unit testing? May 31, 2023 pm 04:10 PM

In PHP project development, unit testing is a very important task. PHPUnit and Mockery are two very popular PHP unit testing frameworks. PHPUnit is a widely used unit testing tool, while Mockery is an object simulation tool that focuses on providing a unified and concise API to create and manage object mocks. By using PHPUnit and Mockery, developers can quickly and efficiently perform unit testing to ensure the correctness and stability of their code base

See all articles