时间:2021-07-01 10:21:17 帮助过:19人阅读
0、PHPUnit手册:https://phpunit.de/manual/current/zh_cn/phpunit-book.html
1、读取XML文件
developer-a.xml
?
MyTest.php
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)); }}?>
?
测试命令:
写道phpunit --configuration developer-a.xml MyTest.php?
2、例 2.3: 利用测试之间的依赖关系
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() ); }}?>
?
测试命令行:写道phpunit DependencyFailureTest.html?3、PHP 关联数组关联数组是使用您分配给数组的指定键的数组。
有两种创建关联数组的方法:
$age=array("Peter"=>"35","Ben"=>"37","Joe"=>"43");
?
或者:$age['Peter']="35";$age['Ben']="37";$age['Joe']="43";?随后可以在脚本中使用指定键:
"35","Steve"=>"37","Peter"=>"43");echo "Peter is " . $age['Peter'] . " years old.";?>?