PHPUnit安装及使用示例,phpunit安装示例
PHPUnit安装及使用示例,phpunit安装示例
PHPUnit是zend官方大力支持的测试框架,高质量的单元测试时保证项目质量的基础,能够有效的减少BUG,改善程序。
安装PHPUnit:
在php的目录下:
复制代码 代码如下:
pear channel-discover pear;
pear install phpunit/PHPUnit
windows下将php的环境变量加入到PATH环境变量中。
简单使用:
复制代码 代码如下:
class StackTest extends PHPUnit_Framework_TestCase
{
public function testArray()
{
$stack = array();
$this->assertEquals(0, count($stack));
array_push($stack, 'foo');
$this->assertEquals('foo', $stack[count($stack)-1]);
$this->assertEquals(1, count($stack));
$this->assertEquals('foo', array_pop($stack));
$this->assertEquals(0, count($stack));
}
/**
* @test
*/
public function Stringlen()
{
$str = 'abc';
$this->assertEquals(3, strlen($str));
}
}
从上可以看到编写PHPUnit的基本规律:
(1)类Class的测试写在ClassTest中
(2)ClassTest继承PHPUnit_Framework_TestCase
(3)测试方法都是test*格式,也可以通过@test将其标注为测试方法。
(4)通过断言方法assertEquals来对实际值和预期值进行断言。
PHPUnit可以通过PHP扩展和程序库(PEAE)获得。PEAR是可重用PHP组件的框架和分发系统。安装PHPUnit可以通过PEAR安装程序命令获得:
pear install PHPUnit2
根据PEAR的版本命名标准,适用于PHP5的PHPUnit包称为PHPUnit2。PHPUnit是适用于PHP4的包,这在本书后面关于“在PHP4中使用PHPUnit”一章会提到。
安装只有,能够在本地的PEAR目录中找到PHPUnit的源代码,路径通常是/usr/lib/ php/PHPUnit2。
尽管使用PEAR安装程序是PHPUnit唯一支持的安装方法,但你还是可以手工安装。要手工安装,参照以下做法:
1.从pear.php.net/package/PHPUnit2/download下载PHPUnit发布包,然后解压缩,确保目录在php.ini定义的include_path中。
2.准备phpunit脚本
a.将pear-phpunit脚本改名为phpunit
b.将脚本中所有的@php_bin@改名为PHP命令行解释器所在的目录(通常为/usr/bin/ php)。
c.将此脚本拷贝到一个PATH环境变量所包含的目录中,并将文件属性改为可执行(chmod +x phpunit)。
3.将PHPUnit2/ Runner/Version.php脚本中的所有@package_version@字符串替换为你所安装的PHPUnit版本(如2.3.0)。
解决方法
根据上述出错信息,我们可以知道PEAR DB类安装出错问题所在:是由于在重新安装PEAR时,没有更改PEAR的安装目录环境变量PHP_PEAR_INSTALL_DIR,导致PEAR命令无法正常使用。
提示告诉我们可以通过修改pear.bat中的PEAR安装环境变量PHP_PEAR_INSTALL_DIR的值来解决此问题。
右击pear.bat,选择编辑,即可以记事本方式打开此批处理文件。找到
REM Check PEAR global ENV, set them if they do not exist
修改下面的
IF “%PHP_PEAR_INSTALL_DIR%”==”" SET “PHP_PEAR_INSTALL_DIR=E:\phpos\DedeAMPZ\WebRoot\Default\pear”
为
IF “%PHP_PEAR_INSTALL_DIR%”==”E:\phpos\DedeAMPZ\Program\PHP5\pear” SET “PHP_PEAR_INSTALL_DIR=E:\phpos\DedeAMPZ\WebRoot\Default\pear”
即可对PEAR安装环境变量PHP_PEAR_INSTALL_DIR的值进行覆盖。
至此,PHP PEAR在安装时由于PHP_PEAR_INSTALL_DIR(安装目录)值不对,导致无法使用PEAR的问题就解决了。

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

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



CrystalDiskMark is a small HDD benchmark tool for hard drives that quickly measures sequential and random read/write speeds. Next, let the editor introduce CrystalDiskMark to you and how to use crystaldiskmark~ 1. Introduction to CrystalDiskMark CrystalDiskMark is a widely used disk performance testing tool used to evaluate the read and write speed and performance of mechanical hard drives and solid-state drives (SSD). Random I/O performance. It is a free Windows application and provides a user-friendly interface and various test modes to evaluate different aspects of hard drive performance and is widely used in hardware reviews

If you have successfully downloaded the installation file of Baidu Netdisk, but cannot install it normally, it may be that there is an error in the integrity of the software file or there is a problem with the residual files and registry entries. Let this site take care of it for users. Let’s introduce the analysis of the problem that Baidu Netdisk is successfully downloaded but cannot be installed. Analysis of the problem that Baidu Netdisk downloaded successfully but could not be installed 1. Check the integrity of the installation file: Make sure that the downloaded installation file is complete and not damaged. You can download it again, or try to download the installation file from another trusted source. 2. Turn off anti-virus software and firewall: Some anti-virus software or firewall programs may prevent the installation program from running properly. Try disabling or exiting the anti-virus software and firewall, then re-run the installation

foobar2000 is a software that can listen to music resources at any time. It brings you all kinds of music with lossless sound quality. The enhanced version of the music player allows you to get a more comprehensive and comfortable music experience. Its design concept is to play the advanced audio on the computer The device is transplanted to mobile phones to provide a more convenient and efficient music playback experience. The interface design is simple, clear and easy to use. It adopts a minimalist design style without too many decorations and cumbersome operations to get started quickly. It also supports a variety of skins and Theme, personalize settings according to your own preferences, and create an exclusive music player that supports the playback of multiple audio formats. It also supports the audio gain function to adjust the volume according to your own hearing conditions to avoid hearing damage caused by excessive volume. Next, let me help you

NetEase Mailbox, as an email address widely used by Chinese netizens, has always won the trust of users with its stable and efficient services. NetEase Mailbox Master is an email software specially created for mobile phone users. It greatly simplifies the process of sending and receiving emails and makes our email processing more convenient. So how to use NetEase Mailbox Master, and what specific functions it has. Below, the editor of this site will give you a detailed introduction, hoping to help you! First, you can search and download the NetEase Mailbox Master app in the mobile app store. Search for "NetEase Mailbox Master" in App Store or Baidu Mobile Assistant, and then follow the prompts to install it. After the download and installation is completed, we open the NetEase email account and log in. The login interface is as shown below

Cloud storage has become an indispensable part of our daily life and work nowadays. As one of the leading cloud storage services in China, Baidu Netdisk has won the favor of a large number of users with its powerful storage functions, efficient transmission speed and convenient operation experience. And whether you want to back up important files, share information, watch videos online, or listen to music, Baidu Cloud Disk can meet your needs. However, many users may not understand the specific use method of Baidu Netdisk app, so this tutorial will introduce in detail how to use Baidu Netdisk app. Users who are still confused can follow this article to learn more. ! How to use Baidu Cloud Network Disk: 1. Installation First, when downloading and installing Baidu Cloud software, please select the custom installation option.

MetaMask (also called Little Fox Wallet in Chinese) is a free and well-received encryption wallet software. Currently, BTCC supports binding to the MetaMask wallet. After binding, you can use the MetaMask wallet to quickly log in, store value, buy coins, etc., and you can also get 20 USDT trial bonus for the first time binding. In the BTCCMetaMask wallet tutorial, we will introduce in detail how to register and use MetaMask, and how to bind and use the Little Fox wallet in BTCC. What is MetaMask wallet? With over 30 million users, MetaMask Little Fox Wallet is one of the most popular cryptocurrency wallets today. It is free to use and can be installed on the network as an extension

Installing Android applications on Linux has always been a concern for many users. Especially for Linux users who like to use Android applications, it is very important to master how to install Android applications on Linux systems. Although running Android applications directly on Linux is not as simple as on the Android platform, by using emulators or third-party tools, we can still happily enjoy Android applications on Linux. The following will introduce how to install Android applications on Linux systems.

If you have used Docker, you must understand daemons, containers, and their functions. A daemon is a service that runs in the background when a container is already in use in any system. Podman is a free management tool for managing and creating containers without relying on any daemon such as Docker. Therefore, it has advantages in managing containers without the need for long-term backend services. Additionally, Podman does not require root-level permissions to be used. This guide discusses in detail how to install Podman on Ubuntu24. To update the system, we first need to update the system and open the Terminal shell of Ubuntu24. During both installation and upgrade processes, we need to use the command line. a simple
