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
Latest Articles by Author
-
2024-10-22 09:46:29
-
2024-10-13 13:53:41
-
2024-10-12 12:15:51
-
2024-10-11 22:47:31
-
2024-10-11 19:36:51
-
2024-10-11 15:50:41
-
2024-10-11 15:07:41
-
2024-10-11 14:21:21
-
2024-10-11 12:59:11
-
2024-10-11 12:17:31
Latest Issues
Popular Recommendations
Popular Tutorials
More>
-
JAVA Beginner's Video Tutorial2568753
Latest Downloads
More>