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

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