Home Backend Development PHP Tutorial PHPUnit知识点集聚(持续更新)

PHPUnit知识点集聚(持续更新)

Jun 13, 2016 pm 12:24 PM
gt phpunit stack this

PHPUnit知识点汇聚(持续更新)

0、PHPUnit手册:https://phpunit.de/manual/current/zh_cn/phpunit-book.html

1、读取XML文件

developer-a.xml

<?xml version="1.0" encoding="UTF-8" ?><phpunit>    <php>        <var name="DB_DSN" value="mysql:dbname=myguestbook;host=localhost" />        <var name="DB_USER" value="root" />        <var name="DB_PASSWD" value="123456" />        <var name="DB_DBNAME" value="fetion" />    </php></phpunit>
Copy after login

?

MyTest.php

<?phpclass MyTest extends PHPUnit_Framework_TestCase{    public function testPushAndPop()    {        $stack = array();        $this->assertEquals(0, count($stack));        array_push($stack, $GLOBALS['DB_USER']);        $this->assertEquals('root', $stack[count($stack)-1]);        //$this->assertEquals(1, count($stack));        //$this->assertEquals('foo', array_pop($stack));        //$this->assertEquals(0, count($stack));    }}?>
Copy after login

?

测试命令:

写道

phpunit --configuration developer-a.xml MyTest.php

?

2、例 2.3: 利用测试之间的依赖关系

<?phpclass MultipleDependenciesTest extends PHPUnit_Framework_TestCase{    public function testProducerFirst()    {        $this->assertTrue(true);        return 'first';    }    public function testProducerSecond()    {        $this->assertTrue(true);        return 'second';    }    /**     * @depends testProducerFirst     * @depends testProducerSecond     */    public function testConsumer()    {        $this->assertEquals(            array('first', 'second'),            func_get_args()        );    }}?>
Copy after login

?

测试命令行:

写道

phpunit DependencyFailureTest.html

?

3、PHP 关联数组

关联数组是使用您分配给数组的指定键的数组。

有两种创建关联数组的方法:

$age=array("Peter"=>"35","Ben"=>"37","Joe"=>"43");
Copy after login

?

或者:

$age['Peter']="35";$age['Ben']="37";$age['Joe']="43";
Copy after login
?随后可以在脚本中使用指定键:

<?php$age=array("Bill"=>"35","Steve"=>"37","Peter"=>"43");echo "Peter is " . $age['Peter'] . " years old.";?>
Copy after login
?
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

Video Face Swap

Video Face Swap

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

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)

What are the differences between Huawei GT3 Pro and GT4? What are the differences between Huawei GT3 Pro and GT4? Dec 29, 2023 pm 02:27 PM

Many users will choose the Huawei brand when choosing smart watches. Among them, Huawei GT3pro and GT4 are very popular choices. Many users are curious about the difference between Huawei GT3pro and GT4. Let’s introduce the two to you. . What are the differences between Huawei GT3pro and GT4? 1. Appearance GT4: 46mm and 41mm, the material is glass mirror + stainless steel body + high-resolution fiber back shell. GT3pro: 46.6mm and 42.9mm, the material is sapphire glass + titanium body/ceramic body + ceramic back shell 2. Healthy GT4: Using the latest Huawei Truseen5.5+ algorithm, the results will be more accurate. GT3pro: Added ECG electrocardiogram and blood vessel and safety

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

Fix: Snipping tool not working in Windows 11 Fix: Snipping tool not working in Windows 11 Aug 24, 2023 am 09:48 AM

Why Snipping Tool Not Working on Windows 11 Understanding the root cause of the problem can help find the right solution. Here are the top reasons why the Snipping Tool might not be working properly: Focus Assistant is On: This prevents the Snipping Tool from opening. Corrupted application: If the snipping tool crashes on launch, it might be corrupted. Outdated graphics drivers: Incompatible drivers may interfere with the snipping tool. Interference from other applications: Other running applications may conflict with the Snipping Tool. Certificate has expired: An error during the upgrade process may cause this issu simple solution. These are suitable for most users and do not require any special technical knowledge. 1. Update Windows and Microsoft Store apps

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.

An in-depth exploration of the structural aspects and functions of OP Stack An in-depth exploration of the structural aspects and functions of OP Stack Jan 18, 2024 pm 05:45 PM

OPStack is an open source blockchain framework released by Optimism Collective, the development group behind the Optimism Network. It is an important tool for both the Ethereum and Optimism communities. The main goal of OPStack is to strengthen the Optimism Network, providing key software tools to the Optimism Mainnet, as well as the upcoming Optimism Superchain and its governance model. By providing a developer-oriented environment, the core idea of ​​OPStack is to promote growth and innovation in the Ethereum space. It paves the way for cutting-edge developments and makes blockchain creation simpler. OPStac

How to check code convention and quality using PHP and PHPUnit How to check code convention and quality using PHP and PHPUnit Jun 25, 2023 pm 04:57 PM

In modern software development, code quality and specifications are extremely important factors. Not only can it make the code cleaner and easier to maintain, it can also improve the readability and scalability of the code. But how do you check the quality and specification of your code? This article will explain how to use PHP and PHPUnit to achieve this goal. Step 1: Check the code specification. In PHP development, there is a very popular code specification, which is called PSR (PHP Standard Specification). The purpose of the PSR specification is to make PHP code more readable and maintainable. in

How to use PHPUnit for PHP unit testing How to use PHPUnit for PHP unit testing May 12, 2023 am 08:13 AM

With the development of the software development industry, testing has gradually become an indispensable part. As the most basic part of software testing, unit testing can not only improve code quality, but also speed up developers' development and maintenance of code. In the field of PHP, PHPUnit is a very popular unit testing framework that provides various functions to help us write high-quality test cases. In this article, we will cover how to use PHPUnit for PHP unit testing. Install PHPUnit and use PHPUnit

What are the common code quality tools in PHP programming? What are the common code quality tools in PHP programming? Jun 12, 2023 am 08:16 AM

What are the common code quality tools in PHP programming? In modern software development, code quality is very important. If the code quality is not good, it will not only reduce the readability of the code and increase the difficulty of maintenance, but also cause a series of problems such as security vulnerabilities. In PHP programming, we can use some code quality tools to check the quality of the code. This article will introduce some common PHP code quality tools. PHP_CodeSnifferPHP_CodeSniffer is a tool for static analysis of PHP code

See all articles