


Automated tests need to be executed many times. In order to ensure that the test process is repeatable, we really want to test in some known states , this state we call Specific state. For example, when testing the article creation feature in a blog application, every time we perform the test, the table related to the article (for example. Post
table, Comment
table) should be restored to a specific state. The PHPUnit documentation has a good description of the general construction of a specific state. This section mainly introduces how to create a specific state like the example just described. In this way, you can build a specific state of the database.
Setting the specific state of building the database is probably one of the most time-consuming parts of testing applications with database backend support. The CBbFixtureManager application component introduced by Yii can effectively alleviate this problem. One question. When running a set of tests, it basically does the following:
Before all tests are run, it resets the test-related data to a knowable state.
Before a single test is run, it resets specific tables to a knowable state.
During the execution of a test method, it provides An access interface that provides row data in a specific state.
Please use the CDbFixtureManager we configured in the application configuration as follows.
return array( 'components'=>array( 'fixture'=>array( 'class'=>'system.test.CDbFixtureManager', ), ), );
Then we provide a specific state data under the directory protected/tests/fixtures
. This directory can be configured by CDbFixtureManager::basePath in the application configuration file Properties are specified as other directories. State-specific data is composed of multiple PHP files called state-specific files. Each state-specific file returns an array representing the initial row of a specific table of data. The file name is the same as the table name. .The following is an example of storing specific status data of the Post
table in a file named Post.php
.
<?php return array( 'sample1'=>array( 'title'=>'test post 1', 'content'=>'test post content 1', 'createTime'=>1230952187, 'authorId'=>1, ), 'sample2'=>array( 'title'=>'test post 2', 'content'=>'test post content 2', 'createTime'=>1230952287, 'authorId'=>1, ), );
As we can see, the above returns two rows of data. Each row represents an array, the key of which is the field name of the table, and the value of which is the corresponding field value. Each row represents an array. The row indices are all strings called row alias (for example: simple1
, simple2
). Later when we write the test script, we This row of data can be conveniently called by its alias. We will cover this in detail in the next section.
You may have noticed that we did not specify the id
field in the above specific state Value. This is because the id
field has been defined as an auto-incrementing primary key, and its value will also be automatically generated when we insert new data.
When CDbFixtureManager is referenced for the first time , it goes through all the specific state files and uses them to reset the corresponding table. It does this by clearing the table, resetting the auto-increment sequence of the table's primary key, and then inserting rows from the specific state file into the table. Table.
Sometimes, we may not want to reset every table described in a specific state file before a set of tests, because resetting too many specific state files may take a lot of time. In this case, We can write a PHP script to customize this initialization process. This script should be saved in the directory where the specific state file is stored, and named init.php
. When CDbFixtureManager detects the existence of this script, it will Execute this script instead of resetting each table.
It's okay if you don't like to use the default way to reset the table, for example: clear the table and then insert specific state data. If this is the case, we can specify Write an initialization script for a specific state file. This script must be named table name + .init.php
. For example: The initialization script file for the Post
table is Post.init. php
. When CDbFixtureManager finds this script, it will execute this script instead of using the default method to reset the table.
Tip: Too many specifics State files greatly extend test time. Therefore, you should only provide specific state files for tables whose data will change during the test. Tables that serve as lookup services will not change and therefore do not require specific state files.
In the next two sections, we will talk about how to use specific states managed by CDbFixtureManager in unit tests and functional tests.
The above is the Yii Framework Official Guide Series 38 - Defining Specific States (Fixtures) content, please pay attention to the PHP Chinese website (www.php.cn) for more related content!

随着互联网的普及以及人们对电影的热爱,电影网站成为了一个受欢迎的网站类型。在创建一个电影网站时,一个好的框架是非常必要的。Yii框架是一个高性能的PHP框架,易于使用且具有出色的性能。在本文中,我们将探讨如何使用Yii框架创建一个电影网站。安装Yii框架在使用Yii框架之前,需要先安装框架。安装Yii框架非常简单,只需要在终端执行以下命令:composer

Yii框架是一个高性能、高扩展性、高可维护性的PHP开发框架,在开发Web应用程序时具有很高的效率和可靠性。Yii框架的主要优点在于其独特的特性和开发方法,同时还集成了许多实用的工具和功能。Yii框架的核心概念MVC模式Yii采用了MVC(Model-View-Controller)模式,是一种将应用程序分为三个独立部分的模式,即业务逻辑处理模型、用户界面呈

Yii框架是一个高性能、可扩展、安全的PHP框架。它是一个优秀的开发工具,能够让开发者快速高效地构建复杂的Web应用程序。以下是几个原因,让Yii框架比其他框架更好用。高性能Yii框架使用了一些先进的技术,例如,延迟加载(lazyloading)和自动加载机制(automaticclassloading),这使得Yii框架的性能高于许多其他框架。它还提

ViewState是ASP.NET中的一种机制,用于保护页面的隐私数据。而在Yii框架中,ViewState同样也是实现页面数据保护的重要手段。在Web开发中,随着用户界面操作的复杂度增加,前端与后端之间的数据传输也愈发频繁。但是,不可避免的会有恶意用户通过网络抓包等手段截获数据。而未加保护的数据可能含有用户隐私、订单信息、财务数据等重要资料。因此,加密传输

随着互联网的快速发展,应用程序对于处理大量并发请求和任务变得越来越重要。在这样的情况下,处理异步任务是必不可少的,因为这可以使应用程序更加高效,并更好地响应用户请求。Yii框架提供了一个方便的队列组件,使得处理异步操作更加容易和高效。在本篇文章中,我们将探讨Yii框架中队列的使用和优势。什么是队列队列是一种数据结构,用于处理数据的先进先出(FIFO)顺序。队

在现今互联网时代,数据的处理和展示对于各种应用而言都是至关重要的。对于一些数据量较大的网站,其展示效果直接影响用户体验,而优秀的分页机制可以使得数据展示更加清晰,提高用户的使用体验。在本文中,我们将介绍Yii框架中的分页机制,并探讨如何通过优化分页机制来改进数据展示效果。Yii框架是一种基于PHP语言的高性能、适用于Web应用的开发框架。它提供

Yii是一款优秀的PHP框架,它提供了很多丰富的功能和组件来加快Web应用程序的开发。其中一个非常重要的特性就是可以方便地使用外部库进行扩展。Yii框架中的扩展可以帮助我们快速完成许多常见的任务,例如操作数据库、缓存数据、发送邮件、验证表单等等。但是有时候,我们需要使用一些其他的PHP类库来完成特定的任务,例如调用第三方API、处理图片、生成PDF文件等等。

在Web应用程序开发领域,身份认证和授权是保障应用程序安全性必不可少的两个环节,而Yii框架提供了完善的身份认证和授权机制,帮助开发者轻松实现这些功能,保障应用程序的安全性。一、身份认证1.1基础认证Yii框架中的基础认证机制采用HTTPBasic认证的方式实现。当用户在浏览器中访问需要认证的页面时,服务器会发送一个401Unauthorized响应,


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

SublimeText3 English version
Recommended: Win version, supports code prompts!

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools
